m@24
|
1 (cl:in-package #:amuse)
|
m@24
|
2
|
m@24
|
3 (defmethod chromatic-pitch ((pitch-designator chromatic-pitch))
|
m@24
|
4 pitch-designator)
|
m@24
|
5
|
m@24
|
6 (defmethod midi-pitch-number ((pitch-designator chromatic-pitch))
|
m@24
|
7 (%chromatic-pitch-number pitch-designator))
|
m@24
|
8
|
m@24
|
9 (defmethod midi-pitch-number ((pitch-designator pitch))
|
m@24
|
10 (%chromatic-pitch-number (chromatic-pitch pitch-designator)))
|
m@24
|
11
|
m@24
|
12 (defmethod span ((pitch-interval-designator pitch-interval))
|
m@24
|
13 (%pitch-interval-span pitch-interval-designator))
|
m@24
|
14
|
m@24
|
15 (defmethod duration ((period-designator period))
|
m@24
|
16 (%period-interval period-designator))
|
m@24
|
17
|
d@33
|
18 (defmethod (setf duration) ((value real) (period-designator period))
|
d@33
|
19 (setf (%period-interval period-designator) value))
|
d@33
|
20
|
m@24
|
21 (defmethod timepoint ((moment-designator moment))
|
m@24
|
22 (%moment-time moment-designator))
|
m@24
|
23
|
d@33
|
24 (defmethod (setf timepoint) ((value real) (moment-designator moment))
|
d@33
|
25 (setf (%moment-time moment-designator) value))
|
d@33
|
26
|
m@24
|
27 (defmethod beat-units-per-bar ((time-signature basic-time-signature))
|
m@24
|
28 (%basic-time-signature-numerator time-signature))
|
m@24
|
29
|
m@24
|
30 (defmethod beat-units ((time-signature basic-time-signature))
|
m@24
|
31 (%basic-time-signature-denominator time-signature))
|
m@24
|
32
|
m@67
|
33 (defmethod time-signature-equal ((ts1 basic-time-signature)
|
m@67
|
34 (ts2 basic-time-signature))
|
m@67
|
35 (let ((n1 (time-signature-numerator ts1))
|
m@67
|
36 (n2 (time-signature-numerator ts2))
|
m@67
|
37 (d1 (time-signature-denominator ts1))
|
m@67
|
38 (d2 (time-signature-denominator ts2)))
|
m@67
|
39 (and n1 n2 (= n1 n2)
|
m@67
|
40 d1 d2 (= d1 d2))))
|
m@67
|
41
|
m@24
|
42 (defmethod key-signature-sharps ((key-signature basic-key-signature))
|
m@24
|
43 (%basic-key-signature-sharp-count key-signature))
|
m@24
|
44
|
m@45
|
45 (defmethod key-signature-mode ((ks midi-key-signature))
|
m@45
|
46 (%midi-key-signature-mode ks))
|
m@45
|
47
|
m@67
|
48 (defmethod key-signature-equal ((ks1 basic-key-signature)
|
m@67
|
49 (ks2 basic-key-signature))
|
m@67
|
50 (let ((s1 (key-signature-sharps ks1))
|
m@67
|
51 (s2 (key-signature-sharps ks2)))
|
m@67
|
52 (and s1 s2 (= s1 s2))))
|
m@67
|
53
|
m@67
|
54 (defmethod key-signature-equal ((ks1 midi-key-signature)
|
m@67
|
55 (ks2 midi-key-signature))
|
m@67
|
56 (let ((s1 (key-signature-sharps ks1))
|
m@67
|
57 (s2 (key-signature-sharps ks2))
|
m@67
|
58 (m1 (key-signature-mode ks1))
|
m@67
|
59 (m2 (key-signature-mode ks2)))
|
m@67
|
60 (and s1 s2 (= s1 s2)
|
m@67
|
61 m1 m2 (= m1 m2))))
|
m@67
|
62
|
m@24
|
63 (defmethod bpm ((tempo tempo))
|
m@24
|
64 (%tempo-bpm tempo))
|
m@24
|
65
|
m@67
|
66 (defmethod tempo-equal ((t1 tempo) (t2 tempo))
|
m@67
|
67 (and (bpm t1) (bpm t2) (= t1 t2)))
|
m@67
|
68
|
m@67
|
69
|
m@24
|
70 ;; Time protocol
|
m@24
|
71
|
m@24
|
72 (defmethod time+ ((object1 moment) (object2 period))
|
m@24
|
73 (make-moment (+ (timepoint object1) (duration object2))))
|
m@24
|
74
|
m@24
|
75 (defmethod time+ ((object1 period) (object2 moment)) ;?
|
m@24
|
76 (time+ object2 object1))
|
m@24
|
77
|
m@24
|
78 (defmethod time+ ((object1 period) (object2 period))
|
m@24
|
79 (make-floating-period (+ (duration object1)
|
m@24
|
80 (duration object2))))
|
m@24
|
81
|
m@24
|
82 (defmethod time+ ((object1 moment) (object2 moment))
|
m@24
|
83 (error 'undefined-action :operation 'time+ :datatype (list (class-of object1) (class-of object2))))
|
m@24
|
84
|
m@24
|
85 (defmethod time- ((object1 moment) (object2 moment))
|
m@24
|
86 (make-anchored-period (timepoint object2)
|
m@24
|
87 (- (timepoint object1)
|
m@24
|
88 (timepoint object2))))
|
m@24
|
89
|
m@24
|
90 (defmethod time- ((object1 moment) (object2 period))
|
m@24
|
91 (make-moment (- (timepoint object1) (duration object2))))
|
m@24
|
92
|
m@24
|
93 (defmethod time- ((object1 period) (object2 moment)) ;?
|
m@24
|
94 (error 'undefined-action
|
m@24
|
95 :operation 'time-
|
m@24
|
96 :datatype (list (class-of object1) (class-of object2))))
|
m@24
|
97
|
m@24
|
98 (defmethod time- ((object1 period) (object2 period))
|
m@24
|
99 (make-floating-period (- (duration object2)
|
m@24
|
100 (duration object1))))
|
m@24
|
101
|
m@24
|
102 ;; these ones are less certain. I've just put them in, but think I
|
m@24
|
103 ;; should remove them and force the user to specify what they mean
|
m@24
|
104 ;; when they give objects that are both moments *and* periods to these
|
m@24
|
105 ;; functions.
|
m@24
|
106
|
m@24
|
107 (defmethod time- ((object1 anchored-period) (object2 anchored-period)) ;?
|
m@24
|
108 (time- (moment object1) (moment object2)))
|
m@24
|
109
|
m@24
|
110 (defmethod time- (object1 (object2 anchored-period)) ;?
|
m@24
|
111 (time- object1 (moment object2)))
|
m@24
|
112
|
m@24
|
113 (defmethod time- ((object1 anchored-period) object2) ;?
|
m@24
|
114 (time- (moment object1) object2))
|
m@24
|
115
|
m@24
|
116 (defmethod time> ((object1 moment) (object2 moment))
|
m@24
|
117 (> (timepoint object1) (timepoint object2)))
|
m@24
|
118
|
m@24
|
119 (defmethod time= ((object1 moment) (object2 moment))
|
m@24
|
120 (= (timepoint object1) (timepoint object2)))
|
m@24
|
121
|
m@24
|
122 (defmethod duration> ((object1 period) (object2 period))
|
m@24
|
123 (> (duration object1) (duration object2)))
|
m@24
|
124
|
m@24
|
125 (defmethod duration= ((object1 period) (object2 period))
|
m@24
|
126 (= (duration object1) (duration object2)))
|
m@24
|
127
|
m@24
|
128 (defmethod duration* ((object1 period) (object2 number))
|
m@24
|
129 (make-floating-period (* (duration object1) object2)))
|
m@24
|
130
|
m@24
|
131 (defmethod duration* ((object1 number) (object2 period))
|
m@24
|
132 (duration* object2 object1))
|
m@24
|
133
|
m@24
|
134 (defmethod duration/ ((object1 period) (object2 number))
|
m@24
|
135 (make-floating-period (/ (duration object1) object2)))
|
m@24
|
136
|
m@24
|
137 ;; Pitch protocol
|
m@24
|
138
|
m@24
|
139 (defmethod pitch+ ((object1 pitch-designator)
|
m@24
|
140 (object2 pitch-designator))
|
m@24
|
141 (error 'undefined-action :operation 'pitch+
|
m@24
|
142 :datatype (list (class-of object1) (class-of object2))))
|
m@24
|
143
|
m@24
|
144 (defmethod pitch+ ((object1 pitch-designator)
|
m@24
|
145 (object2 pitch-interval)) ; or should I check the
|
m@24
|
146 ; pitch/interval types?
|
d@34
|
147 (make-chromatic-pitch (+ (midi-pitch-number object1)
|
m@24
|
148 (span object2))))
|
m@24
|
149
|
m@24
|
150 (defmethod pitch+ ((object1 pitch-interval)
|
m@24
|
151 (object2 pitch-designator)) ;?
|
m@24
|
152 (pitch+ object2 object1))
|
m@24
|
153
|
m@24
|
154 (defmethod pitch+ ((object1 pitch-interval)
|
m@24
|
155 (object2 pitch-interval))
|
m@24
|
156 (make-pitch-interval (+ (span object1)
|
m@24
|
157 (span object2))))
|
m@24
|
158
|
m@24
|
159 (defmethod pitch- ((object1 pitch-designator)
|
m@24
|
160 (object2 pitch-designator))
|
d@34
|
161 (make-pitch-interval (- (midi-pitch-number object1)
|
d@34
|
162 (midi-pitch-number object2))))
|
m@24
|
163
|
m@24
|
164 (defmethod pitch- ((object1 pitch-designator)
|
m@24
|
165 (object2 pitch-interval))
|
d@34
|
166 (make-chromatic-pitch (- (midi-pitch-number object1)
|
m@24
|
167 (span object2))))
|
m@24
|
168
|
m@24
|
169 (defmethod pitch- ((object1 pitch-interval)
|
m@24
|
170 (object2 pitch-interval))
|
m@24
|
171 (make-pitch-interval (- (span object1)
|
m@24
|
172 (span object2))))
|
m@24
|
173
|
m@24
|
174 (defmethod pitch- ((object1 pitch-interval)
|
m@24
|
175 (object2 pitch-designator))
|
m@24
|
176 (error 'undefined-action :operation 'pitch-
|
m@24
|
177 :datatype (list (class-of object1) (class-of object2))))
|
m@24
|
178
|
m@24
|
179 (defmethod pitch> ((object1 pitch-designator)
|
m@24
|
180 (object2 pitch-designator))
|
d@34
|
181 (> (midi-pitch-number object1)
|
d@34
|
182 (midi-pitch-number object2)))
|
m@24
|
183
|
m@24
|
184 (defmethod pitch= ((object1 pitch-designator)
|
m@24
|
185 (object2 pitch-designator))
|
d@34
|
186 (= (midi-pitch-number object1)
|
d@34
|
187 (midi-pitch-number object2)))
|
m@24
|
188
|
m@24
|
189 (defmethod interval> ((object1 pitch-interval)
|
m@24
|
190 (object2 pitch-interval))
|
m@24
|
191 (> (span object1)
|
m@24
|
192 (span object2)))
|
m@24
|
193
|
m@24
|
194 (defmethod interval= ((object1 pitch-interval)
|
m@24
|
195 (object2 pitch-interval))
|
m@24
|
196 (= (span object1)
|
m@24
|
197 (span object2)))
|
m@24
|
198
|
m@24
|
199
|
m@24
|
200
|
m@24
|
201 ;; Allen
|
m@24
|
202
|
m@24
|
203 (defmethod meets ((object1 anchored-period)
|
m@24
|
204 (object2 anchored-period))
|
m@24
|
205 (or (time= (cut-off object1) object2)
|
m@24
|
206 (time= (cut-off object2) object1)))
|
m@24
|
207
|
m@24
|
208 (defmethod before ((object1 anchored-period)
|
m@24
|
209 (object2 anchored-period))
|
m@24
|
210 (time> object2 (cut-off object1)))
|
m@24
|
211
|
m@24
|
212 (defmethod overlaps ((object1 anchored-period)
|
m@24
|
213 (object2 anchored-period))
|
m@24
|
214 ;; FIXME: Is there a tidier method?
|
m@24
|
215 (or (and (time> object2 object1) ; object1 starts before object2
|
m@24
|
216 (time> (cut-off object1) object2) ; object1 ends after object2 starts
|
m@24
|
217 (time> (cut-off object2) (cut-off object1))) ; object1 ends before object2 does
|
m@24
|
218 (and (time> object1 object2) ; object1 starts after object2
|
m@24
|
219 (time> (cut-off object2) object1) ; object1 starts before object2 ends
|
m@24
|
220 (time> (cut-off object1) (cut-off object2))))) ; object1 ends after object2 does
|
m@24
|
221
|
m@24
|
222 (defmethod during ((object1 anchored-period)
|
m@24
|
223 (object2 anchored-period))
|
m@24
|
224 (and (time> object1 object2)
|
m@24
|
225 (time< (cut-off object2) (cut-off object2))))
|
m@24
|
226
|
m@24
|
227 (defmethod starts ((object1 anchored-period)
|
m@24
|
228 (object2 anchored-period))
|
m@24
|
229 (time= object1 object2))
|
m@24
|
230
|
m@24
|
231 (defmethod ends ((object1 anchored-period)
|
m@24
|
232 (object2 anchored-period))
|
m@24
|
233 (time= (cut-off object1) (cut-off object2)))
|
m@24
|
234
|
m@24
|
235 ;; ...and
|
m@24
|
236
|
d@33
|
237 (defmethod period= ((object1 anchored-period)
|
d@33
|
238 (object2 anchored-period))
|
d@33
|
239 (and (time= object1 object2)
|
d@33
|
240 (duration= object1 object2)))
|
d@33
|
241 (defmethod period= ((object1 floating-period)
|
d@33
|
242 (object2 floating-period))
|
d@33
|
243 (duration= object1 object2))
|
d@33
|
244
|
m@24
|
245 (defmethod period-intersection ((object1 anchored-period)
|
m@24
|
246 (object2 anchored-period))
|
m@24
|
247 (cond
|
m@24
|
248 ((disjoint object1 object2)
|
m@24
|
249 ;; if they don't overlap, return nil, not a negative-valued
|
m@24
|
250 ;; period
|
m@24
|
251 nil)
|
m@24
|
252 ((let* ((start (if (time> (onset object2) (onset object1))
|
m@24
|
253 (onset object2)
|
m@24
|
254 (onset object1)))
|
m@24
|
255 (duration (duration (time- (if (time> (cut-off object2) (cut-off object1))
|
m@24
|
256 (cut-off object1)
|
m@24
|
257 (cut-off object2))
|
m@24
|
258 start))))
|
m@24
|
259 (make-anchored-period (timepoint start) duration)))))
|
m@24
|
260
|
m@24
|
261
|