Mercurial > hg > amuse
changeset 19:2f331bbdfab8
Added preliminary support for time- and key-signatures and for tempi
darcs-hash:20061213155334-f76cc-a1ece6adfd1e6292e1f67418ddb3f38a56ad2233.gz
author | David Lewis <d.lewis@gold.ac.uk> |
---|---|
date | Wed, 13 Dec 2006 15:53:34 +0000 |
parents | 70e76c1c87b7 |
children | 6eb54ad3b8b4 |
files | classes.lisp constructors.lisp generics.lisp methods.lisp package.lisp |
diffstat | 5 files changed, 182 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/classes.lisp Wed Dec 13 11:40:49 2006 +0000 +++ b/classes.lisp Wed Dec 13 15:53:34 2006 +0000 @@ -40,9 +40,56 @@ (defclass pitch-interval (pitch-interval-designator) ((span :accessor %pitch-interval-span :initarg :span))) +(defclass midi-message () ;? + ((channel :accessor %midi-message-channel :initarg :channel) + (track :accessor %midi-message-track :initarg :track))) + ;; events (defclass event (anchored-period) ()) (defclass pitched-event (event pitch-designator) ()) -(defclass midi-pitched-event (pitched-event chromatic-pitch) ()) +(defclass chromatic-pitched-event (pitched-event chromatic-pitch) ()) +(defclass midi-pitched-event (chromatic-pitched-event midi-message) + ((velocity :initarg :velocity) + (patch :initarg :patch))) (defclass percussive-event (event) ()) +(defclass midi-percussive-event (percussive-event midi-message) + ((velocity :initarg :velocity) + (patch :initarg :patch) + (sound :initarg :sound))) + +;;; Range-based `constituents' +;; Whilst these are all constituents in the CHARM sense, their +;; properties apply to a timed range rather than to a set of +;; events. As such, they can be regarded as anchored-periods with +;; properties. + +(defclass time-signature (anchored-period) ()) + +(defclass basic-time-signature (anchored-period) + ;; N.B. Can only deal with numeric signatures + ((numerator :accessor %basic-time-signature-numerator + :initarg :numerator) + (denominator :accessor %basic-time-signature-denominator + :initarg :denominator))) + +(defclass key-signature (anchored-period) ()) + +(defclass basic-key-signature (key-signature) + ;; Only has line-of-fifths distance from c, so custom signatures + ;; won't work + ((sharp-count :accessor %basic-key-signature-sharp-count + :initarg sharp-count))) + +(defclass midi-key-signature (basic-key-signature) + ;; Is mode ever used in real life? Is it ever accurately used in + ;; real life? + ((mode :accessor %midi-key-signature-mode + :initarg mode))) + +(defclass tempo (anchored-period) + ;; accel and rit in symbolic encoding will need other structures, as + ;; will textual tempo markings. + ((bpm :accessor %tempo-bpm + :initarg :bpm))) + \ No newline at end of file
--- a/constructors.lisp Wed Dec 13 11:40:49 2006 +0000 +++ b/constructors.lisp Wed Dec 13 15:53:34 2006 +0000 @@ -32,8 +32,56 @@ ;; Events -(defun make-midi-pitched-event (pitch-number onset duration) +(defun make-chromatic-pitched-event (pitch-number onset duration) + (make-instance 'chromatic-pitched-event + :number pitch-number + :time onset + :interval duration)) + +(defun make-midi-pitched-event (pitch-number velocity patch + channel track onset duration) (make-instance 'midi-pitched-event :number pitch-number + :velocity velocity + :patch patch + :channel channel + :track track :time onset - :interval duration)) \ No newline at end of file + :interval duration)) + +(defun make-midi-percussive-event (pitch-number velocity patch + channel track onset duration) + (make-instance 'midi-percussive-event + :sound pitch-number + :velocity velocity + :patch patch + :channel channel + :track track + :time onset + :interval duration)) + +(defun make-basic-time-signature (numerator denominator onset duration) + (make-instance 'basic-time-signature + :numerator numerator + :denominator denominator + :time onset + :interval duration)) + +(defun make-basic-key-signature (sharp-count onset duration) + (make-instance 'basic-key-signature + :sharp-count sharp-count + :time onset + :interval duration)) + +(defun make-midi-key-signature (sharp-count mode onset duration) + (make-instance 'midi-key-signature + :sharp-count sharp-count + :mode mode + :time onset + :interval duration)) + +(defun make-tempo (bpm onset duration) + (make-instance 'tempo + :bpm bpm + :time onset + :interval duration))
--- a/generics.lisp Wed Dec 13 11:40:49 2006 +0000 +++ b/generics.lisp Wed Dec 13 15:53:34 2006 +0000 @@ -6,6 +6,8 @@ ;;; Simple Accessors +;; pitch-based + (defgeneric pitch (object &key kind)) ; ? Maybe this returns the pitch ; in its ur form? (defgeneric chromatic-pitch (pitch-designator)) ; How simple are these @@ -14,11 +16,13 @@ (defgeneric chromatic-pitch-number (pitch-designator)) (defgeneric meredith-chromatic-pitch-number (pitch-designator) ;; David Meredith's PhD and ps13 code - (:method (p) (- (midi-chromatic-pitch-number p) 21))) + (:method (p) (- (chromatic-pitch-number p) 21))) (defgeneric pitch-class (pitch-designator) (:method (p) (mod (chromatic-pitch-number p) 12))) (defgeneric span (pitch-interval-designator)) +;; time + (defgeneric duration (period-designator)) (defgeneric (setf duration) (value period-designator)) (defgeneric timepoint (moment-designator)) @@ -29,6 +33,28 @@ (defgeneric cut-off (anchored-period-designator) ; name? (:method (apd) (time+ (moment apd) (floating-period apd)))) +;; others + +;; I've given the time-sig accessors general names because it allows +;; for symbols in time-signatures as well as numbers - numerator is an +;; odd accessor if the time sig is C (even in common practice) but +;; it's meaning is clear. beat-units-per-bar is clearer, though, I +;; think. + +(defgeneric beat-units-per-bar (time-signature)) +(defgeneric time-signature-numerator (time-signature) + (:method (ts) (beat-units-per-bar ts))) +(defgeneric beat-units (time-signature)) +(defgeneric time-signature-denominator (time-signature) + (:method (ts) (beat-units ts))) + +(defgeneric key-signature-sharps (key-signature)) + +(defgeneric bpm (tempo)) ;; in bpm +(defgeneric microseconds-per-crotchet (tempo) + ;; As used (when rounded) in MIDI + (:method (tp) (/ 60000000 (bpm tp)))) + ;;; Coerce-type accessors ;; Should I be including these default methods? Should the accessors @@ -161,8 +187,17 @@ ;;; Time Signature + +(defgeneric get-applicable-time-signatures (object1 object2)) + ;;; Tempo + +(defgeneric get-applicable-tempi (object1 object2)) + ;;; Tonality (Key Signature / Mode) + +(defgeneric get-applicable-key-signatures (object1 object2)) + ;;; Dynamics ;;; Voice ;;; Boundary Strength (phrasing)
--- a/methods.lisp Wed Dec 13 11:40:49 2006 +0000 +++ b/methods.lisp Wed Dec 13 15:53:34 2006 +0000 @@ -1,14 +1,5 @@ (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)) - (defmethod chromatic-pitch ((pitch-designator chromatic-pitch)) pitch-designator) @@ -18,6 +9,27 @@ (defmethod chromatic-pitch-number ((pitch-designator pitch)) (%chromatic-pitch-number (chromatic-pitch pitch-designator))) +(defmethod span ((pitch-interval-designator pitch-interval)) + (%pitch-interval-span pitch-interval-designator)) + +(defmethod duration ((period-designator period)) + (%period-interval period-designator)) + +(defmethod timepoint ((moment-designator moment)) + (%moment-time moment-designator)) + +(defmethod beat-units-per-bar ((time-signature basic-time-signature)) + (%basic-time-signature-numerator time-signature)) + +(defmethod beat-units ((time-signature basic-time-signature)) + (%basic-time-signature-denominator time-signature)) + +(defmethod key-signature-sharps ((key-signature basic-key-signature)) + (%basic-key-signature-sharp-count key-signature)) + +(defmethod bpm ((tempo tempo)) + (%tempo-bpm tempo)) + ;; Time protocol (defmethod time+ ((object1 moment) (object2 period))
--- a/package.lisp Wed Dec 13 11:40:49 2006 +0000 +++ b/package.lisp Wed Dec 13 15:53:34 2006 +0000 @@ -18,8 +18,16 @@ #:diatonic-pitch #:pitch-interval #:pitched-event + #:chromatic-pitched-event #:midi-pitched-event #:percussive-event + #:midi-percussive-event + #:time-signature + #:basic-time-signature + #:key-signature + #:basic-key-signature + #:midi-key-signature + #:tempo #:get-composition #:chromatic-pitch #:diatonic-pitch @@ -31,6 +39,13 @@ #:timepoint #:onset #:cut-off + #:beat-units-per-bar + #:time-signature-numerator + #:beat-units + #:time-signature-denominator + #:key-signature-sharps + #:bpm + #:microseconds-per-crotchet #:anchored-period #:floating-period #:moment @@ -74,10 +89,21 @@ #:disjoint #:period-intersection #:inter-onset-interval + #:get-applicable-time-signatures + #:get-applicable-tempi + #:get-applicable-key-signatures #:make-moment #:make-floating-period #:make-anchored-period #:make-chromatic-pitch #:make-diatonic-pitch #:make-pitch-interval - #:make-midi-pitched-event)) \ No newline at end of file + #:make-chromatic-pitched-event + #:make-midi-pitched-event + #:make-midi-percussive-event + #:make-basic-time-signature + #:make-basic-key-signature + #:make-midi-key-signature + #:make-tempo + +)) \ No newline at end of file