m@24
|
1 (cl:in-package #:amuse)
|
m@24
|
2
|
m@24
|
3 ;;; Pulling compositions from the database
|
m@24
|
4
|
m@24
|
5 (defgeneric get-composition (identifier))
|
m@24
|
6
|
d@33
|
7 ;;; Getting constituents from compositions
|
d@33
|
8 ;; IS this the mechanism we want to use
|
d@72
|
9 (defgeneric time-signatures (composition)
|
d@72
|
10 (:documentation "Returns all time-signatures in a composition
|
d@72
|
11 Probably shouldn't be exported - can be replaced
|
d@72
|
12 by (get-applicable-time-signature commposition composition)"))
|
d@72
|
13 (defgeneric (setf time-signatures) (sequence composition)
|
d@72
|
14 (:documentation "Sets all time-signatures in a composition.
|
d@72
|
15 Is this wanted here?"))
|
d@72
|
16 (defgeneric tempi (composition)
|
d@72
|
17 (:documentation "Returns all tempi in a composition Probably
|
d@72
|
18 shouldn't be exported - can be replaced
|
d@72
|
19 by (get-applicable-tempi commposition composition)"))
|
d@72
|
20 (defgeneric (setf tempi) (sequence composition)
|
d@72
|
21 (:documentation "Sets all tempi in a composition.
|
d@72
|
22 Is this wanted here?"))
|
d@72
|
23 (defgeneric key-signatures (composition)
|
d@72
|
24 (:documentation "Returns all key-signatures in a composition
|
d@72
|
25 Probably shouldn't be exported - can be replaced
|
d@72
|
26 by (get-applicable-key-signature commposition composition)"))
|
d@72
|
27 (defgeneric (setf key-signatures) (sequence composition)
|
d@72
|
28 (:documentation "Sets all key sigs in a composition.
|
d@72
|
29 Is this wanted here?"))
|
d@33
|
30
|
m@24
|
31 ;;; Simple Accessors
|
m@24
|
32
|
m@24
|
33 ;; pitch-based
|
m@24
|
34
|
m@24
|
35 (defgeneric pitch (object &key kind)) ; ? Maybe this returns the pitch
|
m@24
|
36 ; in its ur form?
|
m@24
|
37 (defgeneric chromatic-pitch (pitch-designator)) ; How simple are these
|
m@24
|
38 (defgeneric diatonic-pitch (pitch-designator)) ; if has to be computed?
|
m@24
|
39 (defgeneric frequency (object)) ;?
|
d@72
|
40 (defgeneric midi-pitch-number (pitch-designator)
|
d@72
|
41 (:documentation "Takes a pitch-designator (usually a pitched
|
d@72
|
42 event) and returns an integer between 0 and 127 representing
|
d@72
|
43 the chromatic pitch designated (60=middle C, 48 the C below
|
d@72
|
44 that, etc.)"))
|
m@24
|
45 (defgeneric meredith-chromatic-pitch-number (pitch-designator)
|
d@72
|
46 (:documentation "Takes a pitch-designator (usually a pitched
|
d@72
|
47 event) and returns an integer representing the chromatic pitch
|
d@72
|
48 designated (39=middle C, 27 the C below that, etc.)")
|
d@72
|
49 ;; David Meredith's PhD and ps13 code. FIXME: What is the legal
|
d@72
|
50 ;; range of this?
|
m@24
|
51 (:method (p) (- (midi-pitch-number p) 21)))
|
m@24
|
52 (defgeneric pitch-class (pitch-designator)
|
d@72
|
53 (:documentation "Takes a pitch-designator (usually a pitched
|
d@72
|
54 event) and returns an integer between 0 and 12 representing
|
d@72
|
55 the octave-independant pitch, with c=0, c#=1, etc.")
|
m@24
|
56 (:method (p) (mod (midi-pitch-number p) 12)))
|
m@24
|
57 (defgeneric span (pitch-interval-designator))
|
m@24
|
58
|
m@24
|
59 ;; time
|
m@24
|
60
|
m@24
|
61 (defgeneric duration (period-designator))
|
m@24
|
62 (defgeneric (setf duration) (value period-designator))
|
m@24
|
63 (defgeneric timepoint (moment-designator))
|
m@24
|
64 (defgeneric (setf timepoint) (value moment-designator))
|
m@24
|
65 (defgeneric cut-off (anchored-period-designator) ; name?
|
d@72
|
66 (:documentation "Returns a <moment> representing the point at
|
d@72
|
67 which the anchored period has ended.")
|
m@24
|
68 (:method (apd) (time+ (moment apd) (floating-period apd))))
|
m@24
|
69
|
m@24
|
70 ;; others
|
m@24
|
71
|
m@24
|
72 ;; I've given the time-sig accessors general names because it allows
|
m@24
|
73 ;; for symbols in time-signatures as well as numbers - numerator is an
|
m@24
|
74 ;; odd accessor if the time sig is C (even in common practice) but
|
m@24
|
75 ;; it's meaning is clear. beat-units-per-bar is clearer, though, I
|
m@24
|
76 ;; think.
|
m@24
|
77
|
m@24
|
78 (defgeneric beat-units-per-bar (time-signature))
|
m@24
|
79 (defgeneric time-signature-numerator (time-signature)
|
m@24
|
80 (:method (ts) (beat-units-per-bar ts)))
|
m@24
|
81 (defgeneric beat-units (time-signature))
|
m@24
|
82 (defgeneric time-signature-denominator (time-signature)
|
m@24
|
83 (:method (ts) (beat-units ts)))
|
d@33
|
84 (defgeneric tactus-duration (time-signature)
|
d@33
|
85 ;; basic, but should do?
|
d@33
|
86 (:method (ts)
|
d@33
|
87 (cond
|
d@33
|
88 ((and (not (= (beat-units-per-bar ts) 3))
|
d@33
|
89 (= (rem (beat-units-per-bar ts) 3) 0))
|
d@33
|
90 ;; compound time
|
d@33
|
91 (* (/ 4 (beat-units ts))
|
d@33
|
92 3))
|
d@33
|
93 (t (/ 4 (beat-units ts))))))
|
m@24
|
94
|
m@24
|
95 (defgeneric key-signature-sharps (key-signature))
|
m@45
|
96 (defgeneric key-signature-mode (ks))
|
m@24
|
97
|
m@24
|
98 (defgeneric bpm (tempo)) ;; in bpm
|
m@24
|
99 (defgeneric microseconds-per-crotchet (tempo)
|
m@24
|
100 ;; As used (when rounded) in MIDI
|
m@24
|
101 (:method (tp) (/ 60000000 (bpm tp))))
|
m@24
|
102
|
m@24
|
103 ;;; Coerce-type accessors
|
m@24
|
104
|
m@24
|
105 ;; Should I be including these default methods? Should the accessors
|
m@24
|
106 ;; be direct slot accessors or the generics I'm using? Should we
|
m@24
|
107 ;; return the object itself if it already is in the target class?
|
m@24
|
108
|
m@24
|
109 (defgeneric anchored-period (anchored-period-designator)
|
m@24
|
110 (:method (apd) (make-anchored-period (onset apd) (duration apd))))
|
m@24
|
111
|
m@24
|
112 (defgeneric floating-period (period-designator)
|
m@24
|
113 (:method (pd) (make-floating-period (duration pd))))
|
m@24
|
114
|
m@24
|
115 (defgeneric moment (moment-designator)
|
m@24
|
116 (:method (md) (make-moment (timepoint md))))
|
m@24
|
117
|
m@24
|
118 (defgeneric onset (anchored-period-designator)
|
m@24
|
119 (:method (apd) (moment apd)))
|
m@24
|
120 (defgeneric (setf onset) (value anchored-period-designator))
|
m@24
|
121
|
m@24
|
122 ;;; Time Protocol (or moments?)
|
m@24
|
123
|
m@24
|
124 ;; negative times/durations -> ERROR?
|
m@24
|
125
|
m@24
|
126 ;; time+: <time> <duration> -> <time>
|
m@24
|
127 ;; <duration> <time> -> <time> (same as previous?)
|
m@24
|
128 ;; <duration> <duration> -> <duration> (or a distinct duration+?)
|
m@24
|
129 ;; <time> <time> -> ERROR?
|
m@24
|
130 ;;
|
m@24
|
131 ;; time-: <time> <time> -> <duration>
|
m@24
|
132 ;; <time> <duration> -> <time>
|
m@24
|
133 ;; <duration> <duration> -> <duration> (or a distinct duration-?)
|
m@24
|
134 ;; <duration> <time> -> ERROR?
|
m@24
|
135 ;; <anchored> <anchored> -> (time- (moment o1) (moment o2)) ? or error?
|
m@24
|
136
|
m@24
|
137 (defgeneric time+ (object1 object2))
|
m@24
|
138 (defgeneric time- (object1 object2))
|
m@24
|
139
|
m@24
|
140 (defgeneric time> (object1 object2))
|
m@24
|
141 (defgeneric time< (object1 object2)
|
m@24
|
142 (:method (o1 o2) (time> o2 o1)))
|
m@24
|
143 (defgeneric time= (object1 object2))
|
m@24
|
144 (defgeneric time>= (object1 object2)
|
m@24
|
145 (:method (o1 o2) (or (time> o1 o2) (time= o1 o2))))
|
m@24
|
146 (defgeneric time<= (object1 object2)
|
m@24
|
147 (:method (o1 o2) (or (time< o1 o2) (time= o1 o2))))
|
m@24
|
148 (defgeneric time/= (object1 object2)
|
m@24
|
149 (:method (o1 o2) (not (time= o1 o2))))
|
m@24
|
150
|
m@24
|
151 ;;; Duration protocol
|
m@24
|
152
|
m@24
|
153 (defgeneric duration> (object1 object2))
|
m@24
|
154 (defgeneric duration< (object1 object2)
|
m@24
|
155 (:method (o1 o2) (duration> o2 o1)))
|
m@24
|
156 (defgeneric duration= (object1 object2))
|
m@24
|
157 (defgeneric duration>= (object1 object2)
|
m@24
|
158 (:method (o1 o2) (or (duration> o1 o2) (duration= o1 o2))))
|
m@24
|
159 (defgeneric duration<= (object1 object2)
|
m@24
|
160 (:method (o1 o2) (or (duration< o1 o2) (duration= o1 o2))))
|
m@24
|
161 (defgeneric duration/= (object1 object2)
|
m@24
|
162 (:method (o1 o2) (not (duration= o1 o2))))
|
m@24
|
163
|
m@24
|
164 ;; for linear scaling:
|
m@24
|
165 (defgeneric duration* (object1 object2))
|
m@24
|
166 (defgeneric duration/ (object1 number))
|
m@24
|
167
|
m@24
|
168 ;;; Pitch protocol
|
m@24
|
169
|
m@24
|
170 ;; pitch+: <pitch> <pitch> -> ERROR
|
m@24
|
171 ;; <pitch> <interval> -> <pitch>
|
m@24
|
172 ;; <interval> <pitch> -> <pitch> (same as previous?)
|
m@24
|
173 ;; <interval> <interval> -> <interval> (or a distinct interval+?)
|
m@24
|
174 ;;
|
m@24
|
175 ;; pitch-: <pitch> <pitch> -> <interval>
|
m@24
|
176 ;; <pitch> <interval> -> <pitch>
|
m@24
|
177 ;; <interval> <interval> -> <interval>
|
m@24
|
178 ;; <interval> <pitch> -> ERROR
|
m@24
|
179
|
m@24
|
180 (defgeneric pitch+ (object1 object2))
|
m@24
|
181 (defgeneric pitch- (object1 object2))
|
m@24
|
182
|
m@24
|
183 (defgeneric pitch> (object1 object2))
|
m@24
|
184 (defgeneric pitch< (object1 object2)
|
m@24
|
185 (:method (o1 o2) (pitch> o2 o1)))
|
m@24
|
186 (defgeneric pitch= (object1 object2))
|
m@24
|
187 (defgeneric pitch>= (object1 object2)
|
m@24
|
188 (:method (o1 o2) (or (pitch> o1 o2) (pitch= o1 o2))))
|
m@24
|
189 (defgeneric pitch<= (object1 object2)
|
m@24
|
190 (:method (o1 o2) (or (pitch< o1 o2) (pitch= o1 o2))))
|
m@24
|
191 (defgeneric pitch/= (object1 object2)
|
m@24
|
192 (:method (o1 o2) (not (pitch= o1 o2))))
|
m@24
|
193
|
m@24
|
194 ;;; Interval protocol (emphasise _pitch_ not _time_ interval?)
|
m@24
|
195
|
m@24
|
196 (defgeneric interval> (object1 object2))
|
m@24
|
197 (defgeneric interval< (object1 object2)
|
m@24
|
198 (:method (o1 o2) (interval> o2 o1)))
|
m@24
|
199 (defgeneric interval= (object1 object2))
|
m@24
|
200 (defgeneric interval>= (object1 object2)
|
m@24
|
201 (:method (o1 o2) (or (interval> o1 o2) (interval= o1 o2))))
|
m@24
|
202 (defgeneric interval<= (object1 object2)
|
m@24
|
203 (:method (o1 o2) (or (interval< o1 o2) (interval= o1 o2))))
|
m@24
|
204 (defgeneric interval/= (object1 object2)
|
m@24
|
205 (:method (o1 o2) (not (interval= o1 o2))))
|
m@24
|
206
|
m@24
|
207 ;;; Allen's (1984) interval relations
|
m@24
|
208 ;;; . equals already defined as INTERVAL= above
|
m@24
|
209 ;;; . inverses ommitted for now (just use CL:NOT)
|
m@24
|
210 ;;; . can all be defined in terms of MEETS (apparently)
|
m@24
|
211
|
m@24
|
212 (defgeneric meets (object1 object2))
|
m@24
|
213 (defgeneric before (object1 object2))
|
m@24
|
214 (defgeneric overlaps (object1 object2))
|
m@24
|
215 (defgeneric during (object1 object2))
|
m@24
|
216 (defgeneric starts (object1 object2))
|
m@24
|
217 (defgeneric ends (object1 object2))
|
m@24
|
218
|
m@24
|
219 ;;; and extensions thereof ...
|
m@24
|
220
|
m@24
|
221 (defgeneric subinterval (object1 object2)
|
m@24
|
222 (:method (o1 o2) (or (starts o1 o2) (during o1 o2) (ends o1 o2))))
|
m@24
|
223
|
m@24
|
224 (defgeneric disjoint (object1 object2)
|
m@24
|
225 (:method (o1 o2)
|
m@24
|
226 (or (before o1 o2) (meets o1 o2) (meets o2 o1) (before o2 o1))))
|
m@24
|
227
|
m@24
|
228 ;;; More time-based functions
|
d@33
|
229
|
d@33
|
230 (defgeneric period= (object1 object2)
|
d@33
|
231 (:method (x y) nil))
|
d@33
|
232
|
d@33
|
233 (defgeneric find-overlapping (anchored-period sequence)
|
d@33
|
234 ;; Returns all members of a sequence of period signifiers that overlap
|
d@33
|
235 ;; with the supplied period
|
d@33
|
236 (:method (ap s) (remove-if #'(lambda (x) (amuse:disjoint ap x)) s)))
|
d@33
|
237
|
m@24
|
238 ;; Return the anchored-period representing the intersection of two
|
m@24
|
239 ;; anchored-period-specifiers.
|
m@24
|
240 (defgeneric period-intersection (anchored-period-specifier1
|
m@24
|
241 anchored-period-specifier2))
|
m@24
|
242
|
m@24
|
243 (defgeneric inter-onset-interval (moment-designator1 moment-designator2)
|
m@24
|
244 (:method (md1 md2) (time- (moment md2) (moment md1))))
|
m@24
|
245
|
m@24
|
246
|
m@24
|
247 ;;; Time Signature
|
m@24
|
248
|
d@33
|
249 (defgeneric get-applicable-time-signatures (anchored-period composition)
|
d@33
|
250 (:method (ap c) (find-overlapping ap (time-signatures c))))
|
m@24
|
251
|
m@67
|
252 (defgeneric time-signature-equal (ts1 ts2))
|
m@67
|
253
|
m@24
|
254 ;;; Tempo
|
m@24
|
255
|
d@33
|
256 (defgeneric get-applicable-tempi (anchored-period composition)
|
d@33
|
257 (:method (ap c) (find-overlapping ap (tempi c))))
|
m@24
|
258
|
m@67
|
259 (defgeneric tempo-equal (t1 t2))
|
m@67
|
260
|
m@24
|
261 ;;; Tonality (Key Signature / Mode)
|
m@24
|
262
|
m@24
|
263 (defgeneric get-applicable-key-signatures (object1 object2))
|
m@24
|
264
|
m@67
|
265 (defgeneric key-signature-equal (ks1 ks2))
|
m@67
|
266
|
m@24
|
267 ;;; Dynamics
|
m@24
|
268 ;;; Voice
|
m@24
|
269 ;;; Boundary Strength (phrasing)
|
m@24
|
270
|