Mercurial > hg > amuse
comparison base/generics.lisp @ 136:fd85f52d9f9d
Class revolution
* PITCH-DESIGNATOR -> PITCH (PITCH removed)
* MOMENT-DESIGNATOR -> MOMENT , MOMENT -> STANDARD-MOMENT
* PERIOD-DESIGNATOR -> PERIOD , PERIOD -> STANDARD-PERIOD
* ANCHORED-PERIOD-DESIGNATOR -> ANCHORED-PERIOD , ANCHORED-PERIOD -> STANDARD-ANCHORED-PERIOD
* FLOATING-PERIOD removed
* TIME-SIGNATURE-DESIGNATOR -> TIME-SIGNATURE & TIME-SIGNATURE-PERIOD
* TIME-SIGNATURE -> STANDARD-TIME-SIGNATURE & STANDARD-TIME-SIGNATURE-PERIOD
* KEY-SIGNATURE-DESIGNATOR -> KEY-SIGNATURE (& ...-PERIOD)
* KEY-SIGNATURE -> STANDARD-KEY-SIGNATURE (& ...-PERIOD)
* TEMPO now abstract (& TEMPO-PERIOD)
* STANDARD-TEMPO AND STANDARD-TEMPO-PERIOD
* COMPOSITION, CONSTITUENT & TIME-ORDERED-CONSTITUENT all have STANDARD- forms
make-x methods and specialisers changes appropriately
darcs-hash:20070831142943-f76cc-7be0d08963de06d87b36e4922076287d565c7ee2.gz
author | David Lewis <d.lewis@gold.ac.uk> |
---|---|
date | Fri, 31 Aug 2007 15:29:43 +0100 |
parents | 5e362d998f29 |
children | ebfe054eea1c |
comparison
equal
deleted
inserted
replaced
135:188fe5ea837f | 136:fd85f52d9f9d |
---|---|
39 | 39 |
40 ;; pitch-based | 40 ;; pitch-based |
41 | 41 |
42 (defgeneric pitch (object &key kind)) ; ? Maybe this returns the pitch | 42 (defgeneric pitch (object &key kind)) ; ? Maybe this returns the pitch |
43 ; in its ur form? | 43 ; in its ur form? |
44 (defgeneric chromatic-pitch (pitch-designator)) | 44 (defgeneric chromatic-pitch (pitch)) |
45 (defgeneric diatonic-pitch (pitch-designator)) | 45 (defgeneric diatonic-pitch (pitch)) |
46 (defgeneric frequency (object)) ;? | 46 (defgeneric frequency (object)) ;? |
47 | 47 |
48 (defgeneric octave (pitch-designator) | 48 (defgeneric octave (pitch) |
49 (:documentation "Return an integer representing the octave of | 49 (:documentation "Return an integer representing the octave of |
50 pitch-designator where middle c is defined to be the lowest pitch in | 50 pitch where middle c is defined to be the lowest pitch in |
51 octave 4.")) | 51 octave 4.")) |
52 | 52 |
53 (defgeneric diatonic-pitch-octave (pitch-designator) | 53 (defgeneric diatonic-pitch-octave (pitch) |
54 (:documentation "Return an integer representing the diatonic octave | 54 (:documentation "Return an integer representing the diatonic octave |
55 of PITCH-DESIGNATOR.")) | 55 of pitch.")) |
56 | 56 |
57 (defgeneric diatonic-pitch-accidental (pitch-designator) | 57 (defgeneric diatonic-pitch-accidental (pitch) |
58 (:documentation "Return an integer representing the inflection of a | 58 (:documentation "Return an integer representing the inflection of a |
59 diatonic pitch where where negative values indicate numbers of flats, | 59 diatonic pitch where where negative values indicate numbers of flats, |
60 0 indicates natural and positive values indicate numbers of sharps.")) | 60 0 indicates natural and positive values indicate numbers of sharps.")) |
61 | 61 |
62 (defgeneric diatonic-pitch-mp (pitch-designator) | 62 (defgeneric diatonic-pitch-mp (pitch) |
63 (:documentation "Return an integer representing the morphetic pitch | 63 (:documentation "Return an integer representing the morphetic pitch |
64 \(in MIPS terms) of a diatonic pitch.")) | 64 \(in MIPS terms) of a diatonic pitch.")) |
65 (defgeneric diatonic-pitch-cp (pitch-designator) | 65 (defgeneric diatonic-pitch-cp (pitch) |
66 (:documentation "Return an integer representing the chromatic pitch | 66 (:documentation "Return an integer representing the chromatic pitch |
67 \(in MIPS terms) of a diatonic pitch.")) | 67 \(in MIPS terms) of a diatonic pitch.")) |
68 | 68 |
69 (defgeneric middle-c (pitch-designator) | 69 (defgeneric middle-c (pitch) |
70 (:documentation "Returns the value of middle C in the particular | 70 (:documentation "Returns the value of middle C in the particular |
71 representation of pitch used by PITCH-DESIGNATOR.")) | 71 representation of pitch used by PITCH.")) |
72 (defgeneric midi-pitch-number (pitch-designator) | 72 (defgeneric midi-pitch-number (pitch) |
73 (:documentation "Takes a pitch-designator (usually a pitched | 73 (:documentation "Takes a pitch (usually a pitched event) and |
74 event) and returns an integer between 0 and 127 representing | 74 returns an integer between 0 and 127 representing the chromatic |
75 the chromatic pitch designated (60=middle C, 48 the C below | 75 pitch represented (60=middle C, 48 the C below that, etc.)")) |
76 that, etc.)")) | 76 (defgeneric asa-pitch-string (pitch) |
77 (defgeneric asa-pitch-string (pitch-designator) | |
78 (:documentation "Returns a string representing the designated ASA | 77 (:documentation "Returns a string representing the designated ASA |
79 pitch name which has three parts: a letter name in the set | 78 pitch name which has three parts: a letter name in the set |
80 {A,B,C,D,E,F,G}, an inflection in the set {n,f,s,ff,ss,fff,sss,...} | 79 {A,B,C,D,E,F,G}, an inflection in the set {n,f,s,ff,ss,fff,sss,...} |
81 and an octave number. E.g., Cn4 = Middle C.")) | 80 and an octave number. E.g., Cn4 = Middle C.")) |
82 (defgeneric asa-interval-string (pitch-designator) | 81 (defgeneric asa-interval-string (pitch) |
83 (:documentation "Returns a string representing the designated ASA | 82 (:documentation "Returns a string representing the designated ASA |
84 interval name which has two or three parts: a direction in the set | 83 interval name which has two or three parts: a direction in the set |
85 {r,f} (absent for unisons/primes), a type in the set | 84 {r,f} (absent for unisons/primes), a type in the set |
86 {p,ma,mi,a,d,aa,dd,aaa,ddd,...}, and a size number. E.g. rma2 = | 85 {p,ma,mi,a,d,aa,dd,aaa,ddd,...}, and a size number. E.g. rma2 = |
87 rising major second.")) | 86 rising major second.")) |
88 (defgeneric diatonic-pitch-name (pitch-designator) | 87 (defgeneric diatonic-pitch-name (pitch) |
89 (:documentation "Returns a char in the set | 88 (:documentation "Returns a char in the set |
90 {#\A,#\B,#\C,#\D,#\E,#\F,#\G}, representing the pitch name of | 89 {#\A,#\B,#\C,#\D,#\E,#\F,#\G}, representing the pitch name of |
91 PITCH-DESIGNATOR.")) | 90 PITCH.")) |
92 (defgeneric pitch-class (pitch-designator) | 91 (defgeneric pitch-class (pitch) |
93 (:documentation "Takes a pitch-designator (usually a pitched | 92 (:documentation "Takes a pitch (usually a pitched event) and |
94 event) and returns an integer between 0 and 12 representing | 93 returns an integer between 0 and 12 representing the |
95 the octave-independant pitch, with c=0, c#=1, etc.") | 94 octave-independant pitch, with c=0, c#=1, etc.") |
96 (:method (p) (mod (midi-pitch-number p) 12))) | 95 (:method (p) (mod (midi-pitch-number p) 12))) |
97 (defgeneric span (pitch-interval-designator)) | 96 (defgeneric span (pitch-interval)) |
98 | 97 |
99 ;; time | 98 ;; time |
100 | 99 |
101 (defgeneric duration (period-designator) | 100 (defgeneric duration (period) |
102 (:documentation "Returns a value. Probably should only apply do | 101 (:documentation "Returns a real. Probably should only apply do |
103 periods (rather than designators?)")) | 102 standard-periods (rather than periods? or should it return |
104 (defgeneric (setf duration) (value period-designator) | 103 something other than a value in other cases)")) |
105 (:documentation "As with duration, should probably work only | 104 (defgeneric (setf duration) (value period) |
106 with periods")) | 105 (:documentation "As with duration, perhaps this should work only |
107 (defgeneric timepoint (moment-designator) | 106 with standard-periods")) |
108 (:documentation "Returns a value for a moment. Does this make | 107 (defgeneric timepoint (moment) |
109 any sense on a designator?")) | 108 (:documentation "Returns a number for a moment. Does this make |
110 (defgeneric (setf timepoint) (value moment-designator) | 109 any sense on an abstrace class? Should it just apply to |
111 (:documentation "Sets timepoint. What does this mean for a | 110 standard-moment?")) |
112 designator?")) | 111 (defgeneric (setf timepoint) (value moment) |
113 (defgeneric cut-off (anchored-period-designator) ; name? | 112 (:documentation "Sets timepoint. What does this mean for an |
113 abstract class? Should it just apply to standard-moment")) | |
114 (defgeneric cut-off (anchored-period) ; name? | |
114 (:documentation "Returns a <moment> representing the point at | 115 (:documentation "Returns a <moment> representing the point at |
115 which the anchored period has ended. By default, is calculated | 116 which the anchored period has ended. By default, is calculated |
116 as the result of running time+ on the onset and period of the | 117 as the result of running time+ on the onset and period of the |
117 object.") | 118 object.") |
118 (:method (apd) (time+ (moment apd) (floating-period apd)))) | 119 (:method (apd) (time+ (moment apd) (period apd)))) |
119 (defgeneric crotchet (object) | 120 (defgeneric crotchet (object) |
120 (:documentation "Returns a period, the duration of which represents | 121 (:documentation "Returns a period, the duration of which represents |
121 a crotchet in the time representation used by object.")) | 122 a crotchet in the time representation used by object.")) |
122 | 123 |
123 ;; others | 124 ;; others |
124 | 125 |
178 | 179 |
179 ;; Should I be including these default methods? Should the accessors | 180 ;; Should I be including these default methods? Should the accessors |
180 ;; be direct slot accessors or the generics I'm using? Should we | 181 ;; be direct slot accessors or the generics I'm using? Should we |
181 ;; return the object itself if it already is in the target class? | 182 ;; return the object itself if it already is in the target class? |
182 | 183 |
183 (defgeneric anchored-period (anchored-period-designator) | 184 (defgeneric anchored-period (anchored-period) |
184 (:method (apd) (make-anchored-period (onset apd) (duration apd))) | 185 (:method (apd) (make-anchored-period (onset apd) (duration apd))) |
185 (:documentation "Coerce any anchored period to a plain anchored | 186 (:documentation "Coerce any anchored period to a plain anchored |
186 period")) | 187 period")) |
187 | 188 |
188 (defgeneric floating-period (period-designator) | 189 (defgeneric period (period) |
189 (:method (pd) (make-floating-period (duration pd))) | 190 (:method (pd) (make-period (duration pd))) |
190 (:documentation "Coerce any period to a floating period")) | 191 (:documentation "Coerce any period to a floating period")) |
191 | 192 |
192 (defgeneric moment (moment-designator) | 193 (defgeneric moment (moment) |
193 (:method (md) (make-moment (timepoint md))) | 194 (:method (md) (make-moment (timepoint md))) |
194 (:documentation "Coerce any moment(-designator?), including an | 195 (:documentation "Coerce any moment, including an |
195 anchored-period to a moment")) | 196 anchored-period to a moment")) |
196 | 197 |
197 (defgeneric onset (anchored-period-designator) | 198 (defgeneric onset (anchored-period) |
198 (:method (apd) (moment apd)) | 199 (:method (apd) (moment apd)) |
199 (:documentation "Return a moment for the start of an anchored period")) | 200 (:documentation "Return a moment for the start of an anchored period")) |
200 (defgeneric (setf onset) (value anchored-period-designator)) | 201 (defgeneric (setf onset) (value anchored-period)) |
201 | 202 |
202 ;;; Time Protocol (or moments?) | 203 ;;; Time Protocol (or moments?) |
203 | 204 |
204 ;; negative times/durations -> ERROR? | 205 ;; negative times/durations -> ERROR? |
205 | 206 |
213 ;; <duration> <duration> -> <duration> (or a distinct duration-?) | 214 ;; <duration> <duration> -> <duration> (or a distinct duration-?) |
214 ;; <duration> <time> -> ERROR? | 215 ;; <duration> <time> -> ERROR? |
215 ;; <anchored> <anchored> -> (time- (moment o1) (moment o2)) ? or error? | 216 ;; <anchored> <anchored> -> (time- (moment o1) (moment o2)) ? or error? |
216 | 217 |
217 (defgeneric time+ (object1 object2) | 218 (defgeneric time+ (object1 object2) |
218 (:documentation "Addition for time designators")) | 219 (:documentation "Addition for time objects")) |
219 (defgeneric time- (object1 object2) | 220 (defgeneric time- (object1 object2) |
220 (:documentation "Subtraction for time designators")) | 221 (:documentation "Subtraction for time objects")) |
221 | 222 |
222 (defgeneric time> (object1 object2) | 223 (defgeneric time> (object1 object2) |
223 (:documentation "> operator for moment designators")) | 224 (:documentation "> operator for moments")) |
224 (defgeneric time< (object1 object2) | 225 (defgeneric time< (object1 object2) |
225 (:documentation "< operator for moment designators") | 226 (:documentation "< operator for moments") |
226 (:method (o1 o2) (time> o2 o1))) | 227 (:method (o1 o2) (time> o2 o1))) |
227 (defgeneric time= (object1 object2) | 228 (defgeneric time= (object1 object2) |
228 (:documentation "= operator for moment designators")) | 229 (:documentation "= operator for moments")) |
229 (defgeneric time>= (object1 object2) | 230 (defgeneric time>= (object1 object2) |
230 (:documentation ">= operator for moment designators") | 231 (:documentation ">= operator for moments") |
231 (:method (o1 o2) (or (time> o1 o2) (time= o1 o2)))) | 232 (:method (o1 o2) (or (time> o1 o2) (time= o1 o2)))) |
232 (defgeneric time<= (object1 object2) | 233 (defgeneric time<= (object1 object2) |
233 (:documentation "<= operator for moment designators") | 234 (:documentation "<= operator for moments") |
234 (:method (o1 o2) (or (time< o1 o2) (time= o1 o2)))) | 235 (:method (o1 o2) (or (time< o1 o2) (time= o1 o2)))) |
235 (defgeneric time/= (object1 object2) | 236 (defgeneric time/= (object1 object2) |
236 (:documentation "not = operator for moment designators") | 237 (:documentation "not = operator for moments") |
237 (:method (o1 o2) (not (time= o1 o2)))) | 238 (:method (o1 o2) (not (time= o1 o2)))) |
238 | 239 |
239 ;;; Duration protocol | 240 ;;; Duration protocol |
240 | 241 |
241 (defgeneric duration> (object1 object2) | 242 (defgeneric duration> (object1 object2) |
242 (:documentation "> operator for period designators")) | 243 (:documentation "> operator for periods")) |
243 (defgeneric duration< (object1 object2) | 244 (defgeneric duration< (object1 object2) |
244 (:documentation "< operator for period designators") | 245 (:documentation "< operator for periods") |
245 (:method (o1 o2) (duration> o2 o1))) | 246 (:method (o1 o2) (duration> o2 o1))) |
246 (defgeneric duration= (object1 object2) | 247 (defgeneric duration= (object1 object2) |
247 (:documentation "= operator for period designators")) | 248 (:documentation "= operator for periods")) |
248 (defgeneric duration>= (object1 object2) | 249 (defgeneric duration>= (object1 object2) |
249 (:documentation ">= operator for period designators") | 250 (:documentation ">= operator for periods") |
250 (:method (o1 o2) (or (duration> o1 o2) (duration= o1 o2)))) | 251 (:method (o1 o2) (or (duration> o1 o2) (duration= o1 o2)))) |
251 (defgeneric duration<= (object1 object2) | 252 (defgeneric duration<= (object1 object2) |
252 (:documentation "<= operator for period designators") | 253 (:documentation "<= operator for periods") |
253 (:method (o1 o2) (or (duration< o1 o2) (duration= o1 o2)))) | 254 (:method (o1 o2) (or (duration< o1 o2) (duration= o1 o2)))) |
254 (defgeneric duration/= (object1 object2) | 255 (defgeneric duration/= (object1 object2) |
255 (:documentation "not = operator for period designators") | 256 (:documentation "not = operator for periods") |
256 (:method (o1 o2) (not (duration= o1 o2)))) | 257 (:method (o1 o2) (not (duration= o1 o2)))) |
257 | 258 |
258 ;; for linear scaling: | 259 ;; for linear scaling: |
259 (defgeneric duration* (object1 object2) | 260 (defgeneric duration* (object1 object2) |
260 (:documentation "Multiplication operator for period | 261 (:documentation "Multiplication operator for |
261 designators. Intuitively, this makes sense, but it may cause us | 262 periods. Intuitively, this makes sense, but it may cause us |
262 trouble with some implementations in the future.")) | 263 trouble with some implementations in the future.")) |
263 (defgeneric duration/ (object1 number) | 264 (defgeneric duration/ (object1 number) |
264 (:documentation "Division operator for period designators. This | 265 (:documentation "Division operator for periods. This may turn |
265 may turn out not to mean much. Division is probably useful, but | 266 out not to mean much. Division is probably useful, but we may |
266 we may need to define what we mean with care.")) | 267 need to define what we mean with care.")) |
267 | 268 |
268 ;;; Pitch protocol | 269 ;;; Pitch protocol |
269 | 270 |
270 ;; pitch+: <pitch> <pitch> -> ERROR | 271 ;; pitch+: <pitch> <pitch> -> ERROR |
271 ;; <pitch> <interval> -> <pitch> | 272 ;; <pitch> <interval> -> <pitch> |
334 ;; Returns all members of a sequence of period signifiers that overlap | 335 ;; Returns all members of a sequence of period signifiers that overlap |
335 ;; with the supplied period | 336 ;; with the supplied period |
336 (:method (ap s) (remove-if #'(lambda (x) (amuse:disjoint ap x)) s))) | 337 (:method (ap s) (remove-if #'(lambda (x) (amuse:disjoint ap x)) s))) |
337 | 338 |
338 ;; Return the anchored-period representing the intersection of two | 339 ;; Return the anchored-period representing the intersection of two |
339 ;; anchored-period-specifiers. | 340 ;; anchored-period. |
340 (defgeneric period-intersection (anchored-period-specifier1 | 341 (defgeneric period-intersection (anchored-period1 |
341 anchored-period-specifier2)) | 342 anchored-period2)) |
342 | 343 |
343 (defgeneric inter-onset-interval (moment-designator1 moment-designator2) | 344 (defgeneric inter-onset-interval (moment1 moment2) |
344 (:method (md1 md2) (time- (moment md2) (moment md1)))) | 345 (:method (moment1 moment2) (time- (moment moment2) (moment moment1)))) |
345 | 346 |
346 | 347 |
347 ;;; Time Signature | 348 ;;; Time Signature |
348 | 349 |
349 (defgeneric get-applicable-time-signatures (anchored-period composition) | 350 (defgeneric get-applicable-time-signatures (anchored-period composition) |
350 (:method (ap c) (find-overlapping ap (time-signatures c))) | 351 (:method (ap c) (find-overlapping ap (time-signatures c))) |
351 (:documentation "Return a list of time-signatures that are | 352 (:documentation "Return a list of TIME-SIGNATURE-PERIODs that are |
352 relevant to <anchored-period>. The period may contain | 353 relevant to <anchored-period>. The period may contain |
353 information such as staff position and voicing, and the method | 354 information such as staff position and voicing, and the method |
354 may use this to filter its response")) | 355 may use this to filter its response")) |
355 | 356 |
356 (defgeneric time-signature-equal (ts1 ts2) | 357 (defgeneric time-signature-equal (ts1 ts2) |
359 | 360 |
360 ;;; Tempo | 361 ;;; Tempo |
361 | 362 |
362 (defgeneric get-applicable-tempi (anchored-period composition) | 363 (defgeneric get-applicable-tempi (anchored-period composition) |
363 (:method (ap c) (find-overlapping ap (tempi c))) | 364 (:method (ap c) (find-overlapping ap (tempi c))) |
364 (:documentation "Return a list of tempi that are relevant to | 365 (:documentation "Return a list of TEMPO-PERIODs that are |
365 <anchored-period>. The period may contain information such as | 366 relevant to <anchored-period>. The period may contain |
366 staff position and voicing, and the method may use this to | 367 information such as staff position and voicing, and the method |
367 filter its response")) | 368 may use this to filter its response")) |
368 | 369 |
369 (defgeneric tempo-equal (t1 t2) | 370 (defgeneric tempo-equal (t1 t2) |
370 (:documentation "Comparison operator. The definition of | 371 (:documentation "Comparison operator. The definition of |
371 equality is left open for implementers")) | 372 equality is left open for implementers")) |
372 | 373 |
373 ;;; Tonality (Key Signature / Mode) | 374 ;;; Tonality (Key Signature / Mode) |
374 | 375 |
375 (defgeneric get-applicable-key-signatures (object1 object2) | 376 (defgeneric get-applicable-key-signatures (object1 object2) |
376 (:documentation "Return a list of key-signatures that are | 377 (:documentation "Return a list of KEY-SIGNATURE-PERIODs that are |
377 relevant to <anchored-period>. The period may contain | 378 relevant to <anchored-period>. The period may contain |
378 information such as staff position and voicing, and the method | 379 information such as staff position and voicing, and the method |
379 may use this to filter its response")) | 380 may use this to filter its response")) |
380 | 381 |
381 (defgeneric key-signature-equal (ks1 ks2) | 382 (defgeneric key-signature-equal (ks1 ks2) |
382 (:documentation "Comparison operator. The definition of | 383 (:documentation "Comparison operator. The definition of |
383 equality is left open to implementers")) | 384 equality is left open to implementers")) |
384 | 385 |
386 ;;; Some generic constructors - are these useful? (DL 31/8/07) | |
387 (defgeneric make-moment (value) | |
388 (:documentation "Returns MOMENT of subclass appropriate to the | |
389 class of value. Probably guessed.")) | |
390 (defgeneric make-period (value) | |
391 (:documentation "Returns PERIOD of subclass appropriate to the | |
392 class of value. Probably guessed.")) | |
393 (defgeneric make-anchored-period (start-value duration-value) | |
394 (:documentation "Returns ANCHORED-PERIOD of subclass | |
395 appropriate to the class of value. Probably guessed.")) | |
396 | |
397 | |
385 ;;; Dynamics | 398 ;;; Dynamics |
386 ;;; Voice | 399 ;;; Voice |
387 ;;; Boundary Strength (phrasing) | 400 ;;; Boundary Strength (phrasing) |