annotate implementations/geerdes/constructors.lisp @ 279:c591a5034da6

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