All pastes #383327 Raw Edit

ve mpd shebang

public text v1 · immutable
·published 2007-03-06 08:05 UTC
rendered paste body
;;;; vim: set fenc=utf-8 lisp ic wm=0 et tw=0 sm para=lpppipnpbp sect=shuh ai :
;;;; ---------------------------------------------------------------------------
;;;; FILE IDENTIFICATION
;;;;
;;;; Name:      mpd-shebang.lisp
;;;; Purpose:   An mpd status printing shebang script.
;;;; Author:    Stephen P. Horner
;;;; Started:   2006-08-12
;;;;
;;;; $Id:$
;;;;
;;;; This file is Copyright © 2006 by Stephen P. Horner
;;;;
;;;; ---------------------------------------------------------------------------

(declaim (optimize (speed 1) (space 1) (safety 1) (debug 3) (compilation-speed 3)))

#-sbcl
(error "This script will only work with 'CL-MPD ASDF-INSTALLED, and only on SBCL.")

;;; Muffle compiler-notes globally
(eval-when (:compile-toplevel :load-toplevel :execute)
  (declaim (sb-ext:muffle-conditions sb-ext:compiler-note)))

(require 'asdf)
(asdf:operate 'asdf:load-op 'mpd :verbose nil)

(in-package #:mpd)

(defun mpd-client (&key (bitrate nil))
  (let ((client (make-instance 'mpd-client))
        (status (make-instance 'mpd-status))
        (song   (make-instance 'mpd-song)))

    (with-mpd-client-slots (client)
      (mpd-update-song client song)
      (with-mpd-song-slots (song)
        (if (stringp composer)
          (format *standard-output*
                  "MPD is playing \"~:[~;~:*~A~]\" by \"~:[~;~:*~A~]\" from the album \"~:[~;~:*~A~]\" composed by \"~:[~;~:*~A~]\" "
                  title artist album composer)
          (format *standard-output*
                  "MPD is playing \"~:[~;~:*~A~]\" by \"~:[~;~:*~A~]\" from the album \"~:[~;~:*~A~]\" "
                  title artist album))

      (when (>= bitrate 1)
        (dotimes (i bitrate)
          (mpd-update-status client status)
          (let ((cbr (mpd-status-bitrate status)))
            (format t "~%@ ~A kbps~%" cbr))))

      (mpd-client-disconnect client)))))

(progn
  (sb-ext:disable-debugger)
  (mpd-client :bitrate 1)
  (sb-ext:quit))

;;; EOF