From: Tim Vaughan Date: Sun, 8 Dec 2019 20:46:46 +0000 (+0100) Subject: Added album skipping. X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=commitdiff_plain;h=d0b58f6dbe917c240dd64a0dc7191b831951788a;p=emus.git Added album skipping. --- diff --git a/emus.el b/emus.el index 3349113..04a8e73 100644 --- a/emus.el +++ b/emus.el @@ -293,24 +293,55 @@ (interactive) (emus-volume-increase-by -10)) -(defun emus-play-nearby (offset) - (let ((idx (seq-position emus-records emus-current-record))) - (if idx - (let ((next-record (elt emus-records (+ idx offset)))) - (if next-record - (if (eq emus-state 'playing) - (emus-play-record next-record) - (emus-select-record next-record)) - (error "Track does not exist"))) - (error "No track is currently selected")))) +(defun emus--play-adjacent-track (&optional prev) + (emus--with-library + (let ((idx (seq-position emus-records emus-current-record)) + (offset (if prev -1 +1))) + (if idx + (let ((next-record (elt emus-records (+ idx offset)))) + (if next-record + (if (eq emus-state 'playing) + (emus-play-record next-record) + (emus-select-record next-record)) + (error "Track does not exist"))) + (error "No track selected"))))) + +(defun emus--play-adjacent-album (&optional prev) + (emus--with-library + (let ((idx (seq-position emus-records emus-current-record))) + (if idx + (let* ((search-list (if prev + (reverse (seq-subseq emus-records 0 idx)) + (seq-subseq emus-records (+ idx 1)))) + (current-album (emus-record-album emus-current-record)) + (next-record (seq-some (lambda (r) + (if (string= (emus-record-album r) + current-album) + nil + r)) + search-list))) + (if next-record + (if (eq emus-state 'playing) + (emus-play-record next-record) + (emus-select-record next-record)) + (error "Track does not exist"))) + (error "No track selected"))))) (defun emus-play-next () (interactive) - (emus-play-nearby 1)) + (emus--play-adjacent-track)) (defun emus-play-prev () (interactive) - (emus-play-nearby -1)) + (emus--play-adjacent-track t)) + +(defun emus-play-next-album () + (interactive) + (emus--play-adjacent-album)) + +(defun emus-play-prev-album () + (interactive) + (emus--play-adjacent-album t)) (defun emus-display-status () (interactive) @@ -440,6 +471,8 @@ (defun emus-refresh-status () (interactive) (emus-refresh) (emus-display-status)) (defun emus-play-next-status () (interactive) (emus-play-next) (emus-display-status)) (defun emus-play-prev-status () (interactive) (emus-play-prev) (emus-display-status)) +(defun emus-play-next-album-status () (interactive) (emus-play-next-album) (emus-display-status)) +(defun emus-play-prev-album-status () (interactive) (emus-play-prev-album) (emus-display-status)) (defun emus-centre-current-status () (interactive) (emus-centre-current) (emus-display-status)) (defvar emus-browser-mode-map @@ -452,6 +485,8 @@ (define-key map (kbd "R") 'emus-refresh-status) (define-key map (kbd "n") 'emus-play-next-status) (define-key map (kbd "p") 'emus-play-prev-status) + (define-key map (kbd "N") 'emus-play-next-album-status) + (define-key map (kbd "P") 'emus-play-prev-album-status) (define-key map (kbd "c") 'emus-centre-current-status) (when (fboundp 'evil-define-key*) (evil-define-key* 'motion map @@ -463,6 +498,8 @@ (kbd "R") 'emus-refresh-status (kbd "n") 'emus-play-next-status (kbd "p") 'emus-play-prev-status + (kbd "N") 'emus-play-next-album-status + (kbd "P") 'emus-play-prev-album-status (kbd "c") 'emus-centre-current-status)) map) "Keymap for emus.")