fordon_greeman / voidfiles

Branch: main
Switch branches/tags
main
theidioticdev add emacs 2079ec5 22h ago
266 lines · 8.6 KB Raw Blame History
1 ;;; emms-setup.el --- Setup script for EMMS -*- lexical-binding: t; -*-
2
3 ;; Copyright (C) 2005-2022, 2025 Free Software Foundation, Inc.
4
5 ;; Author: Yoni Rabkin <yrk@gnu.org>
6 ;; Keywords: emms setup multimedia
7
8 ;; This file is part of EMMS.
9
10 ;; EMMS 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, or (at your option)
13 ;; any later version.
14
15 ;; EMMS 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 EMMS; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 ;; Boston, MA 02110-1301, USA.
24
25 ;;; Commentary:
26
27 ;; This file provides the `emms-setup' feature. With `emms-setup' we
28 ;; can setup Emms with different features enabled. The use of this
29 ;; feature is documented in the Emms manual which is distributed with
30 ;; Emms.
31 ;;
32 ;; The use this feature we can invoke (for example):
33 ;;
34 ;; (require 'emms-setup)
35 ;; (emms-all)
36 ;;
37 ;; The first command loads the feature into Emacs and the second
38 ;; chooses the `emms-all' level.
39
40 ;;; Code:
41
42 (require 'emms)
43
44 (defgroup emms-setup nil
45 "*The Emacs Multimedia System setup utility."
46 :prefix "emms-setup"
47 :group 'multimedia)
48
49 (defcustom emms-setup-default-player-list
50 '(emms-player-mpg321
51 emms-player-ogg123
52 emms-player-mplayer-playlist
53 emms-player-mplayer
54 emms-player-mpv
55 emms-player-vlc
56 emms-player-vlc-playlist)
57 "Default list of players for emms-setup."
58 :type '(repeat symbol))
59
60 (defvar emms-setup-discover-player-alist
61 '((emms-player-mpg321 . "mpg123")
62 (emms-player-ogg123 . "ogg123")
63 (emms-player-mplayer . "mplayer")
64 (emms-player-mpv . "mpv")
65 (emms-player-vlc . "vlc"))
66 "Association list of players and their binaries.")
67
68 (defvar emms-setup-discover-info-alist
69 '((emms-info-exiftool . "exiftool")
70 (emms-info-metaflac . "metaflac")
71 (emms-info-mp3info . "mp3info")
72 (emms-info-ogginfo . "ogginfo")
73 (emms-info-opusinfo . "opusinfo"))
74 "Association list of info-functions and their binaries.")
75
76 ;;;###autoload
77 (defun emms-minimalistic ()
78 "An Emms setup script.
79 Invisible playlists and all the basics for playing media."
80 (require 'emms-source-file)
81 (require 'emms-source-playlist)
82 (require 'emms-player-simple)
83 (require 'emms-player-mplayer)
84 (require 'emms-player-mpv)
85 (require 'emms-player-vlc))
86
87 ;;;###autoload
88 (defun emms-all ()
89 "An Emms setup script.
90 Everything included in the `emms-minimalistic' setup and adds all
91 the stable features which come with the Emms distribution."
92 ;; include
93 (emms-minimalistic)
94 ;; define
95 (eval-and-compile
96 (require 'emms-playlist-mode)
97 (require 'emms-info)
98 (require 'emms-info-mp3info)
99 (require 'emms-info-ogginfo)
100 (require 'emms-info-opusinfo)
101 (require 'emms-info-metaflac)
102 (require 'emms-info-tinytag)
103 (require 'emms-info-exiftool)
104 (require 'emms-info-native)
105 (require 'emms-cache)
106 (require 'emms-mode-line)
107 (require 'emms-mark)
108 (require 'emms-tag-editor)
109 (require 'emms-tag-tracktag)
110 (require 'emms-show-all)
111 (require 'emms-streams)
112 (require 'emms-lyrics)
113 (require 'emms-playing-time)
114 (require 'emms-player-mpd)
115 (require 'emms-player-xine)
116 (require 'emms-playlist-sort)
117 (require 'emms-browser)
118 (require 'emms-mode-line-icon)
119 (require 'emms-cue)
120 (require 'emms-bookmarks)
121 (require 'emms-last-played)
122 (require 'emms-metaplaylist-mode)
123 (require 'emms-stream-info)
124 (require 'emms-score)
125 (require 'emms-history)
126 (require 'emms-i18n)
127 (require 'emms-volume)
128 (require 'emms-playlist-limit)
129 (require 'emms-librefm-scrobbler)
130 (require 'emms-librefm-stream)
131 (require 'emms-mpris)
132 (require 'emms-idapi-musicbrainz)
133 (require 'emms-idapi-browser))
134 ;; setup
135 (setq emms-playlist-default-major-mode #'emms-playlist-mode)
136 (add-to-list 'emms-track-initialize-functions #'emms-info-initialize-track)
137 (setq emms-info-functions '(emms-info-native emms-info-cueinfo))
138 (setq emms-track-description-function #'emms-info-track-description)
139 (when (fboundp 'emms-cache) ; work around compiler warning
140 (emms-cache 1))
141 (emms-mode-line-mode 1)
142 (emms-mode-line-blank)
143 (emms-lyrics 1)
144 (emms-playing-time-mode 1)
145 (add-hook 'emms-player-started-hook #'emms-last-played-update-current)
146 (emms-score 1))
147
148
149 ;;;###autoload
150 (defun emms-default-players ()
151 "Set `emms-player-list' to `emms-setup-default-player-list'."
152 (setq emms-player-list
153 emms-setup-default-player-list))
154
155
156
157 ;; These are kept around in order not to break anyone's existing
158 ;; setup.
159 ;;;###autoload
160 (defun emms-devel ()
161 (emms-all))
162 (make-obsolete 'emms-devel 'emms-all "4.1")
163
164 ;;;###autoload
165 (defun emms-standard ()
166 (emms-all))
167 (make-obsolete 'emms-standard 'emms-all "4.1")
168
169
170 ;;; ------------------------------------------------------------------
171 ;;; Player discovery
172 ;;; ------------------------------------------------------------------
173 (defun emms-setup-discover-binary (bin-str)
174 "Find if BIN-STR can be executed in the current environment."
175 (when (not (eq system-type 'gnu/linux))
176 (error "Player discovery only supported on GNU/Linux."))
177 (let ((result (call-process "which" nil nil nil bin-str)))
178 (cond ((eq 0 result) t)
179 ((eq 1 result) nil)
180 ((eq 2 result) (error "invalid arguments to `which'.")))))
181
182 (defun emms-setup-discover-player-has-binary-p (player)
183 "Find if PLAYER has an excecutable in the current environment."
184 (let ((bin-str (alist-get player emms-setup-discover-player-alist)))
185 (if bin-str
186 (emms-setup-discover-binary bin-str)
187 nil)))
188
189 (defun emms-setup-discover-info-has-binary-p (info-function)
190 "Find if INFO-FUNCTION has an excecutable in the current environment."
191 (let ((bin-str (alist-get info-function emms-setup-discover-info-alist)))
192 (if bin-str
193 (emms-setup-discover-binary bin-str)
194 nil)))
195
196 (defun emms-setup-discover-players (arg)
197 "Interactively add players to `emms-player-list'.
198
199 With a prefix, also insert the configuration at point."
200 (interactive "P")
201 (when (and emms-player-list
202 (y-or-n-p (format "`emms-player-list' is already set to %s, do you want to empty it
203 first?"
204 emms-player-list)))
205 (setq emms-player-list nil))
206 (let ((players (copy-tree emms-setup-default-player-list)))
207 (while players
208 (let ((player (car players)))
209 (when (emms-setup-discover-player-has-binary-p player)
210 (when (y-or-n-p
211 (format "Player \"%s\" is installed on your system, add it to the Emms player list?"
212 player))
213 (add-to-list 'emms-player-list player))))
214 (setq players (cdr players))))
215 (when arg
216 (insert
217 (format "(setq emms-player-list '%s)" emms-player-list)))
218 (message "emms-player-list is now set to: %s" emms-player-list))
219
220 (defun emms-setup-discover-info (arg)
221 "Interactively add info-functions to `emms-info-functions'.
222
223 With prefix, also insert the configuration at point."
224 (interactive "P")
225 (let (native-p)
226 (when (and emms-info-functions
227 (y-or-n-p (format "`emms-info-functions' is already set to %s, do you want to empty it
228 first?"
229 emms-info-functions)))
230 (setq emms-info-functions nil))
231 (when (y-or-n-p
232 (format "Install the built-in `emms-info-native' info function (recommended)?"))
233 (setq native-p t))
234 (mapc
235 #'(lambda (info-function)
236 (when (and (emms-setup-discover-info-has-binary-p info-function)
237 (y-or-n-p
238 (format "Meta-info reader \"%s\" is installed on your system, add it to the info-function list?"
239 (alist-get info-function emms-setup-discover-info-alist))))
240 (add-to-list 'emms-info-functions info-function)))
241 (mapcar
242 #'(lambda (e)
243 (car e))
244 emms-setup-discover-info-alist))
245 (when native-p
246 (setq emms-info-functions
247 (cons 'emms-info-native emms-info-functions))))
248 (when arg
249 (insert
250 (format "(setq emms-info-functions '%s)" emms-info-functions)))
251 (message "emms-info-functions is now set to: %s"
252 emms-info-functions))
253
254 (defun emms-setup-discover ()
255 "Discover and output players and info functions.
256
257 Scan for media players and meta-data readers on the user's
258 machine and print out a setup."
259 (interactive)
260 (emms-setup-discover-players t)
261 (newline)
262 (emms-setup-discover-info t))
263
264
265 (provide 'emms-setup)
266 ;;; emms-setup.el ends here