annotate implementations/midi-db/db-select-functions.lisp @ 330:2fbff655ba47 tip

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