comparison base/generics.lisp @ 33:d1010755f507

Large upload of local changes. Many additions, such as harmony and piece-level objects darcs-hash:20070413100909-f76cc-a8aa8dfc07f438dc0c1a7c45cee7ace2ecc1e6a5.gz
author David Lewis <d.lewis@gold.ac.uk>
date Fri, 13 Apr 2007 11:09:09 +0100
parents 8d2b1662f658
children 0f31919a855d
comparison
equal deleted inserted replaced
32:5e705b6f94b6 33:d1010755f507
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
7 ;;; Getting constituents from compositions
8 ;; IS this the mechanism we want to use
9 (defgeneric time-signatures (composition))
10 (defgeneric (setf time-signatures) (sequence composition))
11 (defgeneric tempi (composition))
12 (defgeneric (setf tempi) (sequence composition))
13 (defgeneric key-signatures (composition))
14 (defgeneric (setf key-signatures) (sequence composition))
6 15
7 ;;; Simple Accessors 16 ;;; Simple Accessors
8 17
9 ;; pitch-based 18 ;; pitch-based
10 19
42 (defgeneric time-signature-numerator (time-signature) 51 (defgeneric time-signature-numerator (time-signature)
43 (:method (ts) (beat-units-per-bar ts))) 52 (:method (ts) (beat-units-per-bar ts)))
44 (defgeneric beat-units (time-signature)) 53 (defgeneric beat-units (time-signature))
45 (defgeneric time-signature-denominator (time-signature) 54 (defgeneric time-signature-denominator (time-signature)
46 (:method (ts) (beat-units ts))) 55 (:method (ts) (beat-units ts)))
56 (defgeneric tactus-duration (time-signature)
57 ;; basic, but should do?
58 (:method (ts)
59 (cond
60 ((and (not (= (beat-units-per-bar ts) 3))
61 (= (rem (beat-units-per-bar ts) 3) 0))
62 ;; compound time
63 (* (/ 4 (beat-units ts))
64 3))
65 (t (/ 4 (beat-units ts))))))
47 66
48 (defgeneric key-signature-sharps (key-signature)) 67 (defgeneric key-signature-sharps (key-signature))
49 68
50 (defgeneric bpm (tempo)) ;; in bpm 69 (defgeneric bpm (tempo)) ;; in bpm
51 (defgeneric microseconds-per-crotchet (tempo) 70 (defgeneric microseconds-per-crotchet (tempo)
176 (defgeneric disjoint (object1 object2) 195 (defgeneric disjoint (object1 object2)
177 (:method (o1 o2) 196 (:method (o1 o2)
178 (or (before o1 o2) (meets o1 o2) (meets o2 o1) (before o2 o1)))) 197 (or (before o1 o2) (meets o1 o2) (meets o2 o1) (before o2 o1))))
179 198
180 ;;; More time-based functions 199 ;;; More time-based functions
200
201 (defgeneric period= (object1 object2)
202 (:method (x y) nil))
203
204 (defgeneric find-overlapping (anchored-period sequence)
205 ;; Returns all members of a sequence of period signifiers that overlap
206 ;; with the supplied period
207 (:method (ap s) (remove-if #'(lambda (x) (amuse:disjoint ap x)) s)))
208
181 ;; Return the anchored-period representing the intersection of two 209 ;; Return the anchored-period representing the intersection of two
182 ;; anchored-period-specifiers. 210 ;; anchored-period-specifiers.
183 (defgeneric period-intersection (anchored-period-specifier1 211 (defgeneric period-intersection (anchored-period-specifier1
184 anchored-period-specifier2)) 212 anchored-period-specifier2))
185 213
187 (:method (md1 md2) (time- (moment md2) (moment md1)))) 215 (:method (md1 md2) (time- (moment md2) (moment md1))))
188 216
189 217
190 ;;; Time Signature 218 ;;; Time Signature
191 219
192 (defgeneric get-applicable-time-signatures (object1 object2)) 220 (defgeneric get-applicable-time-signatures (anchored-period composition)
221 (:method (ap c) (find-overlapping ap (time-signatures c))))
193 222
194 ;;; Tempo 223 ;;; Tempo
195 224
196 (defgeneric get-applicable-tempi (object1 object2)) 225 (defgeneric get-applicable-tempi (anchored-period composition)
226 (:method (ap c) (find-overlapping ap (tempi c))))
197 227
198 ;;; Tonality (Key Signature / Mode) 228 ;;; Tonality (Key Signature / Mode)
199 229
200 (defgeneric get-applicable-key-signatures (object1 object2)) 230 (defgeneric get-applicable-key-signatures (object1 object2))
201 231