Fixe unmap-notify request
[clfswm.git] / contrib / mpd.lisp
blob52cd03a01260b022ddc71850a60d71bae07ccc4c
1 ;;; --------------------------------------------------------------------------
2 ;;; CLFSWM - FullScreen Window Manager
3 ;;;
4 ;;; --------------------------------------------------------------------------
5 ;;; Documentation: Music Player Daemon (MPD) interface
6 ;;; --------------------------------------------------------------------------
7 ;;;
8 ;;; (C) 2012 Philippe Brochard <pbrochard@common-lisp.net>
9 ;;;
10 ;;; This program is free software; you can redistribute it and/or modify
11 ;;; it under the terms of the GNU General Public License as published by
12 ;;; the Free Software Foundation; either version 3 of the License, or
13 ;;; (at your option) any later version.
14 ;;;
15 ;;; This program is distributed in the hope that it will be useful,
16 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;;; GNU General Public License for more details.
19 ;;;
20 ;;; You should have received a copy of the GNU General Public License
21 ;;; along with this program; if not, write to the Free Software
22 ;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 ;;;
24 ;;; Documentation: If you want to use this file, just add this line in
25 ;;; your configuration file:
26 ;;;
27 ;;; (load-contrib "mpd.lisp")
28 ;;;
29 ;;; --------------------------------------------------------------------------
31 (in-package :clfswm)
33 (format t "Loading MPD code... ")
36 (defun mpd-menu ()
37 "Open the Music Player Daemon (MPD) menu"
38 (open-menu (find-menu 'mpd-menu)))
41 (defun start-sonata ()
42 "Start sonata"
43 (do-shell "exec sonata"))
45 (defun start-gmpc ()
46 "Start gmpc"
47 (do-shell "exec gmpc"))
50 (defun show-mpd-info ()
51 "Show MPD informations"
52 (info-on-shell "MPD informations:" "mpc")
53 (mpd-menu))
55 (defun mpd-previous (&optional (in-menu t))
56 "Play the previous song in the current playlist"
57 (if in-menu
58 (progn
59 (info-on-shell "MPD:" "mpc prev")
60 (mpd-menu))
61 (do-shell "mpc prev" nil t)))
63 (defun mpd-next (&optional (in-menu t))
64 "Play the next song in the current playlist"
65 (if in-menu
66 (progn
67 (info-on-shell "MPD:" "mpc next")
68 (mpd-menu))
69 (do-shell "mpc next" nil t)))
71 (defun mpd-toggle ()
72 "Toggles Play/Pause, plays if stopped"
73 (do-shell "mpc toggle"))
75 (defun mpd-play ()
76 "Start playing"
77 (do-shell "mpc play"))
79 (defun mpd-stop ()
80 "Stop the currently playing playlists"
81 (do-shell "mpc stop"))
84 (defun mpd-seek-+5% (&optional (in-menu t))
85 "Seeks to +5%"
86 (if in-menu
87 (progn
88 (do-shell "mpc seek +5%")
89 (mpd-menu))
90 (do-shell "mpc seek +5%" nil t)))
92 (defun mpd-seek--5% (&optional (in-menu t))
93 "Seeks to -5%"
94 (if in-menu
95 (progn
96 (do-shell "mpc seek -5%")
97 (mpd-menu))
98 (do-shell "mpc seek -5%" nil t)))
100 (defun show-mpd-playlist ()
101 "Show the current MPD playlist"
102 (info-on-shell "Current MPD playlist:" "mpc playlist")
103 (mpd-menu))
105 (unless (find-menu 'mpd-menu)
106 (add-sub-menu 'help-menu "F2" 'mpd-menu "Music Player Daemon (MPD) menu")
108 (add-menu-key 'mpd-menu "i" 'show-mpd-info)
109 (add-menu-key 'mpd-menu "p" 'mpd-previous)
110 (add-menu-key 'mpd-menu "n" 'mpd-next)
111 (add-menu-key 'mpd-menu "t" 'mpd-toggle)
112 (add-menu-key 'mpd-menu "y" 'mpd-play)
113 (add-menu-key 'mpd-menu "k" 'mpd-stop)
114 (add-menu-key 'mpd-menu "x" 'mpd-seek-+5%)
115 (add-menu-key 'mpd-menu "w" 'mpd-seek--5%)
116 (add-menu-key 'mpd-menu "l" 'show-mpd-playlist)
117 (add-menu-key 'mpd-menu "s" 'start-sonata)
118 (add-menu-key 'mpd-menu "g" 'start-gmpc))
121 (defun mpd-binding ()
122 (define-main-key ("F2" :alt) 'mpd-menu))
124 (add-hook *binding-hook* 'mpd-binding)
128 #+:clfswm-toolbar
129 (progn
130 (defconfig *mpd-toolbar* '((mpd-buttons 1)
131 (mpd-info 60))
132 'Toolbar "MPD toolbar modules")
134 (defconfig *mpd-toolbar-client* "gmpc"
135 'Toolbar "MPD client")
137 (define-toolbar-color mpd-info "MPD - Music Player Daemon information color")
138 (define-toolbar-color mpd-buttons "MPD - Music Player Daemon buttons color")
140 (define-toolbar-module (mpd-info small)
141 "(small) - MPD (Music Player Daemon) informations"
142 (let* ((lines (do-shell "mpc" nil t))
143 (mpd-line (loop for line = (read-line lines nil nil)
144 while line
145 collect line)))
146 (if (>= (length mpd-line) 3)
147 (if small
148 (toolbar-module-text toolbar module (tb-color mpd-info)
149 "~A"
150 (ensure-printable (first mpd-line)))
151 (toolbar-module-text toolbar module (tb-color mpd-info)
152 "~A - ~A"
153 (ensure-printable (first mpd-line))
154 (ensure-printable (second mpd-line))))
155 (toolbar-module-text toolbar module (tb-color mpd-info)
156 "MPD - Not playing"))))
158 (define-toolbar-module (mpd-buttons small)
159 "(small) - MPD (Music Player Daemon) buttons"
160 (with-set-toolbar-module-rectangle (module)
161 (toolbar-module-text toolbar module (tb-color mpd-buttons)
162 (if small
163 "PNT<>C"
164 "P N T < > C"))))
166 (define-toolbar-module-click (mpd-buttons small)
167 "P=Previous, N=Next, T=Toogle, <=seek-5% >=seek+5% C=start MPD client"
168 (declare (ignore state small))
169 (when (= code 1)
170 (let ((pos (toolbar-module-subdiv toolbar module root-x root-y 6)))
171 (case pos
172 (0 (mpd-previous nil))
173 (1 (mpd-next nil))
174 (2 (mpd-toggle))
175 (3 (mpd-seek--5% nil))
176 (4 (mpd-seek-+5% nil))
177 (5 (do-shell *mpd-toolbar-client*))))
178 (refresh-toolbar toolbar))))
181 (format t "done~%")