From a254f2e035344a4ced0f14bc5d05196605a4f795 Mon Sep 17 00:00:00 2001 From: Tim Vaughan Date: Thu, 5 Dec 2019 10:23:51 +0100 Subject: [PATCH] More hacking. --- emus.el | 85 ++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 72 insertions(+), 13 deletions(-) diff --git a/emus.el b/emus.el index c66aed3..616d183 100644 --- a/emus.el +++ b/emus.el @@ -1,6 +1,6 @@ -;;; emus.el --- Simple music player for Emacs +;;; emus.el --- Simple music player for Emacs. -*- lexical-binding:t -*- -;; Author: T. G. Vaughan +;; Author: Tim Vaughan ;; Version: 1.0 ;; Keywords: multimedia ;; URL: http://github.com/tgvaughan/emus @@ -12,36 +12,95 @@ ;;; Code: +;;; Customizations +;; + (defgroup emus nil "Simple music player for Emacs inspired by CMUS." :group 'multimedia) (defcustom emus-directory "~/Music/" "Directory containing audio files for emus." - :type 'string - :group 'emus) + :type '(string)) -(defcustom emus-mpg123-excecutable "mpg123" +(defcustom emus-mpg123-program "mpg123" "Name of (and, optionally, path to) mpg123 binary." - :type 'string - :group 'emus) + :type '(string)) + +;;; Library +;; + +(defvar emus-library nil + "Emus audio library.") (defun emus-get-audio-files () "Get all mp3 files in main emus directory." (directory-files-recursively emus-directory ".*\\.mp3")) -(defun emus () - "Switch to *emus* audio library buffer." +(defvar emus-tags nil) + +(defun emus-update-tags () + "Get ID3 tags for given filename" + (let ((proc (emus-get-process)) + (depth 0) + (tagstr "") + (filenames (emus-get-audio-files))) + (setq emus-tags nil) + (set-process-filter proc (lambda (proc string) + (setq tagstr (concat tagstr string)) + (cond + ((string-suffix-p "}\n" string) (setq depth (- depth 1))) + ((string-suffix-p "{\n" string) (setq depth (+ depth 1)))) + (when (and (= depth 0) (string-suffix-p "\n" string)) + (add-to-list 'emus-tags `(,(car filenames) ,tagstr)) + (setq tagstr "") + (setq filenames (cdr filenames)) + (if filenames + (emus-send-cmd "lp" (car filenames)) + (set-process-filter proc nil))))) + (emus-send-cmd "lp" (car filenames)))) + +(defun emus-get-process () + "Return current or new mpg123 process." + (let* ((emus-process-raw (get-process "emus-process")) + (emus-process (if emus-process-raw + (if (process-live-p emus-process-raw) + emus-process-raw + (kill-process emus-process-raw) + nil)))) + (if emus-process + emus-process + (make-process :name "emus-process" + ;; :buffer (get-buffer-create "*emus-process*") + :command `(,emus-mpg123-program "-R"))))) + +(defun emus-send-cmd (cmd &rest args) + (process-send-string (emus-get-process) + (concat + (seq-reduce (lambda (s1 s2) (concat s1 " " s2)) args cmd) + "\n"))) + +;;; Browser +;; + +(defun emus-browse () + "Switch to *emus* audio library browser." (interactive) (switch-to-buffer "*emus*") (emus-mode)) (define-derived-mode emus-mode special-mode "Emus" - "Major mode for EMUS music player." + "Major mode for EMUS music player.") + +;;; Debugging + +(defun emus-test () + (message (emus-get-file-tags "/Users/vaughant/Music/Floex_-_Zorya/Floex - Zorya - 01 Ursa Major.mp3"))) - (setq-local default-directory emus-directory) +(defun emus-test-play () + (emus-send-cmd "lp" "/Users/vaughant/Music/Floex_-_Zorya/Floex - Zorya - 01 Ursa Major.mp3") + (emus-send-cmd "silence") + (emus-send-cmd "p")) - (let ((player (make-process :name "mpg123" :command '(emus-mpg123-excecutable "-R")))) - (process-send-string player "load The Midnight - Endless Summer - 01 Endless Summer.mp3\n"))) ;;; emus.el ends here -- 2.20.1