1 ;;; --------------------------------------------------------------------------
2 ;;; CLFSWM - FullScreen Window Manager
4 ;;; --------------------------------------------------------------------------
5 ;;; Documentation: Music Player Daemon (MPD) interface
6 ;;; --------------------------------------------------------------------------
8 ;;; (C) 2015 Philippe Brochard <pbrochard@common-lisp.net>
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.
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.
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.
24 ;;; Documentation: If you want to use this file, just add this line in
25 ;;; your configuration file:
27 ;;; (load-contrib "mpd.lisp")
29 ;;; --------------------------------------------------------------------------
33 (format t
"Loading MPD code... ")
37 "Open the Music Player Daemon (MPD) menu"
38 (open-menu (find-menu 'mpd-menu
)))
41 (defun start-sonata ()
43 (do-shell "exec sonata"))
47 (do-shell "exec gmpc"))
50 (defun show-mpd-info ()
51 "Show MPD informations"
52 (info-on-shell "MPD informations:" "mpc")
55 (defun mpd-previous (&optional
(in-menu t
))
56 "Play the previous song in the current playlist"
59 (info-on-shell "MPD:" "mpc prev")
61 (do-shell "mpc prev" nil t
)))
63 (defun mpd-next (&optional
(in-menu t
))
64 "Play the next song in the current playlist"
67 (info-on-shell "MPD:" "mpc next")
69 (do-shell "mpc next" nil t
)))
72 "Toggles Play/Pause, plays if stopped"
73 (do-shell "mpc toggle"))
77 (do-shell "mpc play"))
80 "Stop the currently playing playlists"
81 (do-shell "mpc stop"))
84 (defun mpd-seek-+5%
(&optional
(in-menu t
))
88 (do-shell "mpc seek +5%")
90 (do-shell "mpc seek +5%" nil t
)))
92 (defun mpd-seek--5%
(&optional
(in-menu t
))
96 (do-shell "mpc seek -5%")
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")
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
)
130 (defconfig *mpd-toolbar
* '((mpd-buttons 1)
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
)
146 (if (>= (length mpd-line
) 3)
148 (toolbar-module-text toolbar module
(tb-color mpd-info
)
150 (ensure-printable (first mpd-line
)))
151 (toolbar-module-text toolbar module
(tb-color mpd-info
)
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
)
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
))
170 (let ((pos (toolbar-module-subdiv toolbar module root-x root-y
6)))
172 (0 (mpd-previous nil
))
175 (3 (mpd-seek--5% nil
))
176 (4 (mpd-seek-+5% nil
))
177 (5 (do-shell *mpd-toolbar-client
*))))
178 (refresh-toolbar toolbar
))))