From: plugd Date: Fri, 20 Jan 2023 09:00:10 +0000 (+0100) Subject: Made progress tracking optional. X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?p=emus.git;a=commitdiff_plain;h=b2d3157b868f33f78e09c1f336d44c8c77fd1ebf Made progress tracking optional. --- diff --git a/README b/README index e91fafc..8886e1e 100644 --- a/README +++ b/README @@ -81,6 +81,16 @@ Outside of the browser buffer, `M-x emus-display-status` can be used 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 --------------------------- @@ -111,6 +121,7 @@ The following example is from my own init.el 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) diff --git a/emus.el b/emus.el index e8b960d..7b65d87 100644 --- a/emus.el +++ b/emus.el @@ -103,6 +103,11 @@ Used to prevent commands from interfering with library construction.") (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 ;; @@ -122,7 +127,8 @@ Used to prevent commands from interfering with library construction.") (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) @@ -323,31 +329,38 @@ by the filesystem." (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) @@ -511,6 +524,18 @@ If PREV is non-nil, plays the last track of the previous album." (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 ;; @@ -715,6 +740,12 @@ Used to update browser display when `emus-current-track' and/or `emus-state' cha (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) @@ -747,6 +778,7 @@ Used to update browser display when `emus-current-track' and/or `emus-state' cha (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 @@ -763,7 +795,8 @@ Used to update browser display when `emus-current-track' and/or `emus-state' cha (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.")