-
Notifications
You must be signed in to change notification settings - Fork 19
/
mingus.el
4661 lines (3998 loc) · 165 KB
/
mingus.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
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;; mingus.el --- MPD Interface
;; _
;; _ __ ___ (_)_ __ __ _ _ _ ___
;; | '_ ` _ \| | '_ \ / _` | | | / __|
;; | | | | | | | | | | (_| | |_| \__ \
;; |_| |_| |_|_|_| |_|\__, |\__,_|___/
;; |___/
;; -----------------------------------------------------------
;; MPD Interface that's No Garbage, but (just) Utterly Stylish
;; -----------------------------------------------------------
;; ....................but actually named after a man so named
;;
;; Copyright (C) 2006-2011, 2015, 2016 Niels Giesen <com dot gmail at
;; niels dot giesen, in reversed order>
;; Author: Niels Giesen <pft on #emacs>
;; URL: https://github.com/pft/mingus
;; Package-Requires: ((libmpdee "2.2"))
;; Contributors (with patches and bug reports): Jeremie Lasalle
;; Ratelle, "Lexa12", Marc Zonzon, Mark Taylor, Drew Adams, Alec
;; Heller, "death" (github.com/death), Александр Цамутали, Maximilian
;; Gass, Dan King, Vincent Zhang, and Ben Metzger
;; Version: 0.34
;; Or Alice's Wonderland
;; Latest version can be found at http://github.com/pft/mingus/
;; For Changes, please view http://github.com/pft/mingus/commits/master
;; Keywords: multimedia, elisp, music, mpd
;; This file is *NOT* part of GNU Emacs
;; This program 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
;; of the License, or (at your option) any later version.
;; This program 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 this program; if not, write to the Free Software
;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
;; 02111-1307, USA.
;;; Commentary:
;; Mingus is a client for the Music Player Daemon (MPD). It provides an
;; interactive interface, where most emphasis lies on on-screen display/editing
;; of the playlist, and browsing in a buffer. However, minibuffer operations are
;; becoming more intelligent with each version (with completive browsing
;; somewhat like in `find-file', and searching on multiple fields, also with
;; auto-completion).
;; Installation (Melpa)
;; ====================
;; Mingus is now installable from Melpa, and this is the preferred method.
;; NOTE if you want to use the mingus-stays-home library (see below),
;; you still will have to put
;; (require 'mingus-stays-home)
;; in your init file.
;; For non-Melpa installs, see below.
;; Usage
;; =====
;; After installation the following commands will be available:
;; 1) M-x mingus-help shows the Mingus help buffer;
;; 2) M-x mingus will show the playlist;
;; 3) M-x mingus-browse navigates your music collection.
;; You can switch between these buffers with keys 1: help, 2: playlist, 3: browser.
;; For other key bindings, see M-x mingus-help.
;; Mingus-stays-home
;; =================
;; When the computer running the mpd service is the same as the one from which
;; mingus is being run, you may use the library mingus-stays-home.
;; This library can provide stuff such as:
;; - id3 tagging
;; - cd-burning
;; - integration with dired and the shell
;; Check the file mingus-stays-home.el itself if you want to know
;; more.
;; Non-Melpa Installation
;; ======================
;; Make sure you have libmpdee.el in your load-path. NOTE for old-time users:
;; mpc is not required anymore. Everything is done in lisp. This also means that
;; mingus has become multi-platform (in an easy way).
;; 1. When you install both the main mingus AND mingus-stays-home:
;; byte-compile, IN ORDER, repeat: IN ORDER, the files mingus.el and
;; mingus-stays-home.el
;; Add the following to your .emacs:
;; (add-to-list 'load-path "/path/where/mingus-and-mingus-stays-home-reside")
;; (autoload 'mingus "mingus-stays-home" nil t)
;; 2. Mingus only (so NO mingus-stays-home) :
;; byte-compile the file mingus.el
;; Add the following to your .emacs:
;; (add-to-list 'load-path "/path/where/mingus/resides")
;; (autoload 'mingus "mingus" nil t)
;; Design Issues
;; =============
;; No editing of metadata tags is provided in mingus itself. This is because mpd is
;; designed to be run in a network as a server (although it can be used on a single
;; system, which, in fact, is what I do); as such, clients to mpd are unaware of mpd's
;; root dir, and possibly/probably do not have write permissions on the music
;; files.
;; If you DO use mingus-stays-home, rough metadata-editing IS provided. `mingus-id3-set'
;; tries to guess the values for artist, song, track number, and album from the name
;; encountered in the playlist. Use it with caution though, as as I said, it is still
;; rough, e.g. having to abstract away from differences between the various tagging
;; formats. I AM looking into taglib for an elegant solution. But that will take some
;; time. So be patient.
;; The interface is roughly based on that on ncmpc. Many keybindings are alike,
;; except for some notoriously vi-style-ones. Some significant features (main
;; reasons to write this stuff) :
;; MARKING Notice specifically the possibility to mark multiple songs in the playlist
;; for movement or deletion (by pressing the spacebar one toggles the mark at the
;; current line; if there is a region, it marks all songs in the region.) Pressing 'y'
;; asks for a regular expression against which to match the songs. Pressing 'Y' unmarks
;; alike. If a song matches, it is marked. Unmarking all marks happens with a single
;; capital "U".
;; INSERTION POINT Another nice feature is "mingus-set-insertion-point" (Key:
;; "i") : mark a song after which you would like your next insertions to take
;; place. Then go inserting. Unset this behaviour with "u"
;; (mingus-unset-insertion-point), and songs will be added to 3the end of the
;; playlist again. As of version 0.24 this is NOT time-consuming. Yeah!
;; NOTE: right now these two functions are mutually exclusive.
;; Dired
;; =====
;; Ability to snap to the file location of a song instantly in `dired', so as
;; to perform file management or other actions on these files easily (such as
;; removal, movement or renaming), or just to check wtfs '3.ogg' actually
;; refers to.
;; You might want to change the `dired-mode-map' so that it will play well with
;; Mingus. If you want to, you can set the variable `mingus-dired-add-keys' to
;; t; this can be done with `mingus-customize'. It will set "SPC" to
;; `mingus-dired-add', "C-u SPC" to `mingus-dired-add-and-play' and add an item
;; for `mingus-dired-add' to the menu-bar in dired. `mingus-dwim-add' and
;; `mingus-dwim-add-and-play' (see below) calls mingus-dired-add when in dired,
;; so binding this to a global key might be a nice solution too.
;; For those already familiar with mpd, and have set that up, you're done now.
;; If you get a message like
;; MPD_HOST and/or MPD_PORT environment variables are not set message: problems
;; getting a response from "localhost" on port 6600 : Connection refused
;; there are two options:
;; 1. you want to run locally, so run mpd
;; first. Do so from somewhere else or simply evaluate (mingus-start-daemon).
;; On some configurations of mpd this must be done as root.
;; For those unfamiliar with mpd, to set it up, put something like the following
;; in ~/.mpdconf (this is for when run a user)
;; port "6600"
;; music_directory "/your/music/directory"
;; playlist_directory "~/playlists"
;; log_file "~/.mpd.log"
;; message_file "~/.mpd.err"
;;
;; then run mpd
;; 2. you want to connect to a remote host, but have not set the
;; environment variables MPD_HOST and/or MPD_PORT. Do so by calling
;; (mingus-set-variables-interactively) (settings lost when emacs
;; restarted) or by means of customization (mingus-customize) or
;; (customize-group 'mingus).
;; NEW in mingus 0.21: `mingus-wake-up-call'; fixed the lisp-max-eval-depth
;; error message when leaving mingus-info on for a while; allowing spaces in
;; minibuffer operations, such as loading and saving of playlists, radio-streams
;; and the like, but most of all: inclusion of mingus-stays-home, which provides
;; nice integration features. See that file for more information. Emacs21
;; compatablity, except for parts of mingus-stays-home.
;; Known bugs
;; ==========
;; * a file name cannot have a double quotes (") or a backtick (`) in it. Do not
;; know how to fix that, so if anyone feels so inclined... You CAN query your
;; database (M-x mingus-query-regexp " RET) to know if you are in the possession
;; of such files, so you can adjust their names (with mingus-stays-home
;; installed: press 0 (zero) to go to dired to do so). The only way to insert
;; such files currently is by inserting their parent directory.
;; point-of-insertion only works with one file or directory at a time
;;; Code:
;; (@> "requirements")
(require 'cl-lib)
(require 'subr-x)
(require 'dired)
(require 'thingatpt)
(require 'url)
(require 'libmpdee)
;; (@> "globals")
(defvar mingus-header-height 0)
(defvar mingus-marked-list nil)
(defvar mingus-wake-up-call nil)
(defvar mingus-timer nil)
(defvar mingus-status nil
"Current status of the connection to MPD (nil or t).")
(defvar mingus-browse-command-history nil
"Stack of commands issued to obtain a listing in Mingus Browse buffer.
This is used by `mingus-refresh'.")
(make-variable-buffer-local 'mingus-browse-command-history)
(defvar mingus-marked-list nil
"List of marked songs, identified by songid")
(defvar *mingus-point-of-insertion* nil "Insertion point for mingus")
(defvar *mingus-positions* nil "Cursor positions retained in *Mingus Browser*")
(defvar *mingus-header-when-empty* "Press ? for help, 3 for Mingus Browser, 0 for dired."
"Header to show when the playlist is empty")
(defvar mingus-propertized-song-strings
(make-hash-table :test 'eq
:size 1000)
"Song string cache formatted according to `mingus-playlist-format'.
Songs are hashed by their MPD ids.")
(defvar mingus-song-strings
(make-hash-table :test 'eq
:size 1000)
"Cache for song strings according to `mingus-playlist-format',
Songs are hashed by their MPD ids")
(defun mingus-clear-cache ()
"Clear Mingus' caches."
(interactive)
(mapcar
#'clrhash
(list mingus-propertized-song-strings
mingus-song-strings)))
(cl-defstruct (mingus-data)
(playlist -1)
(song nil))
(defvar mingus-data (make-mingus-data))
(defvar *mingus-NP-mark* nil)
(defvar *mingus-pausing-mark* nil)
;; (@> "faces")
(defgroup mingus-faces ()
"Customization group for faces in Mingus"
:prefix "mingus-"
:group 'mingus)
(defface mingus-directory-face
'((default)
(((background light)) (:foreground "#a0606d"))
(((background dark)) (:foreground "#ffa500")))
"Face for displaying directories"
:group 'mingus-faces)
(defface mingus-artist-face
'((((background light)) (:foreground "#7560a0"))
(((background dark)) (:foreground "#b7a6da")))
"Face for displaying song files"
:group 'mingus-faces)
(defface mingus-album-face
'((default (:underline t))
(((background light)) (:foreground "#ba6746"))
(((background dark)) (:foreground "#ce5c32")))
"Face for displaying song files"
:group 'mingus-faces)
(defface mingus-album-stale-face
'((default)
(((background light)) (:foreground "#ba6746"))
(((background dark)) (:foreground "#ce5c32")))
"Face for displaying song files"
:group 'mingus-faces)
(defface mingus-song-file-face
'((default)
(((background light)) (:foreground "#616fa2"))
(((background dark)) (:foreground "lightgreen")))
"Face for displaying song files"
:group 'mingus-faces)
(defface mingus-playlist-face
'((default)
(((background light)) (:foreground "#918e2d"))
(((background dark)) (:foreground "yellow")))
"Face for displaying playlist files"
:group 'mingus-faces)
(defface mingus-mark-face
'((t :bold t :foreground "pink"))
"Mingus face for marking."
:group 'mingus-faces)
(defface mingus-playing-face
'((default)
(((background light)) (:foreground "#c3be3d"))
(((background dark)) (:foreground "#cac655")))
"Face for playing mark"
:group 'mingus-faces)
(defface mingus-pausing-face
'((default)
(((background light)) (:foreground "#979797"))
(((background dark)) (:foreground "#d2d2d2")))
"Face for playing mark"
:group 'mingus-faces)
(defface mingus-stopped-face
'((default)
(((background light)) (:foreground "#902d2d"))
(((background dark)) (:foreground "#df9797")))
"Face for playing mark"
:group 'mingus-faces)
(defcustom mingus-current-song-props
'(:weight bold)
"Extra properties added to the faces used for the current song"
:group 'mingus-faces
:type '(set
(list :inline t :tag "Weight"
(const :weight)
(choice :tag "Weight"
:help-echo "Font weight."
:value bold ; default
(const :tag "black" ultra-bold)
(const :tag "bold" bold)
(const :tag "book" semi-light)
(const :tag "demibold" semi-bold)
(const :tag "extralight" extra-light)
(const :tag "extrabold" extra-bold)
(const :tag "heavy" extra-bold)
(const :tag "light" light)
(const :tag "medium" normal)
(const :tag "normal" normal)
(const :tag "regular" normal)
(const :tag "semibold" semi-bold)
(const :tag "semilight" semi-light)
(const :tag "ultralight" ultra-light)
(const :tag "ultrabold" ultra-bold)
(const :tag "thin" thin)))
(list :inline t :tag "Background"
(const :background)
(color
:help-echo "Set background color (name or #RRGGBB hex spec)."))))
(defun mingus-exec (string)
(mpd-execute-command mpd-inter-conn string))
;; (@> "currentsongdata")
(defun mingus-get-song-pos ()
"Return position in playlist of current song."
(cl-getf (mingus-data-song mingus-data) 'pos))
(defun mingus-set-song-pos (&optional pos)
(setf (cl-getf (mingus-data-song mingus-data) 'pos)
(or pos (cl-getf (mpd-get-status mpd-inter-conn) 'song))))
;; (@> "playlist versioning")
(defun mingus-set-playlist-version (&optional to)
"Set internal playlist version to TO or to true current version."
(setf (mingus-data-playlist mingus-data)
(or to (cl-getf (mpd-get-status mpd-inter-conn) 'playlist))))
(defun mingus-get-old-playlist-version ()
"Get old internal playlist version"
(mingus-data-playlist mingus-data))
(defun mingus-get-new-playlist-version ()
"Get current playlist version"
(cl-getf (mpd-get-status mpd-inter-conn) 'playlist))
;; configuration
(defun mingus-get-config-option (file option)
(if (file-exists-p file)
(with-temp-buffer
(insert-file-contents file)
(or
(and
(re-search-forward (format "^[[:blank:]]*%s[[:blank:]]+\"\\(.+?\\)\"[[:blank:]]*$" option) nil t)
(match-string 1))
))
nil))
(defgroup mingus nil "Group customization for mingus mpd interface"
:group 'external
:group 'multimedia
:group 'applications)
(defcustom mingus-timer-interval 1
"The interval for executing `mingus-timer-handler', in seconds."
:group 'mingus
:type '(number))
(defcustom mingus-use-caching nil
"Whether or not to use caching.
It appears caching does not help a lot, and easily leads to
out-of-date stuff. That's why it has been turned off for now by
default."
:group 'mingus
:type '(boolean))
(defcustom mingus-mpd-config-file "~/.mpdconf"
"File used by mpd as a configuration file"
:group 'mingus
:type '(string))
(defcustom mingus-mpd-playlist-dir
(expand-file-name
(concat (mingus-get-config-option
mingus-mpd-config-file "playlist_directory")
"/"))
"Directory where MPD puts its playlists"
:group 'mingus
:type '(string))
(defcustom mingus-fold-case t
"Sort case-insensitive?
Mingus sort functions should take this variable into account."
:group 'mingus
:type '(boolean))
(defgroup mingus-mode-line nil
"Customization group to control the modeline for `mingus'"
:group 'mingus)
(defcustom mingus-mode-line-separator " + "
"Separator for fields (artist, song, genre etc.) in Mingus mode-line.
You might want to put something like the following in your .emacs:
(setq mingus-mode-line-separator
(if window-system
\" ● \"
\" + \"))
Or, you might show me how to use a function/string choice in customize ;)"
:group 'mingus
:type '(string))
(make-obsolete-variable 'mingus-playlist-separator
'mingus-mode-line-separator
"2015-11-18")
(defcustom mingus-use-ido-mode-p nil
"Whether to use ido-mode fuzzy completion when searching artists, tracks, etc.
Do not use ido-mode completion when nil.
Do use ido-mode completion when t.
Default: nil."
:group 'mingus
:type '(boolean))
(defcustom mingus-use-mouse-p t
"Use mouse to play/insert/pause etc. songs in Playlist and Browser buffer?"
:group 'mingus
:type '(boolean))
(defcustom mingus-mpd-env-set-p nil
"Whether to set environment variables from emacs.
Do not set when nil.
Do set when t.
Default: nil.
These variables are set when loading mingus or callinge `mingus-set-variables'."
:group 'mingus
:type '(boolean))
(defun mingus-set-host (sym host)
(let ((mpd-interactive-connection-parameters
(list host
(or (and
(boundp 'mingus-mpd-port)
mingus-mpd-port)
(or (and (getenv "MPD_PORT")
(string-to-number (getenv "MPD_PORT")))
6600))
10.0)))
(when (processp (aref mpd-inter-conn 1))
(stop-process (aref mpd-inter-conn 1)))
(mingus-clear-cache)
(setq mpd-inter-conn
(apply 'mpd-conn-new `(,@(mpd-connection-tidy
mpd-interactive-connection-parameters)
nil))))
(set-default sym host)
(save-window-excursion
(when (get-buffer "*Mingus*")
(mingus))
(when (get-buffer "*Mingus Browser*")
(mingus-ls ""))))
(defun mingus-set-port (sym port)
(let ((mpd-interactive-connection-parameters
(list
(or (and
(boundp 'mingus-mpd-host)
mingus-mpd-host)
(or (getenv "MPD_HOST") "localhost"))
port 10.0)))
(when (processp (aref mpd-inter-conn 1))
(stop-process (aref mpd-inter-conn 1)))
(mingus-clear-cache)
(setq mpd-inter-conn
(apply 'mpd-conn-new `(,@(mpd-connection-tidy
mpd-interactive-connection-parameters)
nil))))
(set-default sym port)
(save-window-excursion
(when (get-buffer "*Mingus*")
(mingus))
(when (get-buffer "*Mingus Browser*")
(mingus-ls ""))))
(defcustom mingus-mpd-host (or (getenv "MPD_HOST") "127.0.0.1")
"Setting for environment variable MPD_HOST"
:group 'mingus
:type '(string)
:set 'mingus-set-host)
(defcustom mingus-mpd-port (if (getenv "MPD_PORT")
(string-to-number (getenv "MPD_PORT"))
6600)
"Setting for environment variable MPD_PORT"
:group 'mingus
:type '(integer)
:set 'mingus-set-port)
(defcustom mingus-mpd-root
(expand-file-name
(concat (mingus-get-config-option
mingus-mpd-config-file
"music_directory") "/"))
"Music directory used by MPD.
Note that you can use tramp, as in
\"/ssh:username@host:/var/lib/mpd/music/\"
\(don't forget the trailing slash)"
:group 'mingus
:type '(string))
(defcustom mingus-playlist-directory
nil
"Playlist directory to save playlists to.
This is just in case the MPD implementation does not allow to
save playlists.
Note that you can use tramp, as in
\"/ssh:username@host:/var/lib/mpd/music/\"
\(don't forget the trailing slash)"
:group 'mingus
:type '(string))
(defcustom mingus-seek-amount 10
"Default amount of seconds or percents to seek by when using `mingus-seek'."
:group 'mingus
:type '(integer))
(when mingus-mpd-env-set-p
(setenv "MPD_HOST" mingus-mpd-host)
(setenv "MPD_PORT" (number-to-string mingus-mpd-port)))
(defcustom mingus-mode-always-modeline nil
"Behaviour of modeline: NIL shows current mpd status only in
mingus buffers; Current mpd status is shown in all buffers when
set to t."
:group 'mingus-mode-line
:type '(boolean))
;; (defcustom mingus-mode-line-string "[[%artist% - ]%title%]|[%file%]"
;; "Format-string to display in modeline;
;; `mingus-mode-line-show-elapsed-time' and
;; `mingus-mode-line-show-elapsed-percentage'."
;; :group 'mingus-mode-line
;; :type '(string))
;; FIXME: add customization widget.
(defcustom mingus-mode-line-string-max 40
"Maximum length for (result of) `mingus-mode-line-string'."
:group 'mingus-mode-line
:type '(integer))
(defcustom mingus-mode-line-show-elapsed-time t
"Whether or not to display elapsed time in the mode-line."
:group 'mingus-mode-line
:type '(boolean))
(defcustom mingus-mode-line-show-elapsed-percentage nil
"Whether or not to display elapsed time in the mode-line."
:group 'mingus-mode-line
:type '(boolean))
(defcustom mingus-mode-line-show-status t
"Display status information on volume, repeat and random in mode-line?
See also the variables `mingus-mode-line-show-volume' and
`mingus-mode-line-show-random-and-repeat-status'"
:group 'mingus-mode-line
:type '(boolean))
(defcustom mingus-mode-line-show-volume t
"Display volume information in the mode-line?
Set `mingus-mode-line-show-status' to non-`nil' value for this variable to
have effect"
:group 'mingus-mode-line
:type '(boolean))
(defcustom mingus-mode-line-show-random-and-repeat-status t
"Display random and repeat status in the mode-line?
If random is shown, a letter z is shown, if repeat is on, a letter r is shown
too. Set the variable `mingus-mode-line-show-status' to a non-`nil' value for
this variable to have effect."
:group 'mingus-mode-line
:type '(boolean))
(defcustom mingus-mode-line-show-consume-and-single-status t
"Display consume and single status in the mode-line?
If single is shown, the letter s is shown, if consume is on, the
letter c is shown. Set the variable
`mingus-mode-line-show-status' to a non-`nil' value for this
variable to have effect.
Note: consume and single statuses are available with MPD versions
> 0.16"
:group 'mingus-mode-line
:type '(boolean))
;; (@> "emacs21") some emacs21 compatibility:
(if (not (fboundp 'read-number))
(defun read-number (prompt &optional default)
(let ((n nil))
(when default
(setq prompt
(if (string-match "\\(\\):[ \t]*\\'" prompt)
(replace-match (format " (default %s)" default)
t t prompt 1)
(replace-regexp-in-string "[ \t]*\\'"
(format " (default %s) " default)
prompt t t))))
(while
(progn
(let ((str (read-from-minibuffer
prompt nil nil nil nil
(and default
(number-to-string default)))))
(setq n (cond
((zerop (length str)) default)
((stringp str) (read str)))))
(unless (numberp n)
(message "Please enter a number.")
(sit-for 1)
t))) n)))
;; fixme: use `mpd-inter-conn' directly. Doc this and get rid of these vars.
' (defun mingus-set-variables-interactively ()
"Set environment variables for mpd connection.
Default to `mingus-mpd-host' and `mingus-mpd-port'. Do not use this for
customizing these values; use `mingus-customize' for that"
(interactive)
(setenv "MPD_HOST" (read-string "MPD_HOST: " mingus-mpd-host))
(setenv "MPD_PORT"
(number-to-string (read-number "MPD_PORT: " mingus-mpd-port))))
(defun mingus-set-variables-interactively ()
"Set environment variables for mpd connection.
Default to `mingus-mpd-host' and `mingus-mpd-port'. Do not use this for
customizing these values; use `mingus-customize' for that."
(interactive)
(let ((mpd-interactive-connection-parameters
(list (completing-read
"MPD_HOST: "
(remove nil (list mingus-mpd-host "localhost"))
nil
nil
mingus-mpd-host)
(read-number "MPD_PORT: " mingus-mpd-port)
(read-number "Timeout: " 10.0))))
;; clean up for new connection - bit too low level actually
(when (processp (aref mpd-inter-conn 1))
(stop-process (aref mpd-inter-conn 1)))
(mingus-clear-cache)
;; make new connection and process
(setq mpd-inter-conn
(apply 'mpd-conn-new `(,@(mpd-connection-tidy
mpd-interactive-connection-parameters)
nil)))
;; update views immediately
(when (get-buffer "*Mingus*")
(mingus-playlist))
(when (get-buffer "*Mingus Browser*")
(with-current-buffer
(get-buffer "*Mingus Browser*")
(mingus-ls "")))))
(defun mingus-customize ()
"Call the customize function with mingus as argument."
(interactive)
(customize-group 'mingus))
(defvar mingus-version "Alice's Wonderland or: 0.34")
(defun mingus-version ()
"Echo `mingus-version' in minibuffer."
(interactive)
(message "Version: %s" mingus-version))
(defvar mingus-stream-regexp
"http:[^<>'\"?{}() ]+\.\\([Mm][Pp]3\\|[Oo][Gg][Gg]\\|[fF][lL][aA][cC]\\|[wW][aA][vV]\\|[0-9]{4}\\)")
(defvar mingus-last-query-results nil
"Variable to hold last results of mingus-query")
(defvar mingus-last-query nil)
(make-variable-buffer-local 'mingus-last-query-results)
(defvar mingus-help-text ""
"Text to display in mingus-help")
(setq mingus-help-text
(format
" _
_ __ ___ (_)_ __ __ _ _ _ ___
| '_ ` _ \\| | '_ \\ / _` | | | / __|
| | | | | | | | | | (_| | |_| \\__ \\
|_| |_| |_|_|_| |_|\\__, |\\__,_|___/
|___/
=====================================================
MPD Interface, Nice, GPL'ed, User-friendly and Simple
=====================================================
.........but actually just named after Charles Mingus
Version: %s
REFCARD: (see further down for more elaborate instructions)
Those familiar with dired-mode should find themselves at home;
those familiar with ncmpc too, AMAP that is
MAIN CONTROLS:
mingus-help: 1
mingus-playlist: 2
mingus-browser: 3
mingus-dired-file: 0
Global keys:
p mingus-toggle (toggle play/pause)
> mingus-next
< mingus-prev
q mingus-git-out
s mingus-stop
?,1,H mingus-help
+,right,*, C-<mouse-4> mingus-vol-up
-,left,/, C-<mouse-5> mingus-vol-down
a mingus-insert
~ mingus-add-stream
` mingus-add-podcast
b,S-<mouse-5> mingus-seek-backward
f,S-<mouse-4> mingus-seek-forward
%% mingus-seek-percents
$ mingus-seek-from-start
c mingus-crop
C mingus-clear
L mingus-load-all
z mingus-random
Z mingus-shuffle
r mingus-repeat
. mingus-single
, mingus-consume
C-x C-s mingus-save-playlist
R mingus-remove-playlist
l mingus-load-playlist
o mingus-open-playlist
Q mingus-query
e mingus-query-dir
M-%% mingus-query-regexp
\\ mingus-last-query-results
k forward-line -1
j forward-line
v mingus-show-version
C-x-r-b mingus-bookmark-jump
C-x-r-m mingus-bookmark-set
C-x-r-d mingus-bookmark-delete
@ mingus-update
U mingus-update-thing-at-p
g mingus-redraw-buffer
G mingus-refresh
Playlist keys:
d,C-d,
<delete>, C-w mingus-del
D mingus-del-marked
O mingus-del-other-songs
M mingus-move-all
C-l mingus-goto-current-song
C-k mingus-move-up
C-j mingus-move-down
RET,[mouse-3] mingus-play
SPC,m,[mouse-2] mingus-mark
* %%, y mingus-mark-regexp
C-u * %%, Y mingus-unmark-regexp
*! mingus-unmark-all
* * mingus-vol-up
! run a command on the marked songs
Browser keys:
<home> mingus-browse-top-level
RET, [mouse-1] mingus-down-dir-or-play-song
:,^, [mouse-3] mingus-open-parent
SPC [mouse-2] mingus-insert
P mingus-insert-and-play
S mingus-browse-sort
MORE ELABORATE INSTRUCTIONS:
Requirements:
- cl-macs.el
- dired.el (included in emacs)
- the program symlinks (for dired)
- access to a connection with an mpd server, either locally or on another
server.
- Emacs22
- Issues with emacs21:
although the function line-number-at-pos is replaced with a
custom mingus-line-number-at-pos, and the call to
`while-no-input' is left out when running emacs21, and whereas
for the previously unsupported read-number, I simply replicated
its function definition from the emacs22 subr.el, annoying issues
now have crept up so that you have to call C-g whenever switching
to and fro the mingus-buffers. The rest /seems/ to work somewhat
now.
Getting started:
This help is always available with the command mingus-help, or
the keys ? or 1 from the buffers *Mingus* or *Mingus
Browser*
When mpd is already playing a playlist, the command M-x mingus
will show this playlist; when not so, load a playlist with l,
or make a new one with M-x mingus-browse (default key: 3).
Starting mpd: mingus-start-mpd-daemon
Providing environment variables: mingus-set-variables-interactively
(see also mingus-customize)
SELECTION OF SONGS:
Browsing: command: mingus-browse key: 3
movement and insertion:
SPACEBAR always inserts everything under point or region
P same as SPACEBAR, and plays the inserted song(s) instantly
RET same as SPACEBAR, except on a dir and no mark, then descend into dir.
^ or : go up a directory
Minibuffer browsing:
a insert a file or directory through the use of the minibuffer;
follow instructions there provided
Playlist loading:
l load playlist
Streaming audio:
Mpd supports streaming audio. Aside from the fact that one can
always save a link in a playlist, this provides a way to take
one's own presets with you as a client, as streaming audio does
not require storage of songs on the server. Mingus takes
advantage of this fact by providing the customizable variables
`mingus-stream-alist' and `mingus-podcast-alist': alists of
conses whose key is a pretty name, and whose value is the url of
the respective radio stream or podcast file.
~ load an audio stream, read from minibuffer, with completion
from the customizable variable `mingus-stream-alist';
defaults to link (in w3m and possibly in gnus html mail buffers)
or url under point.
` same as ~, but loads all podcasts found in a link.
Completion provided by the customizable variable
`mingus-podcast-alist'.
Actually ~ will load a podcast too if a podcast is under point.
However, to provide two separate variables for completion,
this option is provided separately.
Making sure an insertion is instantly played:
If any of the insertion commands is prefinged, they will play the insertion
instantly after insertion.
C-u a mingus-insert-and-play
C-u l mingus-load-playlist-and-play
C-u ~ mingus-add-stream-and-play
C-u ` mingus-add-podcast-and-play
Querying:
Q query the mpd database for artist, album, filename, title,
or regexp on filename (type read from minibuffer)
M-%% query for regexp on filename
\\ show last query results again
Results are shown in the *Mingus Browser* buffer,
where all commands for browsing are available
PLAYING CONTROLS:
see the refcard, and documentation of various commands, just try
them out. They should be quite self-evident, but let me know when
they are not. Not every command is (already) mapped to a
key, so M-x mingus- TAB to your delight to find everything.
PLAYLIST EDITING:
Deletion:
on marked songs: see section `Marking'
C-d, d, C-w or DEL
delete single file, or region when there is a region;
NB: this leaves the marking of other songs intact. As such it can
be slow, esp. when the region is large; it is then highly
recommended to mark the songs first, and then issue the command
mingus-del-marked (until I rewrite this function :])
Movement:
of marked songs: see section `Marking'
of single song:
C-k Move song up one position
C-j Move song up down position