-
Notifications
You must be signed in to change notification settings - Fork 12
/
simple-mpc.el
166 lines (141 loc) · 5.65 KB
/
simple-mpc.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
;;; simple-mpc.el --- provides a simple interface to mpc
;; Copyright (C) 2015,2016 Joren Van Onder <[email protected]>
;; Copyright (C) 2016 Andriy Kmit' <[email protected]>
;; Copyright (C) 2020 Sean Farley <[email protected]>
;; Copyright (C) 2022 Joseph Turner <[email protected]>
;; Author: Joren Van Onder <[email protected]>
;; Maintainer: Joren Van Onder <[email protected]>
;; URL: https://github.com/jorenvo/simple-mpc
;; Keywords: multimedia, mpd, mpc
;; Version: 1.0
;; Package-Requires: ((s "1.10.0"))
;; 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 3 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, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; A GNU Emacs major mode that acts as a front end to mpc. See
;; README.org for more info.
;;; Code:
(require 's)
(require 'simple-mpc-mode)
(require 'simple-mpc-current-playlist)
(require 'simple-mpc-query)
(require 'simple-mpc-vars)
(defun simple-mpc-quit ()
"Quits simple-mpc."
(interactive)
(mapc (lambda (buf)
(if (buffer-live-p (get-buffer buf))
(kill-buffer buf)))
(list simple-mpc-main-buffer-name
simple-mpc-current-playlist-buffer-name
simple-mpc-query-buffer-name)))
(defun simple-mpc-toggle ()
"Toggle the playing / pause state."
(interactive)
(simple-mpc-call-mpc nil "toggle"))
(defun simple-mpc-next ()
"Play the next song."
(interactive)
(simple-mpc-call-mpc nil "next")
(simple-mpc-maybe-refresh-playlist t))
(defun simple-mpc-prev ()
"Play the previous song."
(interactive)
(simple-mpc-call-mpc nil "prev")
(simple-mpc-maybe-refresh-playlist t))
(defun simple-mpc-seek-forward ()
"Does a relative seek forward by `simple-mpc-seek-time-in-s' seconds."
(interactive)
(simple-mpc-seek-internal simple-mpc-seek-time-in-s))
(defun simple-mpc-seek-backward ()
"Does a relative seek backward by -`simple-mpc-seek-time-in-s' seconds."
(interactive)
(simple-mpc-seek-internal (- simple-mpc-seek-time-in-s)))
(defun simple-mpc-seek-internal (time-in-seconds)
"Seek current song by TIME-IN-SECONDS."
(let ((time-string (simple-mpc-convert-number-to-relative-string time-in-seconds)))
(simple-mpc-call-mpc nil (list "seek" time-string))))
(defun simple-mpc-increase-volume ()
"Increases volume by `simple-mpc-volume-step-size'."
(interactive)
(simple-mpc-modify-volume-internal simple-mpc-volume-step-size))
(defun simple-mpc-decrease-volume ()
"Decreases volume by `simple-mpc-volume-step-size'."
(interactive)
(simple-mpc-modify-volume-internal (- simple-mpc-volume-step-size)))
(defun simple-mpc-modify-volume-internal (volume-change)
"Helper function to adjust volume by VOLUME-CHANGE."
(let ((volume-change-string (simple-mpc-convert-number-to-relative-string volume-change)))
(simple-mpc-call-mpc nil (list "volume" volume-change-string)))
(simple-mpc-message-current-volume))
(defun simple-mpc-clear-current-playlist ()
"Clear the current playlist."
(interactive)
(simple-mpc-call-mpc nil "clear")
(message "%s" "Cleared current playlist.")
(simple-mpc-maybe-refresh-playlist))
(defun simple-mpc-toggle-repeat ()
"Toggle repeat mode."
(interactive)
(simple-mpc-call-mpc nil "repeat")
(message "%s" "Toggled repeat mode."))
(defun simple-mpc-shuffle-current-playlist ()
"Shuffle the current playlist."
(interactive)
(simple-mpc-call-mpc nil "shuffle")
(message "%s" "Shuffled current playlist.")
(simple-mpc-maybe-refresh-playlist))
(defun simple-mpc-load-playlist (playlist-name)
"Load a MPD PLAYLIST-NAME.
Provides completion for playlists through the lsplaylists
command."
(interactive
(list
(completing-read "Playlist: " (simple-mpc-call-mpc-strings "lsplaylists"))))
(message "%s %s" "Loading playlist" playlist-name)
(simple-mpc-call-mpc nil (list "load" playlist-name))
(simple-mpc-maybe-refresh-playlist))
;;;###autoload
(defun simple-mpc (&optional ignore-auto noconfirm)
"Start simple-mpc.
IGNORE-AUTO and NOCONFIRM are passed by `revert-buffer'."
(interactive)
(let ((buf (get-buffer-create simple-mpc-main-buffer-name)))
(with-current-buffer buf
(read-only-mode -1)
(erase-buffer)
(insert (propertize "* simple-mpc *\n\n"
'face 'simple-mpc-main-name)
(propertize " * controls\n" 'face 'simple-mpc-main-headers)
" * [t]oggle\n"
" * [n]ext track\n"
" * [p]revious track\n"
" * seek [f]orward\n"
" * seek [b]ackward\n"
" * increase [V]olume\n"
" * decrease [v]olume\n"
" * toggle [r]epeat mode\n"
(propertize "\n * playlist\n" 'face 'simple-mpc-main-headers)
" * view [c]urrent playlist\n"
" * [C]lear current playlist\n"
" * [S]huffle playlist\n"
" * [l]oad playlist\n"
" * [s]earch database\n"
(propertize "\n * misc\n" 'face 'simple-mpc-main-headers)
" * [q]uit")
(simple-mpc-mode) ; start major mode
(switch-to-buffer buf))))
(provide 'simple-mpc)
;;; simple-mpc.el ends here