-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmpcel.el
253 lines (207 loc) · 7.47 KB
/
mpcel.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
;;; mpcel.el --- A mpd (Music Player Daemon) client
;; Copyleft (C) 2006-2009 Jean-Baptiste Bourgoin <monsieur.camille@gmail.com>
;; GPLv3
;; Author: Jean-Baptiste Bourgoin <monsieur.camille@gmail.com>
;; Maintainer: Jean-Baptiste Bourgoin <monsieur.camille@gmail.com>
;; Version: 1.3
;; Keywords: music
;; This file is not part of GNU Emacs.
;; This is free software; you can redistribute it and/or modify it under
;; the terms of the GNU General Public License as published by the Free
;; Software Foundation; either version 2, or (at your option) any later
;; version.
;;
;; This is distributed in the hope that it will be useful, but WITHOUT
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
;; for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation
;; 51 Franklin Street, Fifth Floor
;; Boston, MA 02110-1301
;; USA
;; Description :
;;
;; mpcel.el is a mpc frontend for Emacs. mpc is a command line tool to
;; interface mpd (the Music Player Daemon). With mpcel.el you can control
;; mpd through mpc with the aim of playing your music collection.
;; Installation :
;;
;; 1) install mpc (http://www.musicpd.org/mpc.shtml)
;; & mpd (http://www.musicpd.org)
;; 2) type in your .emacs :
;; (load "/path/to/mpcel.el")
;; 3) evaluate the previous expression, or restart Emacs.
;; 4) to start the mpd daemon type M-x mpcel-mpd-start
;; 5) to add songs type M-x mpcel-add-songs
;; 6) more help can be find on my website (EmacsWiki doesn't accept
;; it, mail me for more information)
;; Acknowledgments :
;;
;; Kim F. Storm : who give me a lot of advice about LISP code
;; (defcustom ; call-process ; eq ...). He's the source of
;; almost all the differences between v1.0 & v1.1
;;
;; Rene Borchers : the author of the mpcel-playlist-load function
;;
;; Richard M. Stallman & Erwin David : who pointed out to me
;; that my old project description was rather laconic.
;;
;; John Sullivan : who pointed out to me that the adress of the FSF
;; has changed ;)
(defcustom mpcel-mpd-program (executable-find "mpd")
"MPD program"
:type 'string
:group 'mpcel)
(defcustom mpcel-mpc-program (executable-find "mpc")
"MPC program"
:type 'string
:group 'mpcel)
;; MPCEL Version
(defun mpcel-version ()
"mpcel version. This is the first."
(interactive)
(message "mpcel version 1.1 - written in 2006 by Bourgoin Jean-Baptiste"))
;; MPD
;; Start mpd daemon :
(defun mpcel-mpd-start ()
"Start mpd daemon"
(interactive)
(if (eq 0 (call-process mpcel-mpd-program nil nil nil))
(message "mpd is ready")
(message "mpd failed to start")))
;; update database
(defun mpcel-mpd-update ()
"Update mpd database"
(interactive)
(if (eq 0 (call-process mpcel-mpc-program nil nil nil "update"))
(message "i'm updating your database ;)")
(message "Hey ! Have you made a database ?")))
;; MPC
;; Player control :
; mpc play track number ### :
(defun mpcel-play (number)
"Play the track number ## with mpc"
(interactive "MTrack number (type 0 to begin or resume): ")
(call-process mpcel-mpc-program nil nil nil "play" number)
(message "playing : %s"
(shell-command-to-string "mpc status | head -n1")))
;; mpc stop playing music :
(defun mpcel-stop ()
"Stop playing music in mpd"
(interactive)
(call-process mpcel-mpc-program nil nil nil "stop")
(message "music is stoped"))
;; toggle random mode.
(defun mpcel-random-mode (onoroff)
"mpcel : toggle random mode."
(interactive
"MRandomize ? ( \"on\" or \"off\") : ")
(call-process mpcel-mpc-program nil nil nil "random" onoroff)
(message (concat "Random mode : " onoroff)))
;; toggle repeat mode.
(defun mpcel-repeat-mode (offoron)
"mpcel : toggle repeat mode."
(interactive
"MRandomize ? ( \"on\" or \"off\") : ")
(call-process mpcel-mpc-program nil nil nil "reapeat" offoron)
(message (concat "Repeat mode : " offoron)))
;; mpc pause playing music :
(defun mpcel-pause ()
"Pause music in mpd"
(interactive)
(call-process mpcel-mpc-program nil nil nil "pause")
(message "status : %s is paused"
(shell-command-to-string "mpc status | head -1")))
;; mpc play the next music :
(defun mpcel-next ()
"Play the next music in mpd"
(interactive)
(call-process mpcel-mpc-program nil nil nil "next")
(message "playing : %s"
(shell-command-to-string "mpc status | head -1")))
;; mpc play the previous music :
(defun mpcel-prev ()
"Play the previous music in mpd"
(interactive)
(call-process mpcel-mpc-program nil nil nil "prev")
(message "playing : %s"
(shell-command-to-string "mpc status | head -1")))
;; Crossfading
(defun mpcel-crossfade (cfade)
"mpd : Sets and gets the current amount of crossfading between song"
(interactive "MCrossfading between songs in seconds (0 to disable) : ")
(call-process mpcel-mpc-program nil nil nil "crossfade" cfade)
(message "amount of crossfading in seconds : %s" cfade))
;; set the volume
(defun mpcel-volume (vol)
"mpcel : increase or decrease volume"
(interactive "M[+-]value : ")
(call-process mpcel-mpc-program nil nil nil "volume" vol))
;; Playlist control :
;; load playlist -- THANKS TO RENE BORCHERS !
(defun mpcel-playlist-load (playlist)
"mpcel : Loads playlist"
(interactive "MPlaylist name: ")
(if (eq 0 (call-process mpcel-mpc-program nil nil nil "load" playlist))
(message "Playlist %s loaded" playlist)
(message "Playlist %s not found" playlist))
)
;; prints the playlist :
(defun mpcel-playlist-print ()
"Prins entire mpd's playlist"
(interactive)
(shell-command
"mpc --format \"[%artist%--[%album%--[%title%]]]|[%file%]\" playlist"))
;; clear playlist
(defun mpcel-playlist-clear ()
"Clear the mpd playlist"
(interactive)
(call-process mpcel-mpc-program nil nil nil "clear")
(message "the playlist is cleared"))
;; add song :
(defun mpcel-add-songs (art rest)
"Add songs in the mpd playlist"
(interactive
"MArtist : \nMChoose album or song (type 0 for all) : ")
(let (mall mch)
(setq muall
(concat "mpc search artist " art " | mpc add"))
(setq mchse
(concat "mpc search artist " art " | grep -i " rest " | mpc add"))
(if (eq nil rest)
(shell-command muall)
(shell-command mchse)))
(message "Tracks : %s"
(shell-command-to-string "mpc playlist | wc -l")))
;; shuffle playlist
(defun mpcel-playlist-shuffle ()
"mpcel : a Troll come to make your playlist untidiness"
(interactive)
(call-process mpcel-mpc-program nil nil nil "shuffle")
(message "what a mess !"))
;; move song
(defun mpcel-playlist-move (pos1 pos2)
"mpcel : Moves song at position x to the postion y in the playlist"
(interactive
"nMove song number : \nnTo : ")
(let (pstn)
(setq pstn
(concat "mpc move "
(number-to-string pos1) " " (number-to-string pos2)))
(shell-command-to-string pstn))
(message (concat
"Track number " (number-to-string pos1)
" move to position " (number-to-string pos2))))
;; crop -- Remove all songs except for the currently playing song:
(defun mpcel-playlist-crop ()
"mpd : Remove all songs except for the currently playing song"
(interactive)
(if (eq 0 (call-process mpcel-mpc-program nil nil nil "crop"))
(message "The only survivor is : %s"
(shell-command-to-string "mpc status | head -1"))
(message "no song is playing")))
(provide 'mpcel)
;;; mpcel.el ends here