annotate implementations/geerdes/constructors.lisp @ 88:8ea75cc8bc2c

Basic geerdes functionality moved to implementations/geerdes from separate package darcs-hash:20070720161242-f76cc-fd256cbbb81d8c418a6c7c45844264184c5ed932.gz
author David Lewis <d.lewis@gold.ac.uk>
date Fri, 20 Jul 2007 17:12:42 +0100
parents
children d041118612d4
rev   line source
d@88 1 (cl:in-package #:amuse-geerdes)
d@88 2
d@88 3 (defgeneric %initialise-notes (composition))
d@88 4 (defmethod %initialise-notes ((composition geerdes-composition))
d@88 5 (let ((notes) (l 0) (last-time 0) (monody-notes)
d@88 6 (monody (make-instance 'geerdes-monody :file-id (file-id composition)))
d@88 7 (timebase (%midi-timebase composition)))
d@88 8 (dolist (row (%midi-events composition))
d@88 9 (let* ((note (if (pitched-row-p row)
d@88 10 (make-geerdes-pitched-event (%fast-pitch row)
d@88 11 (%fast-velocity row)
d@88 12 (%fast-patch row)
d@88 13 (%fast-channel row)
d@88 14 (%fast-track row)
d@88 15 (%fast-onset row timebase)
d@88 16 (%fast-duration row timebase)
d@88 17 (%fast-id row))
d@88 18 (make-geerdes-percussive-event (%fast-pitch row)
d@88 19 (%fast-velocity row)
d@88 20 (%fast-patch row)
d@88 21 (%fast-channel row)
d@88 22 (%fast-track row)
d@88 23 (%fast-onset row timebase)
d@88 24 (%fast-duration row timebase)
d@88 25 (%fast-id row)))))
d@88 26 (when (%fast-monodyp row)
d@88 27 (push note monody-notes))
d@88 28 (when (> (timepoint (cut-off note)) last-time)
d@88 29 (setf last-time (timepoint (cut-off note))))
d@88 30 (push note notes)
d@88 31 (incf l)))
d@88 32 (sequence:adjust-sequence composition l :initial-contents (reverse notes))
d@88 33 (setf (duration composition) last-time
d@88 34 (timepoint composition) 0)
d@88 35 (when monody-notes
d@88 36 (setf (%monody composition) (sequence:adjust-sequence monody (length monody-notes)
d@88 37 :initial-contents (reverse monody-notes))
d@88 38 (timepoint (%monody composition)) (timepoint (elt monody 0))
d@88 39 (duration (%monody composition)) (- (timepoint (cut-off (car monody-notes)))
d@88 40 (timepoint (elt monody 0)))))
d@88 41 composition))
d@88 42
d@88 43 (defgeneric %initialise-constituents (composition))
d@88 44 (defmethod %initialise-constituents ((composition geerdes-composition))
d@88 45 ;; FIXME: Should the duration of composition be affected by this? On
d@88 46 ;; the one hand, it makes no difference to the musical content, but
d@88 47 ;; on the other, it seems illogical to reach outside the period.
d@88 48 (let ((timebase (%midi-timebase composition))
d@88 49 (time-sigs)
d@88 50 (tempi)
d@88 51 (mystery 0))
d@88 52 (dolist (row (%midi-constituents composition))
d@88 53 (cond
d@88 54 ((%fast-tempo row)
d@88 55 (push (make-tempo
d@88 56 (microsecond-per-crotchet-to-bpm
d@88 57 (%fast-tempo row))
d@88 58 (%fast-onset row timebase)
d@88 59 (%fast-duration row timebase))
d@88 60 tempi))
d@88 61 ((%fast-numerator row)
d@88 62 (push (make-basic-time-signature
d@88 63 (%fast-numerator row)
d@88 64 (%fast-denominator row)
d@88 65 (%fast-onset row timebase)
d@88 66 (%fast-duration row timebase))
d@88 67 time-sigs))
d@88 68 (t (incf mystery))))
d@88 69 (setf (time-signatures composition) (reverse time-sigs)
d@88 70 (tempi composition) (reverse tempi))
d@88 71 (when (%monody composition)
d@88 72 (setf (time-signatures (%monody composition)) (time-signatures composition)
d@88 73 (tempi (%monody composition)) (tempi composition)))
d@88 74 (format t "There are ~D constituents not processed~%" mystery)
d@88 75 composition))
d@88 76
d@88 77 (defun %fast-track (row)
d@88 78 (first row))
d@88 79 (defun %fast-channel (row)
d@88 80 (second row))
d@88 81 (defun %fast-onset (row timebase)
d@88 82 (/ (third row) timebase))
d@88 83 (defun %fast-duration (row timebase)
d@88 84 (/ (fourth row) timebase))
d@88 85 (defun %fast-patch (event-row)
d@88 86 (fifth event-row))
d@88 87 (defun %fast-pitch (event-row)
d@88 88 (sixth event-row))
d@88 89 (defun %fast-velocity (event-row)
d@88 90 (seventh event-row))
d@88 91 (defun %fast-id (event-row)
d@88 92 (eighth event-row))
d@88 93 (defun %fast-monodyp (event-row)
d@88 94 (ninth event-row))
d@88 95
d@88 96 (defun %fast-tempo (tp-row)
d@88 97 (eighth tp-row))
d@88 98 (defun %fast-numerator (ts-row)
d@88 99 (ninth ts-row))
d@88 100 (defun %fast-denominator (ts-row)
d@88 101 (tenth ts-row))
d@88 102
d@88 103 (defun pitched-row-p (event-row)
d@88 104 (and (not (= (%fast-channel event-row) 10))
d@88 105 (< (%fast-patch event-row) 112)))
d@88 106
d@88 107 (defun make-geerdes-pitched-event (pitch-number velocity patch
d@88 108 channel track onset duration id)
d@88 109 (make-instance 'geerdes-pitched-event
d@88 110 :number pitch-number
d@88 111 :velocity velocity
d@88 112 :patch patch
d@88 113 :channel channel
d@88 114 :track track
d@88 115 :time onset
d@88 116 :interval duration
d@88 117 :id id))
d@88 118
d@88 119 (defun make-geerdes-percussive-event (pitch-number velocity patch
d@88 120 channel track onset duration id)
d@88 121 (make-instance 'geerdes-percussive-event
d@88 122 :sound pitch-number
d@88 123 :velocity velocity
d@88 124 :patch patch
d@88 125 :channel channel
d@88 126 :track track
d@88 127 :time onset
d@88 128 :interval duration
d@88 129 :id id))
d@88 130
d@88 131 (defgeneric copy-event (event))
d@88 132 (defmethod copy-event ((event geerdes-pitched-event))
d@88 133 (with-slots ((channel amuse-midi::channel)
d@88 134 (track amuse-midi::track)
d@88 135 (number amuse::number)
d@88 136 (time amuse::time)
d@88 137 (interval amuse::interval)
d@88 138 (velocity amuse-midi::velocity)
d@88 139 (patch amuse-midi::patch) id)
d@88 140 event
d@88 141 (make-instance 'geerdes-pitched-event
d@88 142 :channel channel
d@88 143 :track track
d@88 144 :number number
d@88 145 :time time
d@88 146 :interval interval
d@88 147 :velocity velocity
d@88 148 :patch patch
d@88 149 :id id)))
d@88 150 (defmethod copy-event ((event geerdes-percussive-event))
d@88 151 (with-slots ((channel amuse-midi::channel)
d@88 152 (track amuse-midi::track)
d@88 153 (time amuse::time)
d@88 154 (interval amuse::interval)
d@88 155 (velocity amuse-midi::velocity)
d@88 156 (patch amuse-midi::patch)
d@88 157 (sound amuse-midi::sound) id)
d@88 158 event
d@88 159 (make-instance 'geerdes-percussive-event
d@88 160 :channel channel
d@88 161 :track track
d@88 162 :time time
d@88 163 :interval interval
d@88 164 :velocity velocity
d@88 165 :patch patch
d@88 166 :sound sound
d@88 167 :id id)))
d@88 168
d@88 169 ;; We want any function that generates a sequence from a geerdes
d@88 170 ;; composition to preserve all slot values:
d@88 171 (defmethod sequence:make-sequence-like :around ((o geerdes-composition)
d@88 172 length
d@88 173 &key (initial-element nil iep)
d@88 174 (initial-contents nil icp))
d@88 175 (declare (ignore iep icp length initial-element initial-contents))
d@88 176 (let ((result (call-next-method)))
d@88 177 (setf (%db-entry result) (%db-entry o))
d@88 178 result))