;; -*- lexical-binding: t -*- ;;; utilities (defun jao-mixer-get-level (&optional dev nomsg) (interactive) (let* ((dev (or dev "Master")) (s (shell-command-to-string (format "amixer sget %s" dev))) (s (car (last (split-string s "\n" t))))) (when (string-match ".*Front .*\\[\\([0-9]+\\)%\\] .*" s) (let ((level (match-string 1 s))) (unless nomsg (message "%s level: %s%%" dev level)) (string-to-number level))))) (defun jao-mixer-set (dev v) (jao-shell-exec* t "amixer" "sset" dev v) (jao-mixer-get-level dev)) (defun jao-mixer-master-toggle () (interactive) (jao-mixer-set "Master" "toggle")) (defun jao-mixer-master-up () (interactive) (jao-mixer-set "Master" "10%+")) (defun jao-mixer-master-down () (interactive) (jao-mixer-set "Master" "10%-")) (defun jao-mixer-capture-up () (interactive) (jao-mixer-set "Capture" "10%+")) (defun jao-mixer-capture-down () (interactive) (jao-mixer-set "Capture" "10%-")) (jao-shell-def-exec jao-audio-applet "pasystray") (defun jao-toggle-audio-applet () (interactive) (or (jao-shell-kill-p "paystray") (jao-audio-applet))) (global-set-key (kbd "") #'jao-toggle-audio-applet) ;;; streaming aliases (defalias 'jao-streaming-list #'ignore) (defalias 'jao-streaming-like #'ignore) (defalias 'jao-streaming-dislike #'ignore) (defalias 'jao-streaming-toggle-shuffle #'ignore) (defalias 'jao-streaming-lyrics #'ignore) (defalias 'jao-streaming-toggle #'ignore) (defalias 'jao-streaming-next #'ignore) (defalias 'jao-streaming-prev #'ignore) (defalias 'jao-streaming-current #'ignore) (defalias 'jao-streaming-seek #'ignore) (defalias 'jao-streaming-seek-back #'ignore) (defalias 'jao-streaming-volume #'ignore) (defalias 'jao-streaming-volume-down #'ignore) ;;; mpris (defun jao-mpris-lyrics (&optional force) (interactive "P") (jao-show-lyrics force #'jao-mpris-artist-title)) (defun jao-mpris-mopidy-p () (string= "mopidy "jao-mpris-player)) (defun jao-mpc-mopidy-playlist () (interactive) (jao-mpc-show-playlist jao-mopidy-port)) (use-package jao-mpris :demand t) (defun jao-mpris-setup-aliases () (setq espotify-play-uri-function #'espotify-play-uri-with-dbus) ;; (setq jao-mpris-player "mopidy") (defalias 'jao-streaming-list #'jao-mpc-mopidy-playlist) (defalias 'jao-streaming-lyrics #'jao-mpris-lyrics) (defalias 'jao-streaming-toggle #'jao-mpris-play-pause) (defalias 'jao-streaming-next #'jao-mpris-next) (defalias 'jao-streaming-prev #'jao-mpris-previous) (defalias 'jao-streaming-current #'jao-mpris-show-osd) (defalias 'jao-streaming-seek #'jao-mpris-seek) (defalias 'jao-streaming-seek-back #'jao-mpris-seek-back) (defalias 'jao-streaming-volume #'jao-mpris-vol) (defalias 'jao-streaming-volume-down #'jao-mpris-vol-down)) (jao-mpris-register "playerctld" :session 70) ;; (jao-mpris-register "mopidy" :session 70) ;;; mpc (use-package jao-mpc :demand t :commands jao-mpc-setup) (defvar jao-mopidy-port 6669) (defvar jao-mpc-last-port jao-mpc-port) (defun jao-mpc-toggle-port () (interactive) (setq jao-mpc-port (if (equal jao-mpc-port jao-mopidy-port) 6600 jao-mopidy-port) jao-mpc-last-port jao-mpc-port)) (defsubst jao-mpc-mopidy-p () (equal jao-mpc-last-port jao-mopidy-port)) (jao-mpc-setup jao-mopidy-port 70) (defun jao-mpc-pport (&optional mop) (cond ((or mop (jao-mpc-playing-p jao-mopidy-port)) jao-mopidy-port) ((jao-mpc-playing-p) 6600) (t jao-mpc-last-port))) (defmacro jao-defun-play (name &optional mpc-name) (let ((arg (gensym))) `(defun ,(intern (format "jao-player-%s" name)) (&optional ,arg) (interactive "P") (,(intern (format "jao-mpc-%s" (or mpc-name name))) (setq jao-mpc-last-port (jao-mpc-pport ,arg)))))) (jao-defun-play toggle) (jao-defun-play next) (jao-defun-play previous) (jao-defun-play stop) (jao-defun-play echo echo-current-times) (jao-defun-play list show-playlist) (jao-defun-play info lyrics-track-data) (jao-defun-play browse show-albums) (jao-defun-play select-album) (defun jao-player-seek (delta) (jao-mpc-seek delta (jao-mpc-pport))) (defalias 'jao-player-connect 'jao-mpc-connect) (defalias 'jao-player-play 'jao-mpc-play) ;;; spotify (jao-load-path "espotify") (use-package espotify :demand t :init (setq espotify-service-name "mopidy")) (use-package consult-spotify :demand t) (defalias 'jao-streaming-album #'consult-spotify-album) (defalias 'jao-streaming-track #'consult-spotify-track) (defalias 'jao-streaming-artist #'consult-spotify-artist) (defalias 'jao-streaming-playlist #'consult-spotify-playlist) (jao-def-exec-in-term "ncmpcpp" "ncmpcpp" (jao-afio-goto-scratch)) ;;; spt (use-package jao-spt :demand t :config (defun jao-spt-setup-aliases () (setq espotify-play-uri-function #'jao-spt-play-uri) (defalias 'jao-streaming-list #'jao-term-spt) (defalias 'jao-streaming-lyrics #'jao-spt-show-lyrics) (defalias 'jao-streaming-toggle #'jao-spt-toggle) (defalias 'jao-streaming-next #'jao-spt-next) (defalias 'jao-streaming-prev #'jao-spt-previous) (defalias 'jao-streaming-current #'jao-spt-echo-current) (defalias 'jao-streaming-seek #'jao-spt-seek) (defalias 'jao-streaming-seek-back #'jao-spt-seek-back) (defalias 'jao-streaming-volume #'jao-spt-vol) (defalias 'jao-streaming-volume-down #'jao-spt-vol-down) (defalias 'jao-streaming-like #'jao-spt-like) (defalias 'jao-streaming-dislike #'jao-spt-dislike) (defalias 'jao-streaming-toggle-shuffle #'jao-spt-toggle-shuffle))) (jao-def-exec-in-term "spt" "spt" (jao-afio-goto-scratch)) (defvar jao-spt-on t) (defun jao-streaming-toggle-player () (interactive) (if jao-spt-on (progn (setq jao-mpris-player "playerctld") (require 'jao-mpris) (jao-mpris-setup-aliases)) (jao-spt-setup-aliases) (setq jao-mpris-player "spt")) (setq jao-spt-on (not jao-spt-on)) (message "%s activated " jao-mpris-player)) (jao-streaming-toggle-player) ;;; music transients (require 'jao-lyrics) (setq jao-lyrics-info-function #'jao-player-info) (defun jao-player-seek-10 () (interactive) (jao-player-seek 10)) (defun jao-player-seek--10 () (interactive) (jao-player-seek -10)) (defun jao-streaming-clear () (interactive) (jao-mpc-clear jao-mopidy-port)) (defun jao-streaming-echo-current () (interactive) (jao-mpc-echo-current jao-mopidy-port)) (defun jao-streaming-show-playlist () (interactive) (jao-mpc-show-playlist jao-mopidy-port)) (use-package jao-random-album :demand t :config (defun jao--notify-album (album) (unless jao-minibuffer-mode (jao-notify album "Next album" jao-notify-audio-icon)) (jao-minibuffer-refresh)) (setq jao-random-album-notify #'jao--notify-album)) (defun jao-toggle-pasystray-applet () (interactive) (or (jao-shell-kill-p "pasystray") (jao-shell-exec "pasystray"))) (transient-define-prefix jao-transient-streaming () [:description (lambda () (format "Streaming using %s" jao-mpris-player)) ["Search" :if jao-mpris-mopidy-p ("a" "album" jao-streaming-album) ("A" "artist" jao-streaming-artist) ("t" "track" jao-streaming-track) ("P" "playlist" jao-streaming-playlist)] ["Play" ("s" "toggle" jao-streaming-toggle) ("n" "next" jao-streaming-next) ("p" "previous" jao-streaming-prev) ("T" "toggle player" jao-streaming-toggle-player)] ["Seek & shout" ("f" "seek fwd" jao-streaming-seek :transient t) ("F" "seek bwd" jao-streaming-seek-back :transient t) ("u" "up" jao-streaming-volume :transient t) ("d" "down" jao-streaming-volume-down :transient t)] ["Browse" ("l" "playing list" jao-streaming-list :if jao-mpris-mopidy-p) ("L" "lyrics" jao-streaming-lyrics) ("w" "currently playing" jao-streaming-current)] ["Act" :if jao-mpris-mopidy-p ("k" "like" jao-streaming-like) ("K" "dislike" jao-streaming-dislike) ("S" "toggle shuffle" jao-streaming-toggle-shuffle)]]) (transient-define-prefix jao-transient-media () [["Play" ("m" "toggle" jao-player-toggle) ("n" "next" jao-player-next) ("p" "previous" jao-player-previous) ("s" "select album" jao-player-select-album)] ["Seek and search" ("f" "seek fwd" jao-player-seek-10 :transient t) ("F" "seek bwd" jao-player-seek--10 :transient t) ("a" "search album" jao-mpc-select-album) ("S" "play stream" jao-mpc-play-stream)] ["Browse" ("b" "browse" jao-player-browse) ("l" "show play list" jao-player-list) ("L" "show lyrics" jao-show-lyrics) ("w" "now playing" jao-player-echo)] [:description (lambda () (message "%s %s" (if (jao-mpc-mopidy-p) "mopidy" "mpd") (if (jao-mpc-playing-p) (jao-mpc--current-timestr t) (jao-mpc--current-str))) (format "Master %s%%" (jao-mixer-get-level nil t))) ("d" "down" jao-mixer-master-down :transient t) ("u" "up" jao-mixer-master-up :transient t) ("M" "toggle" jao-mixer-master-toggle)] [:description (lambda () (format "Capture %s%%" (jao-mixer-get-level "Capture" t))) ("D" "down" jao-mixer-capture-down :transient t) ("U" "up" jao-mixer-capture-up :transient t)] ["Utilities" ("c" "reconnect to mpd" jao-player-connect) ("N" "next random album" jao-random-album-next) ("r" (lambda () (concat (if jao-random-album-active "dis" "en") "able random album")) jao-random-album-toggle) ;; ("P" (lambda () (concat "Toggle to " (if (jao-mpc-mopidy-p) "mpd" "mopidy"))) ;; jao-mpc-toggle-port) ("P" "pasystray" jao-toggle-pasystray-applet)]]) (global-set-key (kbd "s-m") #'jao-transient-media) ;;; - provide (provide 'jao-custom-multimedia)