Mercurial > hg > amuse
comparison base/generics.lisp @ 123:f57ab0e109fb
More docs
darcs-hash:20070730133825-f76cc-ca46fd2ec43676a919ecf67efa80a7881013f405.gz
author | David Lewis <d.lewis@gold.ac.uk> |
---|---|
date | Mon, 30 Jul 2007 14:38:25 +0100 |
parents | 4198b52e612b |
children | 5e362d998f29 |
comparison
equal
deleted
inserted
replaced
122:997bed70ef28 | 123:f57ab0e109fb |
---|---|
1 (cl:in-package #:amuse) | 1 (cl:in-package #:amuse) |
2 | 2 |
3 ;;; Pulling compositions from the database | 3 ;;; Pulling compositions from the database |
4 | 4 |
5 (defgeneric get-composition (identifier)) | 5 (defgeneric get-composition (identifier) |
6 (:documentation "Returns a composition of type dependant on | |
7 identifier")) | |
6 | 8 |
7 (defgeneric monody (object) | 9 (defgeneric monody (object) |
8 (:documentation "Returns a monody.")) | 10 (:documentation "Returns a monody.")) |
9 (defgeneric ensure-monody (object) | 11 (defgeneric ensure-monody (object) |
10 (:documentation "Returns a generalised boolean.")) | 12 (:documentation "Returns a generalised boolean.")) |
94 (:method (p) (mod (midi-pitch-number p) 12))) | 96 (:method (p) (mod (midi-pitch-number p) 12))) |
95 (defgeneric span (pitch-interval-designator)) | 97 (defgeneric span (pitch-interval-designator)) |
96 | 98 |
97 ;; time | 99 ;; time |
98 | 100 |
99 (defgeneric duration (period-designator)) | 101 (defgeneric duration (period-designator) |
100 (defgeneric (setf duration) (value period-designator)) | 102 (:documentation "Returns a value. Probably should only apply do |
101 (defgeneric timepoint (moment-designator)) | 103 periods (rather than designators?)")) |
102 (defgeneric (setf timepoint) (value moment-designator)) | 104 (defgeneric (setf duration) (value period-designator) |
105 (:documentation "As with duration, should probably work only | |
106 with periods")) | |
107 (defgeneric timepoint (moment-designator) | |
108 (:documentation "Returns a value for a moment. Does this make | |
109 any sense on a designator?")) | |
110 (defgeneric (setf timepoint) (value moment-designator) | |
111 (:documentation "Sets timepoint. What does this mean for a | |
112 designator?")) | |
103 (defgeneric cut-off (anchored-period-designator) ; name? | 113 (defgeneric cut-off (anchored-period-designator) ; name? |
104 (:documentation "Returns a <moment> representing the point at | 114 (:documentation "Returns a <moment> representing the point at |
105 which the anchored period has ended. By default, is calculated | 115 which the anchored period has ended. By default, is calculated |
106 as the result of running time+ on the onset and period of the | 116 as the result of running time+ on the onset and period of the |
107 object.") | 117 object.") |
116 ;; for symbols in time-signatures as well as numbers - numerator is an | 126 ;; for symbols in time-signatures as well as numbers - numerator is an |
117 ;; odd accessor if the time sig is C (even in common practice) but | 127 ;; odd accessor if the time sig is C (even in common practice) but |
118 ;; its meaning is clear. beat-units-per-bar is clearer, though, I | 128 ;; its meaning is clear. beat-units-per-bar is clearer, though, I |
119 ;; think. | 129 ;; think. |
120 | 130 |
121 (defgeneric beat-units-per-bar (time-signature)) | 131 (defgeneric beat-units-per-bar (time-signature) |
132 (:documentation "In a standard, fraction-like time-signature or | |
133 a symbolic equivalent, this is the numerator.")) | |
122 (defgeneric time-signature-numerator (time-signature) | 134 (defgeneric time-signature-numerator (time-signature) |
123 (:method (ts) (beat-units-per-bar ts))) | 135 (:method (ts) (beat-units-per-bar ts)) |
124 (defgeneric beat-units (time-signature)) | 136 (:documentation "Not obviously meaningful for non fraction-like |
137 time signatures")) | |
138 (defgeneric beat-units (time-signature) | |
139 (:documentation "In a standard, fraction-like time-signature or | |
140 a symbolic equivalent, this is the numerator (n.b., | |
141 tactus-duration is the method of choice for compound time | |
142 sensitive queries.")) | |
125 (defgeneric time-signature-denominator (time-signature) | 143 (defgeneric time-signature-denominator (time-signature) |
126 (:method (ts) (beat-units ts))) | 144 (:method (ts) (beat-units ts)) |
145 (:documentation "Not obviously meaningful for non fraction-like | |
146 time signatures")) | |
127 (defgeneric tactus-duration (time-signature) | 147 (defgeneric tactus-duration (time-signature) |
128 ;; basic, but should do? | 148 ;; basic, but should do? |
129 (:method (ts) | 149 (:method (ts) |
130 (cond | 150 (cond |
131 ((and (not (= (beat-units-per-bar ts) 3)) | 151 ((and (not (= (beat-units-per-bar ts) 3)) |
132 (= (rem (beat-units-per-bar ts) 3) 0)) | 152 (= (rem (beat-units-per-bar ts) 3) 0)) |
133 ;; compound time | 153 ;; compound time |
134 (* (/ 4 (beat-units ts)) | 154 (* (/ 4 (beat-units ts)) |
135 3)) | 155 3)) |
136 (t (/ 4 (beat-units ts)))))) | 156 (t (/ 4 (beat-units ts))))) |
137 | 157 (:documentation "Returns a number of crotchets to represent the |
138 (defgeneric key-signature-sharps (key-signature)) | 158 tactus, based on some idea of time signature patterns. Should, |
139 (defgeneric key-signature-mode (ks)) | 159 in future, return a duration rather than a number.")) |
140 | 160 |
141 (defgeneric bpm (tempo)) ;; in bpm | 161 (defgeneric key-signature-sharps (key-signature) |
162 (:documentation "Simple query for normal key-signatures.")) | |
163 (defgeneric key-signature-mode (ks) | |
164 (:documentation "Query that only makes sense for midi-like key | |
165 signatures")) | |
166 | |
167 (defgeneric bpm (tempo) | |
168 (:documentation "Basic tempo query")) ;; in bpm | |
142 (defgeneric microseconds-per-crotchet (tempo) | 169 (defgeneric microseconds-per-crotchet (tempo) |
143 ;; As used (when rounded) in MIDI | 170 ;; As used (when rounded) in MIDI |
144 (:method (tp) (/ 60000000 (bpm tp)))) | 171 (:method (tp) (/ 60000000 (bpm tp))) |
172 (:documentation "Basic tempo query for MIDI. N.B. This will be | |
173 a fraction and must be rounded before being used for output.")) | |
145 | 174 |
146 ;;; Coerce-type accessors | 175 ;;; Coerce-type accessors |
147 | 176 |
148 ;; Should I be including these default methods? Should the accessors | 177 ;; Should I be including these default methods? Should the accessors |
149 ;; be direct slot accessors or the generics I'm using? Should we | 178 ;; be direct slot accessors or the generics I'm using? Should we |
150 ;; return the object itself if it already is in the target class? | 179 ;; return the object itself if it already is in the target class? |
151 | 180 |
152 (defgeneric anchored-period (anchored-period-designator) | 181 (defgeneric anchored-period (anchored-period-designator) |
153 (:method (apd) (make-anchored-period (onset apd) (duration apd)))) | 182 (:method (apd) (make-anchored-period (onset apd) (duration apd))) |
183 (:documentation "Coerce any anchored period to a plain anchored | |
184 period")) | |
154 | 185 |
155 (defgeneric floating-period (period-designator) | 186 (defgeneric floating-period (period-designator) |
156 (:method (pd) (make-floating-period (duration pd)))) | 187 (:method (pd) (make-floating-period (duration pd))) |
188 (:documentation "Coerce any period to a floating period")) | |
157 | 189 |
158 (defgeneric moment (moment-designator) | 190 (defgeneric moment (moment-designator) |
159 (:method (md) (make-moment (timepoint md)))) | 191 (:method (md) (make-moment (timepoint md))) |
192 (:documentation "Coerce any moment(-designator?), including an | |
193 anchored-period to a moment")) | |
160 | 194 |
161 (defgeneric onset (anchored-period-designator) | 195 (defgeneric onset (anchored-period-designator) |
162 (:method (apd) (moment apd))) | 196 (:method (apd) (moment apd)) |
197 (:documentation "Return a moment for the start of an anchored period")) | |
163 (defgeneric (setf onset) (value anchored-period-designator)) | 198 (defgeneric (setf onset) (value anchored-period-designator)) |
164 | 199 |
165 ;;; Time Protocol (or moments?) | 200 ;;; Time Protocol (or moments?) |
166 | 201 |
167 ;; negative times/durations -> ERROR? | 202 ;; negative times/durations -> ERROR? |
308 | 343 |
309 | 344 |
310 ;;; Time Signature | 345 ;;; Time Signature |
311 | 346 |
312 (defgeneric get-applicable-time-signatures (anchored-period composition) | 347 (defgeneric get-applicable-time-signatures (anchored-period composition) |
313 (:method (ap c) (find-overlapping ap (time-signatures c)))) | 348 (:method (ap c) (find-overlapping ap (time-signatures c))) |
314 | 349 (:documentation "Return a list of time-signatures that are |
315 (defgeneric time-signature-equal (ts1 ts2)) | 350 relevant to <anchored-period>. The period may contain |
351 information such as staff position and voicing, and the method | |
352 may use this to filter its response")) | |
353 | |
354 (defgeneric time-signature-equal (ts1 ts2) | |
355 (:documentation "Comparison operator. The definition of | |
356 equality is left open for implementers")) | |
316 | 357 |
317 ;;; Tempo | 358 ;;; Tempo |
318 | 359 |
319 (defgeneric get-applicable-tempi (anchored-period composition) | 360 (defgeneric get-applicable-tempi (anchored-period composition) |
320 (:method (ap c) (find-overlapping ap (tempi c)))) | 361 (:method (ap c) (find-overlapping ap (tempi c))) |
321 | 362 (:documentation "Return a list of tempi that are relevant to |
322 (defgeneric tempo-equal (t1 t2)) | 363 <anchored-period>. The period may contain information such as |
364 staff position and voicing, and the method may use this to | |
365 filter its response")) | |
366 | |
367 (defgeneric tempo-equal (t1 t2) | |
368 (:documentation "Comparison operator. The definition of | |
369 equality is left open for implementers")) | |
323 | 370 |
324 ;;; Tonality (Key Signature / Mode) | 371 ;;; Tonality (Key Signature / Mode) |
325 | 372 |
326 (defgeneric get-applicable-key-signatures (object1 object2)) | 373 (defgeneric get-applicable-key-signatures (object1 object2) |
327 | 374 (:documentation "Return a list of key-signatures that are |
328 (defgeneric key-signature-equal (ks1 ks2)) | 375 relevant to <anchored-period>. The period may contain |
376 information such as staff position and voicing, and the method | |
377 may use this to filter its response")) | |
378 | |
379 (defgeneric key-signature-equal (ks1 ks2) | |
380 (:documentation "Comparison operator. The definition of | |
381 equality is left open to implementers")) | |
329 | 382 |
330 ;;; Dynamics | 383 ;;; Dynamics |
331 ;;; Voice | 384 ;;; Voice |
332 ;;; Boundary Strength (phrasing) | 385 ;;; Boundary Strength (phrasing) |