(defvar emus-current-volume 100
"The current playback volume.")
+(defvar emus-current-progress ""
+ "String describing the progress through the current track.")
+
;;; mpg123 process
;;
(make-process :name "emus-process"
:command `(,emus-mpg123-program "-R"))))
(set-process-query-on-exit-flag proc nil)
- (process-send-string proc "silence\n")
+ ;; (process-send-string proc "silence\n")
proc))))
(defun emus--send-cmd-raw (cmd &rest args)
(unless emus--proc-in-use
(apply #'emus--send-cmd-raw cmd args)))
+(defun emus-kill-process ()
+ "Kill any existing mpg123 process."
+ (let ((emus-process (get-process "emus-process")))
+ (if emus-process
+ (kill-process emus-process))))
+
+(defun emus-restart ()
+ "Restart emus, regardless of current state."
+ (interactive)
+ (emus-kill-process)
+ (setq emus-state 'stopped
+ emus--proc-in-use nil
+ emus-tracks nil))
;;; Library
;;
(setq emus--proc-in-use t)
(emus--suspend-cp)
(setq emus-state 'stopped)
- (setq emus-tracks (emus--make-tracks-from-playlist-files (emus-get-playlist-files)))
+ (setq emus-tracks nil)
(let ((proc (emus-get-process))
(tagstr "")
(filenames (emus-get-audio-files)))
(set-process-filter proc nil)
(setq emus-tracks (reverse emus-tracks))
(emus--sort-tracks)
+ (emus--add-tracks-from-playlist-files)
(unless emus-current-track
(setq emus-current-track (car emus-tracks)))
(funcall then)
(found-title (setq title found-title)))))
(emus-make-track artist album title filename)))
-(defun emus--make-tracks-from-playlist-files (filenames)
+(defun emus--add-tracks-from-playlist-files ()
(let ((tracks nil))
- (dolist (filename filenames)
+ (dolist (filename (emus-get-playlist-files))
(let ((artist "Playlists")
(album (file-name-base filename))
(title nil)
(setq tracks (cons (emus-make-track artist album (or title filename) filename)
tracks))
(setq title nil))))))
- tracks))
+ (setq emus-tracks (append emus-tracks (reverse tracks)))))
(defun emus--sort-tracks ()
"Sort the library tracks according to artist and album.
(let ((album1 (emus-track-album r1))
(album2 (emus-track-album r2)))
(string< album1 album2))
- (if (equal artist1 "Playlists")
- t
- (if (equal artist2 "Playlists")
- nil
- (string< artist1 artist2)))))))))
+ (string< artist1 artist2)))))))
(defmacro emus--with-library (&rest body)
"Evaluate BODY with the library initialized."
(defun emus--resume-cp ()
"Resume continuous playback."
- (setq emus-continuous-playback t)
- (set-process-filter (emus-get-process)
- (lambda (_proc string)
- (and emus-continuous-playback
- (eq emus-state 'playing)
- (string-suffix-p "@P 0\n" string)
- (emus-play-next)))))
+ (setq emus-continuous-playback t))
+
+(defun emus--timestamp (seconds-total)
+ "Produce a timestamp string representation of SECONDS-TOTAL."
+ (let* ((seconds (truncate (mod seconds-total 60)))
+ (minutes (truncate (/ seconds-total 60))))
+ (format "%02d:%02d" minutes seconds)))
(defun emus-play-track (track)
"Set TRACK as current and start playing."
(emus-send-cmd "l" (emus-track-file track))
(setq emus-state 'playing)
(setq emus-current-track track)
+ (setq emus-current-progress "")
+ (set-process-filter
+ (emus-get-process)
+ (lambda (_proc string)
+ (pcase string
+ ((and "@P 0\n"
+ (guard emus-continuous-playback)
+ (guard (eq emus-state 'playing)))
+ (emus-play-next))
+ ((rx (: string-start
+ "@F "
+ (+ digit)
+ " "
+ (+ digit)
+ " "
+ (let left-str (+ (not " ")))
+ " "
+ (let right-str (+ any))))
+ (let* ((left (string-to-number left-str))
+ (right (string-to-number right-str))
+ (total (+ left right)))
+ (setq emus-current-progress
+ (format " %s/%s"
+ (emus--timestamp left)
+ (emus--timestamp total))))))))
(emus--update-track old-track)
(emus--update-track track)
(emus--resume-cp)
(concat "Emus: Volume %d%%"
(pcase emus-state
('stopped " [Stopped]")
- ('paused " [Paused]")
- ('playing " [Playing]")
+ ('paused (format " [Paused%s]" emus-current-progress))
+ ('playing (format " [Playing%s]" emus-current-progress))
(_ ""))
" %s")
emus-current-volume
(if emus-current-track
- (format "- %.30s (%.20s)"
+ (format "- %.30s (%.20s, %.20s)"
(emus-track-title emus-current-track)
+ (emus-track-album emus-current-track)
(emus-track-artist emus-current-track))
""))))
map)
"Keymap for emus browser.")
+(defun emus-restart ()
+ "Restart emus."
+ (interactive)
+ (emus-kill-process))
+
(define-derived-mode emus-browser-mode special-mode "emus-browser"
"Major mode for EMUS music player file browser."
(setq-local buffer-invisibility-spec nil))