;; randomness for playing with gronk ;; Waider, January/February 2001 (require 'timer) ;; incompatible with itimer, typically. (defvar gronk-play-file "" "*Location of gronk's `currently playing' file") (defvar gronk-noticed nil "last track that gronk noticed was playing") (defvar gronk-noticed-mod-time nil "time that we noticed gronk-noticed") (defvar gronk-minibuf-timer nil "timer for gronk minibuf") (defvar gronk-playlist-file "" "*Location of gronk's playlist file") (defvar gronk-playlist-mod-time nil "modtime of gronk-playlist-file") ;; Display the playlist (defun gronk-playlist() (save-excursion ;; Must be a nicer way to do this (if (file-readable-p gronk-play-file) (if (equal (nth 5 (file-attributes gronk-play-file)) gronk-playlist-list-mod-time) gronk-playlist-list (let (artist album track) (set-buffer (get-buffer-create " *gronk-current*")) (erase-buffer) (insert-file-contents gronk-play-file) (goto-char (point-min)) (if (re-search-forward "^\\([^\t]*\\)\t\\([^\t]*\\)\t\\([^\t\r\n]*\\)" (point-max) t) (setq artist (buffer-substring (match-beginning 1) (match-end 1)) album (buffer-substring (match-beginning 2) (match-end 2)) track (buffer-substring (match-beginning 3) (match-end 3)))) ;; save the mod time (setq gronk-playlist-list-mod-time (nth 5 (file-attributes gronk-play-file))) ;; set gronk-playlist-list & return it. (setq gronk-playlist-list (list artist album track)))))) gronk-playlist-list) ;; Check what the currently-playing track is. (defun gronk-current() "Get the currently playing track from Gronk." (save-excursion ;; XMMS overrides gronk (if (fboundp 'xmms-current) (setq gronk-noticed (xmms-current)) ;; Must be a nicer way to do this (if (file-readable-p gronk-play-file) (if (equal (nth 5 (file-attributes gronk-play-file)) gronk-noticed-mod-time) gronk-noticed (let (artist album track) (set-buffer (get-buffer-create " *gronk-current*")) (erase-buffer) (insert-file-contents gronk-play-file) (goto-char (point-min)) (if (re-search-forward "^\\([^\t]*\\)\t\\([^\t]*\\)\t\\([^\t\r\n]*\\)" (point-max) t) (setq artist (buffer-substring (match-beginning 1) (match-end 1)) album (buffer-substring (match-beginning 2) (match-end 2)) track (buffer-substring (match-beginning 3) (match-end 3)))) ;; save the mod time (setq gronk-noticed-mod-time (nth 5 (file-attributes gronk-play-file))) ;; set gronk-noticed & return it. (setq gronk-noticed (list artist album track))))))) gronk-noticed) ;; set up gronk-in-the-minibuf (defun gronk-minibuf-init() (run-at-time nil 60 'gronk-timer-func)) ;; gronk-in-the-minibuf timer function (defun gronk-timer-func() (let* ((data (gronk-current)) (artist (nth 0 data)) (album (nth 1 data)) (track (nth 2 data))) (and artist track (message "Now playing _%s_ by %s" track artist)))) (provide 'gronk)