annotate base/methods.lisp @ 45:0f31919a855d

Implement and export KEY-SIGNATURE-MODE, export {MAKE-,}MIDI-KEY-SIGNATURE. darcs-hash:20070614181742-aa3d6-8a81a04b3df6db990c71a8aef653b69249e331c8.gz
author m.pearce <m.pearce@gold.ac.uk>
date Thu, 14 Jun 2007 19:17:42 +0100
parents 81b4228e26f5
children 8b31d54c95be
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@45 36 (defmethod key-signature-mode ((ks midi-key-signature))
m@45 37 (%midi-key-signature-mode ks))
m@45 38
m@24 39 (defmethod bpm ((tempo tempo))
m@24 40 (%tempo-bpm tempo))
m@24 41
m@24 42 ;; Time protocol
m@24 43
m@24 44 (defmethod time+ ((object1 moment) (object2 period))
m@24 45 (make-moment (+ (timepoint object1) (duration object2))))
m@24 46
m@24 47 (defmethod time+ ((object1 period) (object2 moment)) ;?
m@24 48 (time+ object2 object1))
m@24 49
m@24 50 (defmethod time+ ((object1 period) (object2 period))
m@24 51 (make-floating-period (+ (duration object1)
m@24 52 (duration object2))))
m@24 53
m@24 54 (defmethod time+ ((object1 moment) (object2 moment))
m@24 55 (error 'undefined-action :operation 'time+ :datatype (list (class-of object1) (class-of object2))))
m@24 56
m@24 57 (defmethod time- ((object1 moment) (object2 moment))
m@24 58 (make-anchored-period (timepoint object2)
m@24 59 (- (timepoint object1)
m@24 60 (timepoint object2))))
m@24 61
m@24 62 (defmethod time- ((object1 moment) (object2 period))
m@24 63 (make-moment (- (timepoint object1) (duration object2))))
m@24 64
m@24 65 (defmethod time- ((object1 period) (object2 moment)) ;?
m@24 66 (error 'undefined-action
m@24 67 :operation 'time-
m@24 68 :datatype (list (class-of object1) (class-of object2))))
m@24 69
m@24 70 (defmethod time- ((object1 period) (object2 period))
m@24 71 (make-floating-period (- (duration object2)
m@24 72 (duration object1))))
m@24 73
m@24 74 ;; these ones are less certain. I've just put them in, but think I
m@24 75 ;; should remove them and force the user to specify what they mean
m@24 76 ;; when they give objects that are both moments *and* periods to these
m@24 77 ;; functions.
m@24 78
m@24 79 (defmethod time- ((object1 anchored-period) (object2 anchored-period)) ;?
m@24 80 (time- (moment object1) (moment object2)))
m@24 81
m@24 82 (defmethod time- (object1 (object2 anchored-period)) ;?
m@24 83 (time- object1 (moment object2)))
m@24 84
m@24 85 (defmethod time- ((object1 anchored-period) object2) ;?
m@24 86 (time- (moment object1) 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 time= ((object1 moment) (object2 moment))
m@24 92 (= (timepoint object1) (timepoint 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 period))
m@24 98 (= (duration object1) (duration object2)))
m@24 99
m@24 100 (defmethod duration* ((object1 period) (object2 number))
m@24 101 (make-floating-period (* (duration object1) object2)))
m@24 102
m@24 103 (defmethod duration* ((object1 number) (object2 period))
m@24 104 (duration* object2 object1))
m@24 105
m@24 106 (defmethod duration/ ((object1 period) (object2 number))
m@24 107 (make-floating-period (/ (duration object1) object2)))
m@24 108
m@24 109 ;; Pitch protocol
m@24 110
m@24 111 (defmethod pitch+ ((object1 pitch-designator)
m@24 112 (object2 pitch-designator))
m@24 113 (error 'undefined-action :operation 'pitch+
m@24 114 :datatype (list (class-of object1) (class-of object2))))
m@24 115
m@24 116 (defmethod pitch+ ((object1 pitch-designator)
m@24 117 (object2 pitch-interval)) ; or should I check the
m@24 118 ; pitch/interval types?
d@34 119 (make-chromatic-pitch (+ (midi-pitch-number object1)
m@24 120 (span object2))))
m@24 121
m@24 122 (defmethod pitch+ ((object1 pitch-interval)
m@24 123 (object2 pitch-designator)) ;?
m@24 124 (pitch+ object2 object1))
m@24 125
m@24 126 (defmethod pitch+ ((object1 pitch-interval)
m@24 127 (object2 pitch-interval))
m@24 128 (make-pitch-interval (+ (span object1)
m@24 129 (span object2))))
m@24 130
m@24 131 (defmethod pitch- ((object1 pitch-designator)
m@24 132 (object2 pitch-designator))
d@34 133 (make-pitch-interval (- (midi-pitch-number object1)
d@34 134 (midi-pitch-number object2))))
m@24 135
m@24 136 (defmethod pitch- ((object1 pitch-designator)
m@24 137 (object2 pitch-interval))
d@34 138 (make-chromatic-pitch (- (midi-pitch-number object1)
m@24 139 (span object2))))
m@24 140
m@24 141 (defmethod pitch- ((object1 pitch-interval)
m@24 142 (object2 pitch-interval))
m@24 143 (make-pitch-interval (- (span object1)
m@24 144 (span object2))))
m@24 145
m@24 146 (defmethod pitch- ((object1 pitch-interval)
m@24 147 (object2 pitch-designator))
m@24 148 (error 'undefined-action :operation 'pitch-
m@24 149 :datatype (list (class-of object1) (class-of object2))))
m@24 150
m@24 151 (defmethod pitch> ((object1 pitch-designator)
m@24 152 (object2 pitch-designator))
d@34 153 (> (midi-pitch-number object1)
d@34 154 (midi-pitch-number object2)))
m@24 155
m@24 156 (defmethod pitch= ((object1 pitch-designator)
m@24 157 (object2 pitch-designator))
d@34 158 (= (midi-pitch-number object1)
d@34 159 (midi-pitch-number object2)))
m@24 160
m@24 161 (defmethod interval> ((object1 pitch-interval)
m@24 162 (object2 pitch-interval))
m@24 163 (> (span object1)
m@24 164 (span object2)))
m@24 165
m@24 166 (defmethod interval= ((object1 pitch-interval)
m@24 167 (object2 pitch-interval))
m@24 168 (= (span object1)
m@24 169 (span object2)))
m@24 170
m@24 171
m@24 172
m@24 173 ;; Allen
m@24 174
m@24 175 (defmethod meets ((object1 anchored-period)
m@24 176 (object2 anchored-period))
m@24 177 (or (time= (cut-off object1) object2)
m@24 178 (time= (cut-off object2) object1)))
m@24 179
m@24 180 (defmethod before ((object1 anchored-period)
m@24 181 (object2 anchored-period))
m@24 182 (time> object2 (cut-off object1)))
m@24 183
m@24 184 (defmethod overlaps ((object1 anchored-period)
m@24 185 (object2 anchored-period))
m@24 186 ;; FIXME: Is there a tidier method?
m@24 187 (or (and (time> object2 object1) ; object1 starts before object2
m@24 188 (time> (cut-off object1) object2) ; object1 ends after object2 starts
m@24 189 (time> (cut-off object2) (cut-off object1))) ; object1 ends before object2 does
m@24 190 (and (time> object1 object2) ; object1 starts after object2
m@24 191 (time> (cut-off object2) object1) ; object1 starts before object2 ends
m@24 192 (time> (cut-off object1) (cut-off object2))))) ; object1 ends after object2 does
m@24 193
m@24 194 (defmethod during ((object1 anchored-period)
m@24 195 (object2 anchored-period))
m@24 196 (and (time> object1 object2)
m@24 197 (time< (cut-off object2) (cut-off object2))))
m@24 198
m@24 199 (defmethod starts ((object1 anchored-period)
m@24 200 (object2 anchored-period))
m@24 201 (time= object1 object2))
m@24 202
m@24 203 (defmethod ends ((object1 anchored-period)
m@24 204 (object2 anchored-period))
m@24 205 (time= (cut-off object1) (cut-off object2)))
m@24 206
m@24 207 ;; ...and
m@24 208
d@33 209 (defmethod period= ((object1 anchored-period)
d@33 210 (object2 anchored-period))
d@33 211 (and (time= object1 object2)
d@33 212 (duration= object1 object2)))
d@33 213 (defmethod period= ((object1 floating-period)
d@33 214 (object2 floating-period))
d@33 215 (duration= object1 object2))
d@33 216
m@24 217 (defmethod period-intersection ((object1 anchored-period)
m@24 218 (object2 anchored-period))
m@24 219 (cond
m@24 220 ((disjoint object1 object2)
m@24 221 ;; if they don't overlap, return nil, not a negative-valued
m@24 222 ;; period
m@24 223 nil)
m@24 224 ((let* ((start (if (time> (onset object2) (onset object1))
m@24 225 (onset object2)
m@24 226 (onset object1)))
m@24 227 (duration (duration (time- (if (time> (cut-off object2) (cut-off object1))
m@24 228 (cut-off object1)
m@24 229 (cut-off object2))
m@24 230 start))))
m@24 231 (make-anchored-period (timepoint start) duration)))))
m@24 232
m@24 233