Permalink
Browse files

Small changes.

  • Loading branch information...
1 parent a0f7b04 commit 26c2d20ddebedbd47981dfcf2100d7b736b28a93 @stassats committed Sep 13, 2008
Showing with 91 additions and 87 deletions.
  1. +7 −4 commands.lisp
  2. +12 −13 mpd.lisp
  3. +72 −70 package.lisp
View
11 commands.lisp
@@ -132,6 +132,7 @@
(add connection (file what)))
(defmethod-command add ((what string))
+ (check-args string what)
(send "add" what))
(defgeneric add-id (connection what)
@@ -141,6 +142,7 @@
(add connection (file what)))
(defmethod-command add-id ((what string))
+ (check-args string what)
(car (filter-keys (send "addid" what))))
(defcommand move (from to)
@@ -197,19 +199,19 @@
"Scan directory for music files and add them to the database."
(send "update" path))
-(defcommand mpd-find (type what)
+(defcommand find-tracks (type what)
"Find tracks in the database with a case sensitive, exact match."
(assert (member type +tag-types+))
(check-args string what)
(parse-list (send "find" type what) 'track))
-(defcommand mpd-list (metadata-1 &optional metadata-2 search-term)
+(defcommand list-metadata (metadata-1 &optional metadata-2 search-term)
"List all metadata of `metadata-1'.
If `metadata-2' & `search-term' are supplied,
then list all `metadata-1' in which `metadata-2' has value `search-term'."
(send "list" metadata-1 metadata-2 search-term))
-(defcommand mpd-search (type what)
+(defcommand search-tracks (type what)
"Find tracks in the database with a case sensitive, inexact match."
(assert (member type +tag-types+))
(check-args string what)
@@ -229,9 +231,10 @@ then list all `metadata-1' in which `metadata-2' has value `search-term'."
(check-args (or string null) path)
(parse-list (send "lsinfo" path) 'track))
-(defcommand mpd-count (scope query)
+(defcommand count-tracks (scope query)
"Number of songs and their total playtime matching `query'.
Return: (number playtime)."
+ (check-args string query)
(filter-keys (send "count" scope query)))
(defcommand set-volume (value)
View
25 mpd.lisp
@@ -17,14 +17,14 @@
(when password (password connection password)))))
(defun read-answer (stream)
- (loop
- for line = (read-line stream nil)
- until (string= line "OK" :end1 2)
- collect line
- if (string= line "ACK" :end1 3) do
- (handle-error line)))
+ (loop for line = (read-line stream nil)
+ until (string= line "OK" :end1 2)
+ collect line
+ if (string= line "ACK" :end1 3)
+ do (handle-error line)))
(defun handle-error (text)
+ ;; Error format: ACK [<error id>@<position>] {<comand name>} <description>
(let* ((error-id (parse-integer text :start 5 :junk-allowed t))
(delimiter (position #\] text))
(condition (cdr (assoc error-id +error-ids-alist+))))
@@ -47,7 +47,7 @@
(error 'mpd-error :text (format nil "The stream ~A is not opened." stream)))))
(defun split-value (string)
- "Split a string 'key: value' into (list :key value)."
+ "Split a string `key: value' into (list :key value)."
(let* ((column-position (position #\: string))
(keyword (make-keyword
(string-upcase (subseq string 0 column-position))))
@@ -67,12 +67,9 @@
(subseq entry (+ 2 (position #\: entry))))
strings))
-;;; C.f. performance:
-;; (apply (lambda (&key foo bar) (make-instance
-;; 'zot :quux 42 :foo foo :bar bar)) list)
(defun make-track (data type)
"Make a new instance of the class playlist with initargs from
- the list of strings 'key: value'."
+ the list of strings `key: value'."
(apply 'make-instance type (split-values data)))
(defun parse-list (list &optional class)
@@ -125,8 +122,10 @@
,@forms)))
(defmacro check-args (type &rest args)
+ "Check string and integer arguments."
(if (or (eq type 'string)
- (equal type '(or string null)))
+ (and (listp type)
+ (member 'string type)))
`(progn ,@(mapcan
(lambda (arg)
`((check-type ,arg ,type "a string")
@@ -135,4 +134,4 @@
`(progn ,@(mapcar
(lambda (arg)
`(check-type ,arg ,type "an integer"))
- args))))
+ args))))
View
142 package.lisp
@@ -2,82 +2,84 @@
(in-package :cl-user)
-(defpackage :mpd
- (:use :cl :usocket :alexandria)
+(defpackage #:mpd
+ (:use #:cl #:usocket #:alexandria)
(:export
- :*defualt-host*
- :*default-port*
- :connect
- :disconnect
- :password
- :with-mpd
- :disable-output
- :enableoutput
- :outputs
+ #:*defualt-host*
+ #:*default-port*
+ #:connect
+ #:disconnect
+ #:password
+ #:with-mpd
+ #:disable-output
+ #:enable-output
+ #:outputs
- :ping
- :kill
- :status
+ #:ping
+ #:kill
+ #:status
- :now-playing
- :pause
- :play
- :stop
- :previous
- :next
- :set-volume
+ #:now-playing
+ #:pause
+ #:play
+ #:stop
+ #:previous
+ #:next
+ #:set-volume
- :add
- :add-id
- :move
- :move-id
- :swap
- :swap-id
- :clear-playlist
- :delete-track
- :delete-id
- :save-playlist
- :load-plalist
- :rename-playlist
- :playlist-info
- :shuffle
- :list-playlist
- :list-playlist-info
+ #:add
+ #:add-id
+ #:move
+ #:move-id
+ #:swap
+ #:swap-id
+ #:clear-playlist
+ #:delete-track
+ #:delete-id
+ #:save-playlist
+ #:load-playlist
+ #:rename-playlist
+ #:playlist-info
+ #:shuffle
+ #:list-playlist
+ #:list-playlist-info
- :update
- :tag-types
- :url-handlers
- :list-all
- :list-info
- :list-all-info
+ #:update
- :commands
- :not-commands
- :mpd-find
- :mpd-list
- :mpd-search
+ #:list-all
+ #:list-info
+ #:list-all-info
+ #:find-tracks
+ #:search-tracks
+ #:list-metadata
+ #:count-tracks
- :track
- :file
- :title
- :artist
- :album
- :date
- :duration
- :genre
- :composer
+ #:commands
+ #:not-commands
+ #:tag-types
+ #:url-handlers
- :playlist
- :position-in-playlist
- :id
+ #:track
+ #:file
+ #:title
+ #:artist
+ #:album
+ #:date
+ #:duration
+ #:genre
+ #:composer
- :mpd-error
- :protocol-mismatch
- :bad-argument
- :incorrect-password
- :not-permitted
- :unknown-command
- :not-exist
- :playlist-size-exceed
- :already-updating
- :exist))
+ #:playlist
+ #:position-in-playlist
+ #:id
+
+ #:mpd-error
+ #:protocol-mismatch
+ #:bad-argument
+ #:incorrect-password
+ #:not-permitted
+ #:unknown-command
+ #:not-exist
+ #:playlist-size-exceed
+ #:already-updating
+ #:exist))

0 comments on commit 26c2d20

Please sign in to comment.