m@24
|
1 (cl:in-package #:amuse)
|
m@24
|
2
|
m@24
|
3 (defmethod chromatic-pitch ((pitch-designator chromatic-pitch))
|
m@24
|
4 pitch-designator)
|
m@24
|
5
|
m@24
|
6 (defmethod midi-pitch-number ((pitch-designator chromatic-pitch))
|
m@24
|
7 (%chromatic-pitch-number pitch-designator))
|
m@24
|
8
|
m@24
|
9 (defmethod midi-pitch-number ((pitch-designator pitch))
|
m@24
|
10 (%chromatic-pitch-number (chromatic-pitch pitch-designator)))
|
m@24
|
11
|
m@24
|
12 (defmethod span ((pitch-interval-designator pitch-interval))
|
m@24
|
13 (%pitch-interval-span pitch-interval-designator))
|
m@24
|
14
|
m@24
|
15 (defmethod duration ((period-designator period))
|
m@24
|
16 (%period-interval period-designator))
|
m@24
|
17
|
m@24
|
18 (defmethod timepoint ((moment-designator moment))
|
m@24
|
19 (%moment-time moment-designator))
|
m@24
|
20
|
m@24
|
21 (defmethod beat-units-per-bar ((time-signature basic-time-signature))
|
m@24
|
22 (%basic-time-signature-numerator time-signature))
|
m@24
|
23
|
m@24
|
24 (defmethod beat-units ((time-signature basic-time-signature))
|
m@24
|
25 (%basic-time-signature-denominator time-signature))
|
m@24
|
26
|
m@24
|
27 (defmethod key-signature-sharps ((key-signature basic-key-signature))
|
m@24
|
28 (%basic-key-signature-sharp-count key-signature))
|
m@24
|
29
|
m@24
|
30 (defmethod bpm ((tempo tempo))
|
m@24
|
31 (%tempo-bpm tempo))
|
m@24
|
32
|
m@24
|
33 ;; Time protocol
|
m@24
|
34
|
m@24
|
35 (defmethod time+ ((object1 moment) (object2 period))
|
m@24
|
36 (make-moment (+ (timepoint object1) (duration object2))))
|
m@24
|
37
|
m@24
|
38 (defmethod time+ ((object1 period) (object2 moment)) ;?
|
m@24
|
39 (time+ object2 object1))
|
m@24
|
40
|
m@24
|
41 (defmethod time+ ((object1 period) (object2 period))
|
m@24
|
42 (make-floating-period (+ (duration object1)
|
m@24
|
43 (duration object2))))
|
m@24
|
44
|
m@24
|
45 (defmethod time+ ((object1 moment) (object2 moment))
|
m@24
|
46 (error 'undefined-action :operation 'time+ :datatype (list (class-of object1) (class-of object2))))
|
m@24
|
47
|
m@24
|
48 (defmethod time- ((object1 moment) (object2 moment))
|
m@24
|
49 (make-anchored-period (timepoint object2)
|
m@24
|
50 (- (timepoint object1)
|
m@24
|
51 (timepoint object2))))
|
m@24
|
52
|
m@24
|
53 (defmethod time- ((object1 moment) (object2 period))
|
m@24
|
54 (make-moment (- (timepoint object1) (duration object2))))
|
m@24
|
55
|
m@24
|
56 (defmethod time- ((object1 period) (object2 moment)) ;?
|
m@24
|
57 (error 'undefined-action
|
m@24
|
58 :operation 'time-
|
m@24
|
59 :datatype (list (class-of object1) (class-of object2))))
|
m@24
|
60
|
m@24
|
61 (defmethod time- ((object1 period) (object2 period))
|
m@24
|
62 (make-floating-period (- (duration object2)
|
m@24
|
63 (duration object1))))
|
m@24
|
64
|
m@24
|
65 ;; these ones are less certain. I've just put them in, but think I
|
m@24
|
66 ;; should remove them and force the user to specify what they mean
|
m@24
|
67 ;; when they give objects that are both moments *and* periods to these
|
m@24
|
68 ;; functions.
|
m@24
|
69
|
m@24
|
70 (defmethod time- ((object1 anchored-period) (object2 anchored-period)) ;?
|
m@24
|
71 (time- (moment object1) (moment object2)))
|
m@24
|
72
|
m@24
|
73 (defmethod time- (object1 (object2 anchored-period)) ;?
|
m@24
|
74 (time- object1 (moment object2)))
|
m@24
|
75
|
m@24
|
76 (defmethod time- ((object1 anchored-period) object2) ;?
|
m@24
|
77 (time- (moment object1) object2))
|
m@24
|
78
|
m@24
|
79 (defmethod time> ((object1 moment) (object2 moment))
|
m@24
|
80 (> (timepoint object1) (timepoint object2)))
|
m@24
|
81
|
m@24
|
82 (defmethod time= ((object1 moment) (object2 moment))
|
m@24
|
83 (= (timepoint object1) (timepoint object2)))
|
m@24
|
84
|
m@24
|
85 (defmethod duration> ((object1 period) (object2 period))
|
m@24
|
86 (> (duration object1) (duration object2)))
|
m@24
|
87
|
m@24
|
88 (defmethod duration= ((object1 period) (object2 period))
|
m@24
|
89 (= (duration object1) (duration object2)))
|
m@24
|
90
|
m@24
|
91 (defmethod duration* ((object1 period) (object2 number))
|
m@24
|
92 (make-floating-period (* (duration object1) object2)))
|
m@24
|
93
|
m@24
|
94 (defmethod duration* ((object1 number) (object2 period))
|
m@24
|
95 (duration* object2 object1))
|
m@24
|
96
|
m@24
|
97 (defmethod duration/ ((object1 period) (object2 number))
|
m@24
|
98 (make-floating-period (/ (duration object1) object2)))
|
m@24
|
99
|
m@24
|
100 ;; Pitch protocol
|
m@24
|
101
|
m@24
|
102 (defmethod pitch+ ((object1 pitch-designator)
|
m@24
|
103 (object2 pitch-designator))
|
m@24
|
104 (error 'undefined-action :operation 'pitch+
|
m@24
|
105 :datatype (list (class-of object1) (class-of object2))))
|
m@24
|
106
|
m@24
|
107 (defmethod pitch+ ((object1 pitch-designator)
|
m@24
|
108 (object2 pitch-interval)) ; or should I check the
|
m@24
|
109 ; pitch/interval types?
|
m@24
|
110 (make-chromatic-pitch (+ (chromatic-pitch object1)
|
m@24
|
111 (span object2))))
|
m@24
|
112
|
m@24
|
113 (defmethod pitch+ ((object1 pitch-interval)
|
m@24
|
114 (object2 pitch-designator)) ;?
|
m@24
|
115 (pitch+ object2 object1))
|
m@24
|
116
|
m@24
|
117 (defmethod pitch+ ((object1 pitch-interval)
|
m@24
|
118 (object2 pitch-interval))
|
m@24
|
119 (make-pitch-interval (+ (span object1)
|
m@24
|
120 (span object2))))
|
m@24
|
121
|
m@24
|
122 (defmethod pitch- ((object1 pitch-designator)
|
m@24
|
123 (object2 pitch-designator))
|
m@24
|
124 (make-pitch-interval (- (chromatic-pitch object1)
|
m@24
|
125 (chromatic-pitch object2))))
|
m@24
|
126
|
m@24
|
127 (defmethod pitch- ((object1 pitch-designator)
|
m@24
|
128 (object2 pitch-interval))
|
m@24
|
129 (make-chromatic-pitch (- (chromatic-pitch object1)
|
m@24
|
130 (span object2))))
|
m@24
|
131
|
m@24
|
132 (defmethod pitch- ((object1 pitch-interval)
|
m@24
|
133 (object2 pitch-interval))
|
m@24
|
134 (make-pitch-interval (- (span object1)
|
m@24
|
135 (span object2))))
|
m@24
|
136
|
m@24
|
137 (defmethod pitch- ((object1 pitch-interval)
|
m@24
|
138 (object2 pitch-designator))
|
m@24
|
139 (error 'undefined-action :operation 'pitch-
|
m@24
|
140 :datatype (list (class-of object1) (class-of object2))))
|
m@24
|
141
|
m@24
|
142 (defmethod pitch> ((object1 pitch-designator)
|
m@24
|
143 (object2 pitch-designator))
|
m@24
|
144 (> (chromatic-pitch object1)
|
m@24
|
145 (chromatic-pitch object2)))
|
m@24
|
146
|
m@24
|
147 (defmethod pitch= ((object1 pitch-designator)
|
m@24
|
148 (object2 pitch-designator))
|
m@24
|
149 (= (chromatic-pitch object1)
|
m@24
|
150 (chromatic-pitch object2)))
|
m@24
|
151
|
m@24
|
152 (defmethod interval> ((object1 pitch-interval)
|
m@24
|
153 (object2 pitch-interval))
|
m@24
|
154 (> (span object1)
|
m@24
|
155 (span object2)))
|
m@24
|
156
|
m@24
|
157 (defmethod interval= ((object1 pitch-interval)
|
m@24
|
158 (object2 pitch-interval))
|
m@24
|
159 (= (span object1)
|
m@24
|
160 (span object2)))
|
m@24
|
161
|
m@24
|
162
|
m@24
|
163
|
m@24
|
164 ;; Allen
|
m@24
|
165
|
m@24
|
166 (defmethod meets ((object1 anchored-period)
|
m@24
|
167 (object2 anchored-period))
|
m@24
|
168 (or (time= (cut-off object1) object2)
|
m@24
|
169 (time= (cut-off object2) object1)))
|
m@24
|
170
|
m@24
|
171 (defmethod before ((object1 anchored-period)
|
m@24
|
172 (object2 anchored-period))
|
m@24
|
173 (time> object2 (cut-off object1)))
|
m@24
|
174
|
m@24
|
175 (defmethod overlaps ((object1 anchored-period)
|
m@24
|
176 (object2 anchored-period))
|
m@24
|
177 ;; FIXME: Is there a tidier method?
|
m@24
|
178 (or (and (time> object2 object1) ; object1 starts before object2
|
m@24
|
179 (time> (cut-off object1) object2) ; object1 ends after object2 starts
|
m@24
|
180 (time> (cut-off object2) (cut-off object1))) ; object1 ends before object2 does
|
m@24
|
181 (and (time> object1 object2) ; object1 starts after object2
|
m@24
|
182 (time> (cut-off object2) object1) ; object1 starts before object2 ends
|
m@24
|
183 (time> (cut-off object1) (cut-off object2))))) ; object1 ends after object2 does
|
m@24
|
184
|
m@24
|
185 (defmethod during ((object1 anchored-period)
|
m@24
|
186 (object2 anchored-period))
|
m@24
|
187 (and (time> object1 object2)
|
m@24
|
188 (time< (cut-off object2) (cut-off object2))))
|
m@24
|
189
|
m@24
|
190 (defmethod starts ((object1 anchored-period)
|
m@24
|
191 (object2 anchored-period))
|
m@24
|
192 (time= object1 object2))
|
m@24
|
193
|
m@24
|
194 (defmethod ends ((object1 anchored-period)
|
m@24
|
195 (object2 anchored-period))
|
m@24
|
196 (time= (cut-off object1) (cut-off object2)))
|
m@24
|
197
|
m@24
|
198 ;; ...and
|
m@24
|
199
|
m@24
|
200 (defmethod period-intersection ((object1 anchored-period)
|
m@24
|
201 (object2 anchored-period))
|
m@24
|
202 (cond
|
m@24
|
203 ((disjoint object1 object2)
|
m@24
|
204 ;; if they don't overlap, return nil, not a negative-valued
|
m@24
|
205 ;; period
|
m@24
|
206 nil)
|
m@24
|
207 ((let* ((start (if (time> (onset object2) (onset object1))
|
m@24
|
208 (onset object2)
|
m@24
|
209 (onset object1)))
|
m@24
|
210 (duration (duration (time- (if (time> (cut-off object2) (cut-off object1))
|
m@24
|
211 (cut-off object1)
|
m@24
|
212 (cut-off object2))
|
m@24
|
213 start))))
|
m@24
|
214 (make-anchored-period (timepoint start) duration)))))
|
m@24
|
215
|
m@24
|
216
|
m@24
|
217
|
m@24
|
218 |