(defvar emus-current-volume 100
"The current playback volume.")
+(defvar emus-current-progress ""
+ "String describing the progress through the current track.")
+
+(defvar emus-progress-enabled t
+ "Current state of progress tracking.
+
+To enable or disable progress tracking, using `emus-toggle-progress-tracking'.
+(Changing the value of this variable will not affect anything.)")
;;; 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")
+ (unless emus-progress-enabled
+ (process-send-string proc "silence\n"))
proc))))
(defun emus--send-cmd-raw (cmd &rest args)
(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 (if emus-progress-enabled "" " (progress disabled)"))
+ (set-process-filter
+ (emus-get-process)
+ (lambda (_proc string)
+ (dolist (line (string-split string "\n"))
+ (pcase line
+ ((and "@P 0"
+ (guard emus-continuous-playback)
+ (guard (eq emus-state 'playing)))
+ (emus-play-next))
+ ((and (guard emus-progress-enabled)
+ (rx (: string-start
+ "@I ICY-META: StreamTitle="
+ (let str (+ (not ";")))
+ ";")))
+ (message (concat "Emus: Playing stream " str)))
+ ((and (guard emus-progress-enabled)
+ (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)
(interactive)
(emus-jump -10))
+(defun emus-jump-1m-forward ()
+ "Jump 1 minute forward in current track."
+ (interactive)
+ (emus-jump 60))
+
+(defun emus-jump-1m-backward ()
+ "Jump 1 minute backward in current track."
+ (interactive)
+ (emus-jump -60))
+
(defun emus-display-status ()
"Display the current playback status in the minibuffer."
(interactive)
(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
(emus-track-artist emus-current-track))
""))))
+(defun emus-toggle-progress-tracking ()
+ "Enable/disable progress tracking."
+ (interactive)
+ (setq emus-progress-enabled (not emus-progress-enabled))
+ (if emus-progress-enabled
+ (progn
+ (emus-send-cmd "progress")
+ (setq emus-current-progress ""))
+ (progn
+ (emus-send-cmd "silence")
+ (setq emus-current-progress " (progress diabled)"))))
+
;;; Browser
;;
(emus-jump-10s-backward)
(emus-display-status))
+(defun emus-jump-1m-forward-status ()
+ "Jump 10s forward in current track, then display the emus status in the minibuffer."
+ (interactive)
+ (emus-jump-1m-forward)
+ (emus-display-status))
+
+(defun emus-jump-1m-backward-status ()
+ "Jump 10s backward in current track, then display the emus status in the minibuffer."
+ (interactive)
+ (emus-jump-1m-backward)
+ (emus-display-status))
+
+(defun emus-toggle-progress-status ()
+ "Toggle progress tracking, then display the emus status in the minibuffer."
+ (interactive)
+ (emus-toggle-progress-tracking)
+ (emus-display-status))
+
(defun emus-goto-current-status ()
"Move point to the current track, then display the emus status in the minibuffer."
(interactive)
(define-key map (kbd "P") 'emus-play-prev-album-status)
(define-key map (kbd ",") 'emus-jump-10s-backward-status)
(define-key map (kbd ".") 'emus-jump-10s-forward-status)
+ (define-key map (kbd "<") 'emus-jump-1m-backward-status)
+ (define-key map (kbd ">") 'emus-jump-1m-forward-status)
(define-key map (kbd "c") 'emus-goto-current-status)
+ (define-key map (kbd "!") 'emus-toggle-progress-status)
(when (fboundp 'evil-define-key*)
(evil-define-key* 'motion map
(kbd "SPC") 'emus-playpause-status
(kbd "P") 'emus-play-prev-album-status
(kbd ",") 'emus-jump-10s-backward-status
(kbd ".") 'emus-jump-10s-forward-status
- (kbd "c") 'emus-goto-current-status))
+ (kbd "<") 'emus-jump-1m-backward-status
+ (kbd ">") 'emus-jump-1m-forward-status
+ (kbd "c") 'emus-goto-current-status
+ (kbd "!") 'emus-toggle-progress-status))
map)
"Keymap for emus browser.")