annotate implementations/midi-db/db-select-functions.lisp @ 253:b5ffec94ae6d

some very sketchy Charm constituent code
author Jamie Forth <j.forth@gold.ac.uk>
date Thu, 24 Feb 2011 11:23:18 +0000
parents 2138ea478adb
children
rev   line source
j@236 1 (cl:in-package #:amuse-midi-db)
j@236 2
j@236 3 (defmethod get-composition ((identifier midi-db-composition-identifier))
j@236 4 (let ((database *amuse-database*)) ; Shaddow this to use a different
j@236 5 ; database (for debugging).
j@236 6 (destructuring-bind (collection-id filename timebase start
j@236 7 duration owner version
j@236 8 creation-timestamp
j@236 9 deletion-timestamp)
j@236 10 (%get-midi-db-composition-header identifier database)
j@236 11 (let* ((collection-identifier (make-midi-db-collection-identifier
j@236 12 collection-id))
j@236 13 (events (%get-midi-db-events identifier
j@236 14 collection-identifier
j@236 15 version timebase database))
j@236 16 (tempi (%get-midi-db-tempi identifier
j@236 17 collection-identifier version
j@236 18 timebase database))
j@236 19 (timesigs (%get-midi-db-timesigs identifier
j@236 20 collection-identifier
j@236 21 version timebase database))
j@236 22 (keysigs (%get-midi-db-keysigs identifier
j@236 23 collection-identifier
j@236 24 version timebase database)))
j@236 25 (make-midi-db-composition events
j@236 26 (/ start timebase)
j@236 27 (/ duration timebase)
j@236 28 tempi
j@236 29 timesigs
j@236 30 keysigs
j@236 31 identifier
j@236 32 collection-identifier
j@236 33 timebase
j@236 34 filename
j@236 35 owner
j@236 36 version
j@236 37 creation-timestamp
j@236 38 deletion-timestamp)))))
j@236 39
j@236 40
j@236 41 (defun %get-all-collection-headers ()
j@236 42 #.(clsql:locally-enable-sql-reader-syntax)
j@236 43 (let ((collection-rows (clsql:select [collection-id]
j@236 44 [collection-name] [description]
j@236 45 :from "midi_db_collections"
j@236 46 :flatp t
j@236 47 :database *amuse-database*)))
j@236 48 #.(clsql:locally-disable-sql-reader-syntax) collection-rows))
j@236 49
j@236 50 (defun %get-midi-db-composition-header (identifier database)
j@236 51 "Basic low-level retrieval of constituents. Just takes an identifier
j@236 52 and returns a header without any checking of version or deletion
j@236 53 fields."
j@236 54 #.(clsql:locally-enable-sql-reader-syntax)
j@236 55 (let ((header-row (car (clsql:select
j@236 56 [collection-id]
j@236 57 [filename]
j@236 58 [timebase]
j@236 59 [start]
j@236 60 [duration]
j@236 61 [owner]
j@236 62 [version]
j@236 63 [creation-timestamp]
j@236 64 [deletion-timestamp]
j@236 65 :from "midi_db_compositions"
j@236 66 :where [= [composition-id]
j@236 67 (composition-id identifier)]
j@236 68 :flatp t
j@236 69 :database database))))
j@236 70 #.(clsql:locally-disable-sql-reader-syntax)
j@236 71 header-row))
j@236 72
j@236 73 (defun %get-all-collection-composition-headers (collection-identifier)
j@236 74 #.(clsql:locally-enable-sql-reader-syntax)
j@236 75 (let ((header-rows (clsql:select
j@236 76 [collection-id]
j@241 77 [composition-id]
j@236 78 [filename]
j@236 79 [timebase]
j@236 80 [start]
j@236 81 [duration]
j@236 82 [owner]
j@236 83 [version]
j@236 84 [creation-timestamp]
j@236 85 [deletion-timestamp]
j@236 86 :from "midi_db_compositions"
j@236 87 :where [= [collection-id] (collection-id
j@236 88 collection-identifier)]
j@236 89 :flatp t
j@236 90 :database *amuse-database*)))
j@236 91 #.(clsql:locally-disable-sql-reader-syntax)
j@236 92 header-rows))
j@236 93
j@236 94 (defun %get-all-composition-headers ()
j@236 95 #.(clsql:locally-enable-sql-reader-syntax)
j@236 96 (let ((header-rows (clsql:select
j@236 97 [collection-id]
j@241 98 [composition-id]
j@236 99 [filename]
j@236 100 [timebase]
j@236 101 [start]
j@236 102 [duration]
j@236 103 [owner]
j@236 104 [version]
j@236 105 [creation-timestamp]
j@236 106 [deletion-timestamp]
j@236 107 :from "midi_db_compositions"
j@236 108 :flatp t
j@236 109 :database *amuse-database*)))
j@236 110 #.(clsql:locally-disable-sql-reader-syntax)
j@236 111 header-rows))
j@236 112
j@236 113 (defun %get-midi-db-events (identifier collection-identifier version
j@236 114 timebase database)
j@236 115 (let ((event-rows (clsql:query (concatenate 'string "
j@236 116 SELECT event_id, track, channel, patch, pitch, velocity, start, duration,
j@236 117 version
j@236 118 FROM midi_db_events
j@236 119 WHERE collection_id = " (princ-to-string (collection-id collection-identifier)) "
j@236 120 AND composition_id= " (princ-to-string (composition-id identifier)) "
j@236 121 AND version = " (princ-to-string version))
j@236 122 :flatp t
j@236 123 :database database)))
j@236 124 (%init-events identifier collection-identifier event-rows timebase)))
j@236 125
j@236 126 (defun %init-events (identifier collection-identifier event-rows timebase)
j@236 127 (loop for event-row in event-rows
j@236 128 collecting (init-midi-db-event identifier collection-identifier event-row timebase)
j@236 129 into events
j@236 130 finally (return events)))
j@236 131
j@236 132 (defun init-midi-db-event (identifier collection-identifier event-row timebase)
j@236 133 (destructuring-bind (event-id track channel patch pitch velocity
j@236 134 start duration version)
j@236 135 event-row
j@236 136 (if (= channel 10)
j@236 137 (make-midi-db-percussive-event (collection-id collection-identifier)
j@236 138 (composition-id identifier)
j@236 139 event-id track channel patch
j@236 140 pitch velocity
j@236 141 (/ start timebase)
j@236 142 (/ duration timebase) version)
j@236 143 (make-midi-db-pitched-event (collection-id collection-identifier)
j@236 144 (composition-id identifier)
j@236 145 event-id track channel patch pitch
j@236 146 velocity (/ start timebase)
j@236 147 (/ duration timebase) version))))
j@236 148
j@236 149 (defun %get-midi-db-tempi (identifier collection-identifier version
j@236 150 timebase database)
j@236 151 (declare (ignore version))
j@236 152 (let ((tempo-rows (clsql:query (concatenate 'string "
j@236 153 SELECT start, duration, microsecs_per_crotchet, version
j@236 154 FROM midi_db_tempi
j@236 155 WHERE collection_id = " (princ-to-string (collection-id collection-identifier)) "
j@236 156 AND composition_id = " (princ-to-string (composition-id identifier)))
j@236 157 ;AND version = " (princ-to-string version))
j@236 158 :flatp t
j@236 159 :database database)))
j@236 160 (%init-midi-db-tempi tempo-rows timebase)))
j@236 161
j@236 162 (defun %init-midi-db-tempi (tempo-rows timebase)
j@236 163 (loop for tempo-row in tempo-rows
j@236 164 collecting (init-midi-db-tempo tempo-row timebase)
j@236 165 into tempi
j@236 166 finally (return tempi)))
j@236 167
j@236 168 (defun init-midi-db-tempo (tempo-row timebase)
j@236 169 (destructuring-bind (start duration microsecs-per-crotchet version)
j@236 170 tempo-row
j@236 171 (make-midi-db-tempo (/ start timebase) (/ duration timebase)
j@236 172 microsecs-per-crotchet version)))
j@236 173
j@236 174 (defun %get-midi-db-timesigs (identifier collection-identifier version
j@236 175 timebase database)
j@236 176 (declare (ignore version))
j@236 177 (let ((timesig-rows (clsql:query (concatenate 'string "
j@236 178 SELECT start, duration, numerator, denominator, version
j@236 179 FROM midi_db_timesigs
j@236 180 WHERE collection_id = " (princ-to-string (collection-id collection-identifier)) "
j@236 181 AND composition_id = " (princ-to-string (composition-id identifier)))
j@236 182 ;AND version = " (princ-to-string version))
j@236 183 :flatp t
j@236 184 :database database)))
j@236 185 (%init-midi-db-timesigs timesig-rows timebase)))
j@236 186
j@236 187 (defun %init-midi-db-timesigs (timesig-rows timebase)
j@236 188 (loop for timesig-row in timesig-rows
j@236 189 collecting (init-midi-db-timesig timesig-row timebase)
j@236 190 into timesigs
j@236 191 finally (return timesigs)))
j@236 192
j@236 193 (defun init-midi-db-timesig (timesig-row timebase)
j@236 194 (destructuring-bind (start duration numerator denominator version)
j@236 195 timesig-row
j@236 196 (make-midi-db-timesig (/ start timebase) (/ duration timebase)
j@236 197 numerator denominator version)))
j@236 198
j@236 199 (defun %get-midi-db-keysigs (identifier collection-identifier version
j@236 200 timebase database)
j@236 201 (declare (ignore version))
j@236 202 (let ((keysig-rows (clsql:query (concatenate 'string "
j@236 203 SELECT start, duration, mode, sharp_count, version
j@236 204 FROM midi_db_keysigs
j@236 205 WHERE collection_id = " (princ-to-string (collection-id collection-identifier)) "
j@236 206 AND composition_id = " (princ-to-string (composition-id identifier)))
j@236 207 ;AND version = " (princ-to-string version))
j@236 208 :flatp t
j@236 209 :database database)))
j@236 210 (%init-midi-db-keysigs keysig-rows timebase)))
j@236 211
j@236 212 (defun %init-midi-db-keysigs (keysig-rows timebase)
j@236 213 (loop for keysig-row in keysig-rows
j@236 214 collecting (init-midi-db-keysig keysig-row timebase)
j@236 215 into keysigs
j@236 216 finally (return keysigs)))
j@236 217
j@236 218 (defun init-midi-db-keysig (keysig-row timebase)
j@236 219 (destructuring-bind (start duration mode sharp-count version)
j@236 220 keysig-row
j@236 221 (make-midi-db-keysig (/ start timebase) (/ duration timebase)
j@236 222 mode sharp-count version)))