to show the name of the currently selected/playing song as well as the
current volume.
+Enabling/disabling Progress Tracking
+------------------------------------
+
+By default, emus uses the mpg123 output to keep track of the progress
+through a track, and to listen to Icecast stream updates. However,
+this can cause glitches in the audio on some systems if Emacs (running
+in GUI mode) looses focus for extended periods. As a work-around it is
+possible to toggle progress tracking using `M-x emus-progress-tracking`
+which, inside the browser, is bound to `!`.
+
Example Hydra Configuration
---------------------------
("+" emus-volume-up-status)
("=" emus-volume-up-status)
("o" emus-stop-status)
+ ("!" emus-toggle-progress-status)
("b" emus-browse :color blue))
(bind-key* (kbd "s-m") 'hydra-ecmus/body)
(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)
(emus-send-cmd "l" (emus-track-file track))
(setq emus-state 'playing)
(setq emus-current-track track)
- (setq emus-current-progress "")
+ (setq emus-current-progress (if emus-progress-enabled "" " (progress disabled)"))
(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))))))))
+ (dolist (line (string-split string "\n"))
+ (pcase line
+ ((and "@P 0"
+ (guard emus-continuous-playback)
+ (guard (eq emus-state 'playing)))
+ (emus-play-next))
+ ((rx (: string-start
+ "@I ICY-META: StreamTitle="
+ (let str (+ (not ";")))
+ ";"))
+ (message (concat "Emus: Playing stream " str)))
+ ((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)
(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-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 "<") '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 ".") 'emus-jump-10s-forward-status
(kbd "<") 'emus-jump-1m-backward-status
(kbd ">") 'emus-jump-1m-forward-status
- (kbd "c") 'emus-goto-current-status))
+ (kbd "c") 'emus-goto-current-status
+ (kbd "!") 'emus-toggle-progress-status))
map)
"Keymap for emus browser.")