-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathclasses.lisp
157 lines (142 loc) · 5.03 KB
/
classes.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
;;; -*- Mode: Lisp -*-
;;; This software is in the public domain and is
;;; provided with absolutely no warranty.
(in-package #:mpd)
(define-condition mpd-error (error)
((text :initarg :text :reader text
:initform nil))
(:report (lambda (condition stream)
(princ (text condition) stream))))
(macrolet ((define-conditions (names)
`(progn ,@(mapcar
(lambda (name)
`(define-condition ,name (mpd-error) ()))
names))))
(define-conditions (bad-argument incorrect-password
not-permitted unknown-command not-exist
playlist-size-exceed already-updating exist)))
(defparameter *error-ids-alist*
'((2 . bad-argument)
(3 . incorrect-password)
(4 . not-permitted)
(5 . unknown-command)
(50 . not-exist)
(51 . playlist-size-exceed)
(54 . already-updating)
(56 . exist)))
(defparameter *tag-types*
'(:artist :album :title :track :name :genre :date
:composer :performer :comment :disc :filename :any)
"Types of tags for using in `search' and `find'")
(deftype tag-type ()
`(member ,@*tag-types*))
(defclass track ()
((file
:initform nil :initarg :file :accessor file)
(title
:initform nil :initarg :title :accessor title)
(artist
:initform nil :initarg :artist :accessor artist)
(albumartist
:initform nil :initarg :albumartist :accessor albumartist)
(album
:initform nil :initarg :album :accessor album)
(genre
:initform nil :initarg :genre :accessor genre)
(date
:initform nil :initarg :date :accessor date)
(performer
:initform nil :initarg :performer :accessor performer)
(composer
:initform nil :initarg :composer :accessor composer)
(disc
:initform nil :initarg :disc :accessor disc)
(track
:initform nil :initarg :track :accessor track-number)
(time
:initform nil :initarg :time :accessor duration)
(last-modified
:initform nil :initarg :last-modified :accessor last-modified)))
(defclass playlist (track)
((pos
:initform nil :initarg :pos :accessor position-in-playlist
:type integer)
(id
:initform nil :initarg :id :accessor id
:type integer)))
(defclass status ()
((volume
:reader volume :initarg :volume :initform nil)
(repeat
:reader repeat :initarg :repeat :initform nil)
(random
:reader randomized :initarg :random :initform nil)
(playlist
:reader playlist-version :initarg :playlist :initform nil)
(playlist-length
:reader playlist-length :initarg :playlistlength :initform nil)
(xfade
:reader xfade :initarg :xfade :initform nil)
(state
:reader state :initarg :state :initform nil)
(audio
:reader audio :initarg :audio :initform nil)
(bitrate
:reader bitrate :initarg :bitrate :initform nil)
(time
:reader duration :initarg :time :initform nil)
(songid
:reader songid :initarg :songid :initform nil)
(song :reader song :initarg :song :initform nil)
(nextsongid
:reader nextsongid :initarg :nextsongid :initform nil)
(nextsong
:reader nextsong :initarg :nextsong :initform nil)
(elapsed
:reader elapsed :initarg :elapsed :initform nil)
(mixrampdb
:reader mixrampdb :initarg :mixrampdb :initform nil)
(consume
:reader consume :initarg :consume :initform nil)
(single
:reader single :initarg :single :initform nil)))
(defclass stats ()
((artists
:reader artists :initarg :artists :initform nil)
(albums
:reader albums :initarg :albums :initform nil)
(songs
:reader songs :initarg :songs :initform nil)
(uptime
:reader uptime :initarg :uptime :initform nil)
(playtime
:reader playtime :initarg :playtime :initform nil)
(db-playtime
:reader db-playtime :initarg :db_playtime :initform nil)
(db-update
:reader db-update :initarg :db_update :initform nil)))
(macrolet ((generate-commands (class names)
`(progn
,@(mapcar (lambda (name)
`(defmethod ,name ((stream usocket:stream-usocket))
(,name (,class stream))))
names))))
(generate-commands status
(volume repeat randomized playlist-version playlist-length
xfade state audio bitrate duration songid song))
(generate-commands stats
(artists albums songs uptime playtime db-playtime db-update)))
(defparameter *integer-keys*
'(:id :pos :volume :playlist :playlistlength
:xfade :song :songid :bitrate :playtime
:artists :albums :songs :uptime :db_playtime :db_update
:outputid)
"List of keys which values must be integers.")
(defparameter *value-processing-functions*
'(:time parse-time :state to-keyword
:random string-not-zerop :repeat string-not-zerop
:outputenabled string-not-zerop))
(defmethod print-object ((object track) stream)
(print-unreadable-object (object stream :type t :identity t)
(with-slots (artist title album) object
(format stream "~A - ~A (~A)" artist title album))))