-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemms-init.el
594 lines (513 loc) · 20.9 KB
/
emms-init.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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
;;brew install mpg321 flac123 libtag mp3info mdp
;; https://computingforgeeks.com/install-configure-mpd-ncmpcpp-macos/
;; $ mkdir -p ~/.mpd/playlists
;; $ touch ~/.mpd/{mpd.conf,mpd.db,mpd.log,mpd.pid,mpdstate}
;; $ cat ~/.mpd/mpd.conf
;; music_directory "~/Music"
;; playlist_directory "~/.mpd/playlists"
;; db_file "~/.mpd/mpd.db"
;; log_file "~/.mpd/mpd.log"
;; pid_file "~/.mpd/mpd.pid"
;; state_file "~/.mpd/mpdstate"
;; auto_update "yes"
;; auto_update_depth "2"
;; follow_outside_symlinks "yes"
;; follow_inside_symlinks "yes"
;; audio_output {
;; type "osx"
;; name "CoreAudio"
;; mixer_type "software"
;; }
;; decoder {
;; plugin "mp4ff"
;; enabled "no"
;; }
;; bind_to_address "127.0.0.1"
;; port "6600"
;; user "jmutai"
;; # Visualizer
;; audio_output {
;; type "fifo"
;; name "my_fifo"
;; path "/tmp/mpd.fifo"
;; format "44100:16:2"
;; auto_resample "no"
;; use_mmap "yes"
;; }
(defun my-emms-covers (dir type)
"Choose album cover in DIR deppending on TYPE.
Small cover should be less than 80000 bytes.
Medium - less than 120000 bytes."
(let* ((pics (directory-files-and-attributes
dir t "\\.\\(jpe?g\\|png\\|gif\\|bmp\\)$" t))
(pic (car pics))
(pic-size (nth 8 pic)))
(princ pics)
(let (temp)
(cond
((eq type 'small)
(while (setq temp (cadr pics))
(let ((temp-size (nth 8 temp)))
(if (< temp-size pic-size)
(setq pic temp
pic-size temp-size)))
(setq pics (cdr pics)))
(if (<= (or pic-size 80001) 80000)
(car pic)))
((eq type 'medium)
(if (and pic (setq temp (cadr pics)))
(progn
(setq pics (cdr pics))
(let ((temp-size (nth 8 temp)))
(let ((small temp)
(small-size temp-size))
(if (< pic-size small-size)
(setq small pic
small-size pic-size
pic temp
pic-size temp-size))
(while (setq temp (cadr pics))
(setq temp-size (nth 8 temp))
(cond
((< temp-size small-size)
(setq pic small
pic-size small-size
small temp
small-size temp-size))
((< temp-size pic-size)
(setq pic temp
pic-size temp-size)))
(setq pics (cdr pics)))
(car (if (<= pic-size 120000) pic
small)))))
(car pic)))
((eq type 'large)
(while (setq temp (cadr pics))
(let ((temp-size (nth 8 temp)))
(if (> temp-size pic-size)
(setq pic temp
pic-size temp-size)))
(setq pics (cdr pics)))
(car pic))))))
(use-package emms
:init
(setq emms-directory (expand-file-name "~/.emacs.d/emms/"))
:config
(require 'emms-setup)
(emms-all)
;; Use only libtag for tagging.
(require 'emms-info-libtag)
;; (emms-default-players)
(setq emms-playlist-buffer-name "*Music*")
(setq emms-info-libtag-program-name (expand-file-name "bin/emms-print-metadata" marcel-lisp-dir))
(if (executable-find emms-info-libtag-program-name)(setq emms-info-functions '(emms-info-libtag)))
(setq emms-source-file-default-directory "/Volumes/MusicFiles/MusicCopy/Music")
(setq emms-source-file-directory-tree-function 'emms-source-file-directory-tree-find)
(setq emms-browser-covers #'emms-browser-cache-thumbnail-async)
;; (setq emms-browser-thumbnail-small-size 64)
;; (setq emms-browser-thumbnail-medium-size 128)
;; (setq emms-browser-covers 'my-emms-covers)
(setq emms-stream-default-action "play")
;; «enable-emms-scoring» (to ".enable-emms-scoring")
(setq emms-score-enabled-p t)
;; «Start-browser-with-album» (to ".Start-browser-with-album")
(setq emms-browser-default-browse-type 'info-artist)
(setq emms-browser-default-covers (list (expand-file-name "emms/cover_small.jpg" marcel-lisp-dir)))
(emms-history-load)
(emms-mode-line 1)
(emms-playing-time 1)
;; (define-key emms-stream-mode-map (kbd "s") 'emms-stop)
(define-prefix-command 'my-emms-map)
(bind-keys :map global-map
:prefix-map my-emms-map
:prefix "<f9>"
("r" . emms-streams)
("+" . emms-volume-raise)
("=" . emms-volume-raise)
("-" . emms-volume-lower)
("b" . emms-smart-browse)
("t" . emms-player-mpd-show)
("s" . emms-stop)
("RET" . emms-start)
("c" . emms-browser-clear-playist)
("p" . emms-pause)
(">" . emms-next)
("<" . emms-previous)
("<right>" . emms-next)
("<left>" . emms-previous)
("<up>" . emms-pause)
("m" . emms-mode-line-toggle))
:bind
(("C-c +" . emms-volume-mode-plus)
("C-c -" . emms-volume-mode-minus)
("C-c e e" . emms)
("C-c e SPC" . emms-pause)
("C-c e p" . emms-browser-add-tracks-and-play)
("C-c e +" . emms-seek-forward)
("C-c e -" . emms-seek-backward)
("C-c e s" . emms-seek)
("C-c e b" . emms-smart-browse)
("C-c e r" . emms-player-mpd-update-all-reset-cache)
("C-c e m" . my-emms-mpd-set-player)
("C-c e v" . my-emms-vlc-set-player)
("C-c e x" . my-emms-mpv-set-player)
("C-c e y" . my-emms-mplayer-set-player)
("C-c e n" . my-emms-mpd-kill-music-daemon)
("C-c e u" . my-emms-mpd-update-database)
("C-c e <up>" . emms-start)
("C-c e <down>" . emms-stop)
("C-c e <left>" . emms-previous)
("C-c e <right>" . emms-next)
;;("<XF86AudioPlay>" . emms-pause)
;;("<XF86AudioStop>" . emms-stop)
;;("<XF86AudioPrev>" . emms-previous)
;;("<XF86AudioNext>" . emms-next)
("C-c e [" . my/emms-player-mplayer-slow-down)
("C-c e ]" . my/emms-player-mplayer-speed-up))
)
(define-prefix-command 'my-emms-map)
(bind-keys :map global-map
:prefix-map my-emms-map
:prefix "<f9>"
("r" . emms-streams)
("+" . emms-volume-raise)
("=" . emms-volume-raise)
("-" . emms-volume-lower)
("b" . emms-smart-browse)
("t" . emms-player-mpd-show)
("s" . emms-stop)
("RET" . emms-start)
("c" . emms-browser-clear-playist)
("p" . emms-pause)
(">" . emms-next)
("<" . emms-previous)
("<right>" . emms-next)
("<left>" . emms-previous)
("<up>" . emms-pause)
("m" . emms-mode-line-toggle))
(defun my-emms-add-all-players ()
(interactive)
(setq emms-player-list '(emms-player-vlc-playlist
emms-player-vlc
emms-player-mpg321
emms-player-ogg123
emms-player-mplayer
emms-player-mpv
emms-player-mpd
)))
(defun my-emms-vlc-set-player ()
(interactive)
(require 'emms-player-vlc)
(define-emms-simple-player vlc '(file url)
(concat "\\`\\(http[s]?\\|mms\\)://\\|"
(apply #'emms-player-simple-regexp
emms-player-base-format-list))
"vlc" "--extraintf=rc")
(define-emms-simple-player vlc-playlist '(streamlist)
"\\`http[s]?://"
"vlc" "--extraintf=rc")
(setq emms-player-list '(emms-player-vlc emms-player-vlc-playlist))
(setq emms-player-vlc-command-name
"/Applications/VLC.app/Contents/MacOS/VLC")
(setq emms-player-vlc-parameters '("--extraintf=rc"))
(setq emms-stream-info-backend 'vlc)
)
(defun my-emms-mplayer-set-player ()
(interactive)
(require 'emms-player-mplayer)
(define-emms-simple-player mplayer '(file url)
(regexp-opt '(".ogg" ".mp3" ".wav" ".mpg" ".mpeg" ".wmv" ".wma"
".mov" ".avi" ".divx" ".ogm" ".asf" ".mkv" "http://" "mms://"
".rm" ".rmvb" ".mp4" ".flac" ".vob" ".m4a" ".flv" ".ogv" ".pls"))
"mplayer" "-slave" "-quiet" "-really-quiet" "-fullscreen")
(setq emms-player-list '(emms-player-mplayer)))
(defun my-emms-mpv-set-player ()
(interactive)
(require 'emms-player-mpv)
;; (define-emms-simple-player mpv '(file url streamlist playlist)
;; (concat "\\`\\(http\\|mms\\)://\\|"
;; (emms-player-simple-regexp
;; "ogg" "mp3" "wav" "mpg" "mpeg" "wmv" "wma"
;; "mov" "avi" "divx" "ogm" "ogv" "asf" "mkv"
;; "rm" "rmvb" "mp4" "flac" "vob" "m4a" "ape"
;; "flv" "webm" "aac"))
;; "mpv" "--quiet" "--really-quiet --no-audio-display")
(setq emms-player-list '(emms-player-mpv))
(add-to-list 'emms-player-mpv-parameters "--no-audio-display")
(add-to-list 'emms-info-functions 'emms-info-cueinfo)
(add-to-list 'emms-info-functions 'emms-info-ogginfo)
(add-to-list 'emms-info-functions 'emms-info-mp3info)
(defun ambrevar/emms-play-on-add (old-pos)
"Play tracks when calling `emms-browser-add-tracks' if nothing
is currently playing."
(interactive)
(when (or (not emms-player-playing-p)
emms-player-paused-p
emms-player-stopped-p)
(with-current-emms-playlist
(goto-char old-pos)
;; if we're sitting on a group name, move forward
(unless (emms-playlist-track-at (point))
(emms-playlist-next))
(emms-playlist-select (point)))
(emms-stop)
(emms-start)))
(add-hook 'emms-browser-tracks-added-hook 'ambrevar/emms-play-on-add)
(defun emms-player-mpv-volume-change (v)
"Change the volume by V for mac."
(let* ((cmd (format "%d" (* 10 v))))
(emms-player-mpv-cmd `(add volume ,cmd))
(emms-player-mpv-volume-query)))
(when running-macos
(custom-set-variables
'(emms-volume-change-function #'emms-player-mpv-volume-change)))
(defun emms-player-mpv-volume-set (v)
"Set the volume to V for mac."
(interactive)
(emms-player-mpv-cmd `(set_property volume ,v))
(emms-player-mpv-volume-query))
(defun emms-player-mpv-volume-mute-unmute ()
"Toggle mute status for mac."
(interactive)
(emms-player-mpv-cmd '(cycle mute))
(emms-player-mpv-ipc-req-send '(get_property mute)
(lambda (pts-end err)
(message "Pts End %s Err = %s" pts-end err)
(if err
(unless (and (stringp err)
(string= err "property unavailable"))
(message "Calling ems-player-mpv-ipc-req-error printer")
(emms-player-mpv-ipc-req-error-printer pts-end err))
(when pts-end
(message "Mute: %s" pts-end))))))
(defun emms-player-mpv-volume-query ()
"Show the volume settings for mac"
(interactive)
(emms-player-mpv-ipc-req-send '(get_property volume)
(lambda (pts-end err)
(if err
(unless (and (stringp err)
(string= err "property unavailable"))
(message "Calling ems-player-mpv-ipc-req-error printer")
(emms-player-mpv-ipc-req-error-printer pts-end err))
(when pts-end
(message "Volume %s" pts-end))))))
)
(my-emms-mpv-set-player)
(defun my-emms-mpd-set-player ()
(interactive)
(require 'emms-player-mpd)
(setq emms-seek-seconds 5
emms-player-list '(emms-player-mpd)
emms-info-functions '(emms-info-mpd)
emms-volume-change-function 'emms-volume-mpd-change
emms-player-mpd-music-directory emms-source-file-default-directory
) ;FIXME: use mpd.conf
;; set mpd address and port
(setq emms-player-mpd-server-name "localhost")
(setq emms-player-mpd-server-port "6600")
(my-emms-mpd-start-music-daemon)
)
;; https://github.com/daedreth/UncleDavesEmacs#emms-with-mpd
(defun my-emms-mpd-start-music-daemon ()
"Start MPD, connects to it and syncs the metadata cache."
(interactive)
(shell-command "mpd")
(my-emms-mpd-update-database)
(emms-player-mpd-connect)
(emms-cache-set-from-mpd-all)
(message "MPD Started!"))
;;(global-set-key (kbd "s-m c") 'mpd/start-music-daemon)
;; https://github.com/daedreth/UncleDavesEmacs#emms-with-mpd
(defun my-emms-mpd-kill-music-daemon ()
"Stops playback and kill the music daemon."
(interactive)
(emms-stop)
(call-process "killall" nil nil nil "mpd")
(message "MPD Killed!"))
;;(global-set-key (kbd "s-m k") 'mpd/kill-music-daemon)
;; https://github.com/daedreth/UncleDavesEmacs#emms-with-mpd
(defun my-emms-mpd-update-database ()
"Updates the MPD database synchronously."
(interactive)
(call-process "mpc" nil nil nil "update")
(message "MPD Database Updated!"))
;;(global-set-key (kbd "s-m u") 'mpd/update-database)
;;(emms-player-mpd-connect)
;; (emms-player-mpd-update-all)
;;(emms-cache-set-from-mpd-all)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Settings for MPV
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; (use-package emms-player-simple-mpv
;; :config
;; ;; This plugin provides control functions (e.g. ab-loop, speed, fullscreen).
;; (require 'emms-player-simple-mpv-control-functions)
;; )
;; (use-package emms-player-simple-mpv
;; :config
;; ;; This plugin provides control functions (e.g. ab-loop, speed, fullscreen).
;; (require 'emms-player-simple-mpv-control-functions)
;; )
;; (defun emms-player-mpv-volume-change (v)
;; "Change the volume by V for mpv."
;; (let ((cmd (format "echo 'add volume %d' > %s" v emms-mpv-input-file)))
;; (call-process-shell-command cmd nil nil nil)))
;; (defun emms-player-mpv-volume-set (v)
;; "Set the volume to V for mpv."
;; (interactive "nmpv volume : ")
;; (let ((cmd (format "echo 'set volume %d' > %s" v emms-mpv-input-file)))
;; (call-process-shell-command cmd nil nil nil)))
;; (defun emms-player-mpv-volume-mute ()
;; "Toggle mute status for mpv."
;; (interactive)
;; (let ((cmd (format "echo 'cycle mute' > %s" emms-mpv-input-file)))
;; (call-process-shell-command cmd nil nil nil)))
;; (custom-set-variables
;; '(emms-volume-change-function #'emms-player-mpv-volume-change))
;; (define-emms-simple-player-mpv my-mpv '(file url streamlist playlist)
;; (concat "\\`\\(http[s]?\\|mms\\)://\\|"
;; (apply #'emms-player-simple-regexp
;; "aac" "pls" "m3u"
;; emms-player-base-format-list))
;; "mpv" "--no-terminal" "--force-window=no" "--audio-display=no")
;; (emms-player-simple-mpv-add-to-converters
;; 'emms-player-my-mpv "." '(playlist)
;; (lambda (track-name) (format "--playlist=%s" track-name)))
;; (setq emms-player-list '(emms-player-my-mpv))
(defun emms-player-mac-volume-change (v)
"Change the volume by V for mac."
(let* (
(volume (call-process-shell-command "osascript -e 'output volume of (get volume settings)'" nil nil nil))
(new-volume (max 0 (+ volume v)))
(cmd (format "osascript -e 'set volume output volume (output volume of (get volume settings) + %d)'" (* v 10))))
(message (format "%s" cmd))
(shell-command cmd )))
(when running-macos
(custom-set-variables
'(emms-volume-change-function #'emms-player-mac-volume-change)))
(defun emms-player-mac-volume-set (v)
"Set the volume to V for mac."
(interactive "mac volume (from 0 to 10): ")
(let ((cmd (format "osascript -e 'set volume %d'" v)))
(call-process-shell-command cmd nil nil nil)))
(defun emms-player-mac-volume-mute-unmute ()
"Toggle mute status for mac."
(interactive)
(let ((cmd "osascript -e 'set volume output muted not (output muted of (get volume settings))'"))
(call-process-shell-command cmd nil nil nil)))
;; change the volume by 1%
;; osascript -e "set volume output volume (output volume of (get volume settings) + 1) --100%"
(defun emms-player-mac-volume-query ()
"Show the volume settings for mac"
(interactive)
(message (format "%s" (shell-command-to-string "osascript -e '(get volume settings)'" ))))
;; (use-package helm-emms
;; :defer t
;; :after (helm emms)
;; :config
;; (setq helm-emms-default-sources
;; '(helm-source-emms-dired
;; helm-source-emms-files ; Disable for a huge speed-up.
;; helm-source-emms-streams)))
(defun chunyang-emms-indicate-seek (_sec)
(let* ((total-playing-time (emms-track-get
(emms-playlist-current-selected-track)
'info-playing-time))
(elapsed/total (/ (* 100 emms-playing-time) total-playing-time)))
(with-temp-message (format "[%-100s] %2d%%"
(make-string elapsed/total ?=)
elapsed/total)
(sit-for 2))))
(add-hook 'emms-player-seeked-functions #'chunyang-emms-indicate-seek 'append)
;; «Update-mpd-directory» (to ".Update-mpd-directory")
(defun my-emms-update-and-clean-cache ()
(interactive)
(when emms-cache-db
(clrhash emms-cache-db)
(and (file-exists-p emms-cache-file)
(delete-file emms-cache-file))
(and (file-exists-p emms-history-file)
(delete-file emms-history-file))
(with-current-buffer (find-file-noselect emms-cache-file)
(save-buffer))
;;(emms-add-directory-tree "~/Music/")
))
(defun my-emms-track-simple-description (track)
"Simple function to give a user-readable description of a track.
If it's a file track, just return the file name. Otherwise,
return the type and the name with a colon in between.
Hex-encoded characters in URLs are replaced by the decoded
character."
(let ((type (emms-track-type track)))
(cond ((eq 'file type)
(file-name-sans-extension
(file-name-nondirectory (emms-track-name track))))
((eq 'url type)
(emms-format-url-track-name (emms-track-name track)))
(t (concat (symbol-name type)
": " (emms-track-name track))))))
(setq emms-track-description-function 'my-emms-track-simple-description)
;; (defun emms-player-vlc-volume-query ()
;; "Show the volume settings for vlc"
;; (interactive)
;; (process-send-string emms-player-simple-process-name "volume 100\n")
;; (message (format "%s" (shell-command-to-string "osascript -e '(get volume settings)'" ))))
;; (defun emms-player-vlc-pause ()
;; "Depends on vlc's rc mode."
;; (interactive)
;; (process-send-string
;; emms-player-simple-process-name "pause\n"))
;; (defun emms-player-vlc-seek (sec)
;; "Seek relative within a stream."
;; (when (not (= 0 sec))
;; (process-send-string
;; emms-player-simple-process-name
;; (if (< 0 sec) "fastforward\n" "rewind\n"))))
;; (defun emms-player-vlc-seek-to (sec)
;; "Seek to time SEC within the stream."
;; (process-send-string
;; emms-player-simple-process-name
;; (format "seek %d\n" sec)))
(use-package minibuffer-line)
(setq minibuffer-line-format
'("" (:eval system-name)
" | " (:eval (format-time-string "%F %R"))
" [ " (:eval (string-trim-right (emms-track-description (emms-playlist-current-selected-track)))) " ]"))
(minibuffer-line-mode)
;; (use-package emms-mode-line-cycle
;; :config
;; (emms-mode-line 1)
;; (emms-playing-time 1)
;; (emms-mode-line-cycle 1)
;; ;; `emms-mode-line-cycle' can be used with emms-mode-line-icon.
;; ;; (require 'emms-mode-line-icon)
;; (custom-set-variables
;; ;; '(emms-mode-line-cycle-use-icon-p nil)
;; ; '(emms-mode-line-cycle-max-width 15)
;; ; '(emms-mode-line-cycle-additional-space-numb 4)
;; ; '(emms-mode-line-cycle-use-icon-p t)
;; '(emms-mode-line-format " [%s]")
;; ; '(emms-mode-line-cycle-any-width-p t)
;; '(emms-mode-line-cycle-velocity 2)
;; ;; '(emms-mode-line-cycle-current-title-function
;; ;; (lambda ()
;; ;; (let ((track (emms-playlist-current-selected-track)))
;; ;; (cl-case (emms-track-type track)
;; ;; ((streamlist)
;; ;; (let ((stream-name (emms-stream-name
;; ;; (emms-track-get track 'metadata))))
;; ;; (if stream-name stream-name (emms-track-description track))))
;; ;; ((url) (emms-track-description track))
;; ;; (t (file-name-nondirectory
;; ;; (emms-track-description track)))))))
;; ;; '(emms-mode-line-titlebar-function
;; ;; (lambda ()
;; ;; '(:eval
;; ;; (when emms-player-playing-p
;; ;; (format " %s %s"
;; ;; (format emms-mode-line-format (emms-mode-line-cycle-get-title))
;; ;; emms-playing-time-string))))))
;; ))