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