From: Tim Vaughan Date: Mon, 9 Dec 2019 19:43:55 +0000 (+0100) Subject: Replaced "record" with "track". X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=commitdiff_plain;h=fb0e676fc470481bb45da18eebf27a9a63fe3a25;p=emus.git Replaced "record" with "track". Also hacky fix for race condition in emus-refresh-status. --- diff --git a/emus.el b/emus.el index 898b403..cfa3d65 100644 --- a/emus.el +++ b/emus.el @@ -3,7 +3,7 @@ ;; Copyright (C) 2019 Tim Vaughan ;; Author: Tim Vaughan -;; Created: 12 December 2019 +;; Created: 8 December 2019 ;; Version: 1.0 ;; Keywords: multimedia ;; Homepage: http://thelambdalab.xy/emus @@ -90,29 +90,29 @@ "Get all mp3 files in main emus directory." (directory-files-recursively emus-directory ".*\\.mp3")) -(defvar emus-records nil +(defvar emus-tracks nil "Emus audio library.") -(defun emus-make-record (artist album title filename &optional pos) +(defun emus-make-track (artist album title filename &optional pos) (vector artist album title filename pos)) -(defun emus-record-artist (record) - (elt record 0)) +(defun emus-track-artist (track) + (elt track 0)) -(defun emus-record-album (record) - (elt record 1)) +(defun emus-track-album (track) + (elt track 1)) -(defun emus-record-title (record) - (elt record 2)) +(defun emus-track-title (track) + (elt track 2)) -(defun emus-record-file (record) - (elt record 3)) +(defun emus-track-file (track) + (elt track 3)) -(defun emus-record-browser-pos (record) - (elt record 4)) +(defun emus-track-browser-pos (track) + (elt track 4)) -(defun emus-set-record-browser-pos (record pos) - (aset record 4 pos)) +(defun emus-set-track-browser-pos (track pos) + (aset track 4 pos)) (defun emus--load-library (then) (emus--suspend-cp) @@ -120,28 +120,28 @@ (let ((proc (emus-get-process)) (tagstr "") (filenames (emus-get-audio-files))) - (setq emus-records nil) + (setq emus-tracks nil) (set-process-filter proc (lambda (proc string) (setq tagstr (concat tagstr string)) (when (string-suffix-p "@P 1\n" string) - (add-to-list 'emus-records - (emus--make-record-from-tagstr (car filenames) - tagstr)) + (add-to-list 'emus-tracks + (emus--make-track-from-tagstr (car filenames + tagstr))) (setq tagstr "") (setq filenames (cdr filenames)) (if filenames (emus-send-cmd "lp" (car filenames)) (set-process-filter proc nil) - (setq emus-records (reverse emus-records)) - (emus--sort-records) - (unless emus-current-record - (setq emus-current-record (car emus-records))) + (setq emus-tracks (reverse emus-tracks)) + (emus--sort-tracks) + (unless emus-current-track + (setq emus-current-track (car emus-tracks))) (funcall then) - ;; (emus-render-records) + ;; (emus-render-tracks) (emus--resume-cp))))) (emus-send-cmd "lp" (car filenames)))) -(defun emus--make-record-from-tagstr (filename tagstr) +(defun emus--make-track-from-tagstr (filename tagstr) (let ((artist "") (album "") (title "")) @@ -153,21 +153,21 @@ (found-artist (setq artist found-artist)) (found-album (setq album found-album)) (found-title (setq title found-title))))) - (emus-make-record artist album title filename nil))) + (emus-make-track artist album title filename nil))) -(defun emus--sort-records () - (sort emus-records +(defun emus--sort-tracks () + (sort emus-tracks (lambda (r1 r2) - (let ((artist1 (emus-record-artist r1)) - (artist2 (emus-record-artist r2))) + (let ((artist1 (emus-track-artist r1)) + (artist2 (emus-track-artist r2))) (if (string= artist1 artist2) - (let ((album1 (emus-record-album r1)) - (album2 (emus-record-album r2))) + (let ((album1 (emus-track-album r1)) + (album2 (emus-track-album r2))) (string< album1 album2)) (string< artist1 artist2)))))) (defmacro emus--with-library (&rest args) - `(if emus-records + `(if emus-tracks (progn ,@args) (emus--load-library (lambda () ,@args)))) @@ -216,7 +216,7 @@ ;;; Playback ;; -(defvar emus-current-record nil) +(defvar emus-current-track nil) (defvar emus-state 'stopped) (defvar emus-continuous-playback t) @@ -232,48 +232,48 @@ (string-suffix-p "@P 0\n" string) (emus-play-next))))) -(defun emus-play-record (record) - "Set RECORD as current and start playing." +(defun emus-play-track (track) + "Set TRACK as current and start playing." (emus--with-library - (let ((old-record emus-current-record)) - (emus-send-cmd "l" (emus-record-file record)) + (let ((old-track emus-current-track)) + (emus-send-cmd "l" (emus-track-file track)) (setq emus-state 'playing) - (setq emus-current-record record) - (emus--update-record old-record) - (emus--update-record record) + (setq emus-current-track track) + (emus--update-track old-track) + (emus--update-track track) (emus--resume-cp)))) -(defun emus-select-record (record) - "Set RECORD as current, but do not start playing." +(defun emus-select-track (track) + "Set TRACK as current, but do not start playing." (emus--with-library - (let ((old-record emus-current-record)) + (let ((old-track emus-current-track)) (setq emus-state 'stopped) - (setq emus-current-record record) - (emus--update-record old-record) - (emus--update-record record) + (setq emus-current-track track) + (emus--update-track old-track) + (emus--update-track track) (emus-send-cmd "o") (emus--resume-cp)))) (defun emus-stop () - "Stop playback of the current record." + "Stop playback of the current track." (interactive) (emus--with-library (setq emus-state 'stopped) - (emus--update-record emus-current-record) + (emus--update-track emus-current-track) (emus-send-cmd "s"))) (defun emus-playpause () (interactive) (emus--with-library - (when emus-current-record + (when emus-current-track (if (eq emus-state 'stopped) - (emus-play-record emus-current-record) + (emus-play-track emus-current-track) (emus-send-cmd "p") (pcase emus-state ((or 'paused 'stopped) (setq emus-state 'playing)) ('playing (setq emus-state 'paused))) (unless (eq emus-state 'paused))) - (emus--update-record emus-current-record)))) + (emus--update-track emus-current-track)))) (defvar emus-current-volume 100) @@ -295,35 +295,35 @@ (defun emus--play-adjacent-track (&optional prev) (emus--with-library - (let ((idx (seq-position emus-records emus-current-record)) + (let ((idx (seq-position emus-tracks emus-current-track)) (offset (if prev -1 +1))) (if idx - (let ((next-record (elt emus-records (+ idx offset)))) - (if next-record + (let ((next-track (elt emus-tracks (+ idx offset)))) + (if next-track (if (eq emus-state 'playing) - (emus-play-record next-record) - (emus-select-record next-record)) + (emus-play-track next-track) + (emus-select-track next-track)) (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))) + (let ((idx (seq-position emus-tracks emus-current-track))) (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) + (reverse (seq-subseq emus-tracks 0 idx)) + (seq-subseq emus-tracks (+ idx 1)))) + (current-album (emus-track-album emus-current-track)) + (next-track (seq-some (lambda (r) + (if (string= (emus-track-album r) current-album) nil - r)) - search-list))) - (if next-record + r) + search-list)))) + (if next-track (if (eq emus-state 'playing) - (emus-play-record next-record) - (emus-select-record next-record)) + (emus-play-track next-track) + (emus-select-track next-track)) (error "Track does not exist"))) (error "No track selected"))))) @@ -368,10 +368,10 @@ ('paused " [Paused]") ('playing " [Playing]") (_ "")) - (if emus-current-record + (if emus-current-track (format " - %.30s (%.20s)" - (emus-record-title emus-current-record) - (emus-record-artist emus-current-record)) + (emus-track-title emus-current-track) + (emus-track-artist emus-current-track)) "")) emus-current-volume))) @@ -379,30 +379,30 @@ ;;; Browser ;; -(defun emus--insert-record (record &optional prev-record first) - (let* ((artist (emus-record-artist record)) - (album (emus-record-album record)) - (title (emus-record-title record)) +(defun emus--insert-track (track &optional prev-track first) + (let* ((artist (emus-track-artist track)) + (album (emus-track-album track)) + (title (emus-track-title track)) (help-str (format "mouse-1, RET: Play '%.30s' (%.20s)" title artist))) - (when (or prev-record first) - (unless (equal (emus-record-artist prev-record) artist) + (when (or prev-track first) + (unless (equal (emus-track-artist prev-track) artist) (insert-text-button (propertize artist 'face 'emus-artist) - 'action #'emus--click-record + 'action #'emus--click-track 'follow-link t 'help-echo help-str - 'emus-record record) + 'emus-track track) (insert (propertize "\n" 'face 'emus-artist))) - (unless (equal (emus-record-album prev-record) album) + (unless (equal (emus-track-album prev-track) album) (insert-text-button (propertize (concat " " album) 'face 'emus-album) - 'action #'emus--click-record + 'action #'emus--click-track 'follow-link t 'help-echo help-str - 'emus-record record) + 'emus-track track) (insert (propertize "\n" 'face 'emus-album)))) - (emus-set-record-browser-pos record (point)) - (let ((is-current (equal record emus-current-record))) + (emus-set-track-browser-pos track (point)) + (let ((is-current (equal track emus-current-track))) (insert-text-button (concat (if is-current @@ -417,51 +417,51 @@ 'face (if is-current 'emus-track-current 'emus-track))) - 'action #'emus--click-record + 'action #'emus--click-track 'follow-link t 'help-echo help-str - 'emus-record record) + 'emus-track track) (insert (propertize "\n" 'face (if is-current 'emus-track-current 'emus-track)))))) -(defun emus--update-record (record) - (let ((record-pos (emus-record-browser-pos record))) +(defun emus--update-track (track) + (let ((track-pos (emus-track-browser-pos track))) (when (and (get-buffer "*emus*") - (emus-record-browser-pos record)) + (emus-track-browser-pos track)) (with-current-buffer "*emus*" (let ((inhibit-read-only t) (old-point (point))) - (goto-char record-pos) + (goto-char track-pos) (search-forward "\n") - (delete-region record-pos (point)) - (goto-char record-pos) - (emus--insert-record record) + (delete-region track-pos (point)) + (goto-char track-pos) + (emus--insert-track track) (goto-char old-point)))))) -(defun emus--render-records () +(defun emus--render-tracks () (with-current-buffer "*emus*" (let ((inhibit-read-only t) (old-pos (point))) (erase-buffer) (goto-char (point-min)) - (let ((prev-record nil)) - (dolist (record emus-records) - (emus--insert-record record prev-record (not prev-record)) - (setq prev-record record))) + (let ((prev-track nil)) + (dolist (track emus-tracks) + (emus--insert-track track prev-track (not prev-track)) + (setq prev-track track))) (goto-char old-pos)))) -(defun emus--click-record (button) - (emus-play-record (button-get button 'emus-record)) +(defun emus--click-track (button) + (emus-play-track (button-get button 'emus-track)) (emus-display-status)) (defun emus-centre-current () (interactive) (when (get-buffer "*emus*") (switch-to-buffer "*emus*") - (when emus-current-record - (goto-char (emus-record-browser-pos emus-current-record)) + (when emus-current-track + (goto-char (emus-track-browser-pos emus-current-track)) (recenter)))) (defun emus-browse () @@ -470,20 +470,19 @@ (emus--with-library (switch-to-buffer "*emus*") (emus-browser-mode) - (emus--render-records) + (emus--render-tracks) (emus-centre-current))) (defun emus-refresh () (interactive) (emus-stop) - (setq emus-records nil) + (setq emus-tracks nil) (emus-browse)) (defun emus-playpause-status () (interactive) (emus-playpause) (emus-display-status)) (defun emus-stop-status () (interactive) (emus-stop) (emus-display-status)) (defun emus-volume-up-status () (interactive) (emus-volume-up) (emus-display-status)) (defun emus-volume-down-status () (interactive) (emus-volume-down) (emus-display-status)) -(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)) @@ -492,6 +491,14 @@ (defun emus-jump-10s-backward-status () (interactive) (emus-jump-10s-backward) (emus-display-status)) (defun emus-centre-current-status () (interactive) (emus-centre-current) (emus-display-status)) +(defun emus-refresh-status () + (interactive) + (emus-stop) + (setq emus-tracks nil) + (emus--with-library + (emus-browse) + (emus-display-status))) + (defvar emus-browser-mode-map (let ((map (make-sparse-keymap))) (define-key map (kbd "SPC") 'emus-playpause-status) @@ -526,7 +533,7 @@ "Keymap for emus.") (define-derived-mode emus-browser-mode special-mode "emus-browser" - "Major mode for EMUS music player.") + "Major mode for EMUS music player file browser.") (when (fboundp 'evil-set-initial-state) (evil-set-initial-state 'emus-browser-mode 'motion))