annotate base/methods.lisp @ 34:81b4228e26f5

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