annotate methods.lisp @ 17:930e9880ed3f

Pitch methods and added constructors.lisp file darcs-hash:20061212144422-f76cc-194cd746d5d7eaf40f24ca5788093b25066de77c.gz
author David Lewis <d.lewis@gold.ac.uk>
date Tue, 12 Dec 2006 14:44:22 +0000
parents 5fac84ca066a
children 70e76c1c87b7
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@16 12 ;; Time protocol
d@16 13
d@16 14 (defmethod time+ ((object1 moment) (object2 period))
d@16 15 (make-moment (+ (timepoint object1) (duration object2))))
d@16 16
d@16 17 (defmethod time+ ((object1 period) (object2 moment)) ;?
d@16 18 (time+ object2 object1))
d@16 19
d@16 20 (defmethod time+ ((object1 period) (object2 period))
d@16 21 (make-floating-period (+ (duration object1)
d@16 22 (duration object2))))
d@16 23
d@16 24 (defmethod time+ ((object1 moment) (object2 moment))
d@17 25 (error 'undefined-action :operation 'time+ :datatype (list (class-of object1) (class-of object2))))
d@16 26
d@16 27 (defmethod time- ((object1 moment) (object2 moment))
d@16 28 (make-anchored-period object1
d@16 29 (- (duration object2)
d@16 30 (duration object1))))
d@16 31
d@16 32 (defmethod time- ((object1 moment) (object2 period))
d@16 33 (make-moment (- (timepoint object1) (duration object2))))
d@16 34
d@16 35 (defmethod time- ((object1 period) (object2 moment)) ;?
d@16 36 (error 'undefined-action
d@16 37 :operation 'time-
d@17 38 :datatype (list (class-of object1) (class-of object2))))
d@16 39
d@16 40 (defmethod time- ((object1 period) (object2 period))
d@16 41 (make-floating-period (- (duration object2)
d@16 42 (duration object1))))
d@16 43
d@16 44
d@16 45 (defmethod time> ((object1 moment) (object2 moment))
d@16 46 (> (timepoint object1) (timepoint object2)))
d@16 47
d@16 48 (defmethod time= ((object1 moment) (object2 moment))
d@16 49 (= (timepoint object1) (timepoint object2)))
d@16 50
d@16 51 (defmethod duration> ((object1 period) (object2 period))
d@16 52 (> (duration object1) (duration object2)))
d@16 53
d@16 54 (defmethod duration= ((object1 period) (object2 period))
d@16 55 (= (duration object1) (duration object2)))
d@16 56
d@16 57 (defmethod duration* ((object1 period) (object2 number))
d@16 58 (* (duration object1) object2))
d@16 59
d@16 60 (defmethod duration* ((object1 number) (object2 period))
d@16 61 (duration* object2 object1))
d@16 62
d@16 63 (defmethod duration/ ((object1 period) (object2 number))
d@16 64 (/ (duration object1) object2))
d@16 65
d@16 66 ;; Pitch protocol
d@16 67
d@17 68 (defmethod pitch+ ((object1 pitch-designator)
d@17 69 (object2 pitch-designator))
d@17 70 (error 'undefined-action :operation 'pitch+
d@17 71 :datatype (list (class-of object1) (class-of object2))))
d@17 72
d@17 73 (defmethod pitch+ ((object1 pitch-designator)
d@17 74 (object2 pitch-interval)) ; or should I check the
d@17 75 ; pitch/interval types?
d@17 76 (make-chromatic-pitch (+ (chromatic-pitch object1)
d@17 77 (span object2))))
d@17 78
d@17 79 (defmethod pitch+ ((object1 pitch-interval)
d@17 80 (object2 pitch-designator)) ;?
d@17 81 (pitch+ object2 object1))
d@17 82
d@17 83 (defmethod pitch+ ((object1 pitch-interval)
d@17 84 (object2 pitch-interval))
d@17 85 (make-pitch-interval (+ (span object1)
d@17 86 (span object2))))
d@17 87
d@17 88 (defmethod pitch- ((object1 pitch-designator)
d@17 89 (object2 pitch-designator))
d@17 90 (make-pitch-interval (- (chromatic-pitch object1)
d@17 91 (chromatic-pitch object2))))
d@17 92
d@17 93 (defmethod pitch- ((object1 pitch-designator)
d@17 94 (object2 pitch-interval))
d@17 95 (make-chromatic-pitch (- (chromatic-pitch object1)
d@17 96 (span object2))))
d@17 97
d@17 98 (defmethod pitch- ((object1 pitch-interval)
d@17 99 (object2 pitch-interval))
d@17 100 (make-pitch-interval (- (span object1)
d@17 101 (span object2))))
d@17 102
d@17 103 (defmethod pitch- ((object1 pitch-interval)
d@17 104 (object2 pitch-designator))
d@17 105 (error 'undefined-action :operation 'pitch-
d@17 106 :datatype (list (class-of object1) (class-of object2))))
d@17 107
d@17 108 (defmethod pitch> ((object1 pitch-designator)
d@17 109 (object2 pitch-designator))
d@17 110 (> (chromatic-pitch object1)
d@17 111 (chromatic-pitch object2)))
d@17 112
d@17 113 (defmethod pitch= ((object1 pitch-designator)
d@17 114 (object2 pitch-designator))
d@17 115 (= (chromatic-pitch object1)
d@17 116 (chromatic-pitch object2)))
d@17 117
d@17 118 (defmethod interval> ((object1 pitch-interval)
d@17 119 (object2 pitch-interval))
d@17 120 (> (span object1)
d@17 121 (span object2)))
d@17 122
d@17 123 (defmethod interval= ((object1 pitch-interval)
d@17 124 (object2 pitch-interval))
d@17 125 (= (span object1)
d@17 126 (span object2)))
d@17 127
d@17 128
d@16 129
d@16 130 ;; Allen
d@16 131
d@16 132 (defmethod meets ((object1 anchored-period)
d@16 133 (object2 anchored-period))
d@16 134 (or (time= (cut-off object1) (onset object2))
d@16 135 (time= (cut-off object2) (onset object1))))
d@16 136
d@16 137 (defmethod before ((object1 anchored-period)
d@16 138 (object2 anchored-period))
d@16 139 (time< (cut-off object1) (onset object2)))
d@16 140
d@16 141 (defmethod overlaps ((object1 anchored-period)
d@16 142 (object2 anchored-period))
d@16 143 (or (and (time> (cut-off object1) (onset object2))
d@16 144 (time< (onset object1) (onset object2)))
d@16 145 (and (time> (cut-off object1) (cut-off object2))
d@16 146 (time< (onset object1) (cut-off object2)))))
d@16 147
d@16 148 (defmethod during ((object1 anchored-period)
d@16 149 (object2 anchored-period))
d@16 150 (and (time> (onset object1) (onset object2))
d@16 151 (time< (cut-off object2) (cut-off object2))))
d@16 152
d@16 153 (defmethod starts ((object1 anchored-period)
d@16 154 (object2 anchored-period))
d@16 155 (time= (onset object1) (onset object2)))
d@16 156
d@16 157 (defmethod ends ((object1 anchored-period)
d@16 158 (object2 anchored-period))
d@16 159 (time= (cut-off object1) (cut-off object2)))
d@16 160
d@16 161 ;; ...and
d@16 162
d@16 163 (defmethod period-intersection ((object1 anchored-period)
d@16 164 (object2 anchored-period))
d@16 165 (cond
d@16 166 ((disjoint object1 object2)
d@16 167 ;; if they don't overlap, return nil, not a negative-valued
d@16 168 ;; period
d@16 169 nil)
d@16 170 (t
d@16 171 (let ((new-onset (max (onset object1)
d@16 172 (onset object2))))
d@16 173 (make-anchored-period new-onset
d@16 174 (time- (min (cut-off object1)
d@16 175 (cut-off object2))
d@16 176 new-onset))))))
d@16 177
d@16 178
d@16 179