annotate methods.lisp @ 18:70e76c1c87b7

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