annotate methods.lisp @ 20:6eb54ad3b8b4

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