Mercurial > hg > amuse
view 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 |
line wrap: on
line source
(cl:in-package #:amuse) (defmethod duration ((period-designator period)) (%period-interval period-designator)) (defmethod timepoint ((moment-designator moment)) (%moment-time moment-designator)) (defmethod span ((pitch-interval-designator pitch-interval)) (%pitch-interval-span pitch-interval-designator)) ;; Time protocol (defmethod time+ ((object1 moment) (object2 period)) (make-moment (+ (timepoint object1) (duration object2)))) (defmethod time+ ((object1 period) (object2 moment)) ;? (time+ object2 object1)) (defmethod time+ ((object1 period) (object2 period)) (make-floating-period (+ (duration object1) (duration object2)))) (defmethod time+ ((object1 moment) (object2 moment)) (error 'undefined-action :operation 'time+ :datatype (list (class-of object1) (class-of object2)))) (defmethod time- ((object1 moment) (object2 moment)) (make-anchored-period object1 (- (duration object2) (duration object1)))) (defmethod time- ((object1 moment) (object2 period)) (make-moment (- (timepoint object1) (duration object2)))) (defmethod time- ((object1 period) (object2 moment)) ;? (error 'undefined-action :operation 'time- :datatype (list (class-of object1) (class-of object2)))) (defmethod time- ((object1 period) (object2 period)) (make-floating-period (- (duration object2) (duration object1)))) (defmethod time> ((object1 moment) (object2 moment)) (> (timepoint object1) (timepoint object2))) (defmethod time= ((object1 moment) (object2 moment)) (= (timepoint object1) (timepoint object2))) (defmethod duration> ((object1 period) (object2 period)) (> (duration object1) (duration object2))) (defmethod duration= ((object1 period) (object2 period)) (= (duration object1) (duration object2))) (defmethod duration* ((object1 period) (object2 number)) (* (duration object1) object2)) (defmethod duration* ((object1 number) (object2 period)) (duration* object2 object1)) (defmethod duration/ ((object1 period) (object2 number)) (/ (duration object1) object2)) ;; Pitch protocol (defmethod pitch+ ((object1 pitch-designator) (object2 pitch-designator)) (error 'undefined-action :operation 'pitch+ :datatype (list (class-of object1) (class-of object2)))) (defmethod pitch+ ((object1 pitch-designator) (object2 pitch-interval)) ; or should I check the ; pitch/interval types? (make-chromatic-pitch (+ (chromatic-pitch object1) (span object2)))) (defmethod pitch+ ((object1 pitch-interval) (object2 pitch-designator)) ;? (pitch+ object2 object1)) (defmethod pitch+ ((object1 pitch-interval) (object2 pitch-interval)) (make-pitch-interval (+ (span object1) (span object2)))) (defmethod pitch- ((object1 pitch-designator) (object2 pitch-designator)) (make-pitch-interval (- (chromatic-pitch object1) (chromatic-pitch object2)))) (defmethod pitch- ((object1 pitch-designator) (object2 pitch-interval)) (make-chromatic-pitch (- (chromatic-pitch object1) (span object2)))) (defmethod pitch- ((object1 pitch-interval) (object2 pitch-interval)) (make-pitch-interval (- (span object1) (span object2)))) (defmethod pitch- ((object1 pitch-interval) (object2 pitch-designator)) (error 'undefined-action :operation 'pitch- :datatype (list (class-of object1) (class-of object2)))) (defmethod pitch> ((object1 pitch-designator) (object2 pitch-designator)) (> (chromatic-pitch object1) (chromatic-pitch object2))) (defmethod pitch= ((object1 pitch-designator) (object2 pitch-designator)) (= (chromatic-pitch object1) (chromatic-pitch object2))) (defmethod interval> ((object1 pitch-interval) (object2 pitch-interval)) (> (span object1) (span object2))) (defmethod interval= ((object1 pitch-interval) (object2 pitch-interval)) (= (span object1) (span object2))) ;; Allen (defmethod meets ((object1 anchored-period) (object2 anchored-period)) (or (time= (cut-off object1) (onset object2)) (time= (cut-off object2) (onset object1)))) (defmethod before ((object1 anchored-period) (object2 anchored-period)) (time< (cut-off object1) (onset object2))) (defmethod overlaps ((object1 anchored-period) (object2 anchored-period)) (or (and (time> (cut-off object1) (onset object2)) (time< (onset object1) (onset object2))) (and (time> (cut-off object1) (cut-off object2)) (time< (onset object1) (cut-off object2))))) (defmethod during ((object1 anchored-period) (object2 anchored-period)) (and (time> (onset object1) (onset object2)) (time< (cut-off object2) (cut-off object2)))) (defmethod starts ((object1 anchored-period) (object2 anchored-period)) (time= (onset object1) (onset object2))) (defmethod ends ((object1 anchored-period) (object2 anchored-period)) (time= (cut-off object1) (cut-off object2))) ;; ...and (defmethod period-intersection ((object1 anchored-period) (object2 anchored-period)) (cond ((disjoint object1 object2) ;; if they don't overlap, return nil, not a negative-valued ;; period nil) (t (let ((new-onset (max (onset object1) (onset object2)))) (make-anchored-period new-onset (time- (min (cut-off object1) (cut-off object2)) new-onset))))))