j@236: (cl:in-package #:amuse-midi-db) j@236: j@236: (defmethod get-composition ((identifier midi-db-composition-identifier)) j@236: (let ((database *amuse-database*)) ; Shaddow this to use a different j@236: ; database (for debugging). j@236: (destructuring-bind (collection-id filename timebase start j@236: duration owner version j@236: creation-timestamp j@236: deletion-timestamp) j@236: (%get-midi-db-composition-header identifier database) j@236: (let* ((collection-identifier (make-midi-db-collection-identifier j@236: collection-id)) j@236: (events (%get-midi-db-events identifier j@236: collection-identifier j@236: version timebase database)) j@236: (tempi (%get-midi-db-tempi identifier j@236: collection-identifier version j@236: timebase database)) j@236: (timesigs (%get-midi-db-timesigs identifier j@236: collection-identifier j@236: version timebase database)) j@236: (keysigs (%get-midi-db-keysigs identifier j@236: collection-identifier j@236: version timebase database))) j@236: (make-midi-db-composition events j@236: (/ start timebase) j@236: (/ duration timebase) j@236: tempi j@236: timesigs j@236: keysigs j@236: identifier j@236: collection-identifier j@236: timebase j@236: filename j@236: owner j@236: version j@236: creation-timestamp j@236: deletion-timestamp))))) j@236: j@236: j@236: (defun %get-all-collection-headers () j@236: #.(clsql:locally-enable-sql-reader-syntax) j@236: (let ((collection-rows (clsql:select [collection-id] j@236: [collection-name] [description] j@236: :from "midi_db_collections" j@236: :flatp t j@236: :database *amuse-database*))) j@236: #.(clsql:locally-disable-sql-reader-syntax) collection-rows)) j@236: j@236: (defun %get-midi-db-composition-header (identifier database) j@236: "Basic low-level retrieval of constituents. Just takes an identifier j@236: and returns a header without any checking of version or deletion j@236: fields." j@236: #.(clsql:locally-enable-sql-reader-syntax) j@236: (let ((header-row (car (clsql:select j@236: [collection-id] j@236: [filename] j@236: [timebase] j@236: [start] j@236: [duration] j@236: [owner] j@236: [version] j@236: [creation-timestamp] j@236: [deletion-timestamp] j@236: :from "midi_db_compositions" j@236: :where [= [composition-id] j@236: (composition-id identifier)] j@236: :flatp t j@236: :database database)))) j@236: #.(clsql:locally-disable-sql-reader-syntax) j@236: header-row)) j@236: j@236: (defun %get-all-collection-composition-headers (collection-identifier) j@236: #.(clsql:locally-enable-sql-reader-syntax) j@236: (let ((header-rows (clsql:select j@236: [collection-id] j@241: [composition-id] j@236: [filename] j@236: [timebase] j@236: [start] j@236: [duration] j@236: [owner] j@236: [version] j@236: [creation-timestamp] j@236: [deletion-timestamp] j@236: :from "midi_db_compositions" j@236: :where [= [collection-id] (collection-id j@236: collection-identifier)] j@236: :flatp t j@236: :database *amuse-database*))) j@236: #.(clsql:locally-disable-sql-reader-syntax) j@236: header-rows)) j@236: j@236: (defun %get-all-composition-headers () j@236: #.(clsql:locally-enable-sql-reader-syntax) j@236: (let ((header-rows (clsql:select j@236: [collection-id] j@241: [composition-id] j@236: [filename] j@236: [timebase] j@236: [start] j@236: [duration] j@236: [owner] j@236: [version] j@236: [creation-timestamp] j@236: [deletion-timestamp] j@236: :from "midi_db_compositions" j@236: :flatp t j@236: :database *amuse-database*))) j@236: #.(clsql:locally-disable-sql-reader-syntax) j@236: header-rows)) j@236: j@236: (defun %get-midi-db-events (identifier collection-identifier version j@236: timebase database) j@236: (let ((event-rows (clsql:query (concatenate 'string " j@236: SELECT event_id, track, channel, patch, pitch, velocity, start, duration, j@236: version j@236: FROM midi_db_events j@236: WHERE collection_id = " (princ-to-string (collection-id collection-identifier)) " j@236: AND composition_id= " (princ-to-string (composition-id identifier)) " j@236: AND version = " (princ-to-string version)) j@236: :flatp t j@236: :database database))) j@236: (%init-events identifier collection-identifier event-rows timebase))) j@236: j@236: (defun %init-events (identifier collection-identifier event-rows timebase) j@236: (loop for event-row in event-rows j@236: collecting (init-midi-db-event identifier collection-identifier event-row timebase) j@236: into events j@236: finally (return events))) j@236: j@236: (defun init-midi-db-event (identifier collection-identifier event-row timebase) j@236: (destructuring-bind (event-id track channel patch pitch velocity j@236: start duration version) j@236: event-row j@236: (if (= channel 10) j@236: (make-midi-db-percussive-event (collection-id collection-identifier) j@236: (composition-id identifier) j@236: event-id track channel patch j@236: pitch velocity j@236: (/ start timebase) j@236: (/ duration timebase) version) j@236: (make-midi-db-pitched-event (collection-id collection-identifier) j@236: (composition-id identifier) j@236: event-id track channel patch pitch j@236: velocity (/ start timebase) j@236: (/ duration timebase) version)))) j@236: j@236: (defun %get-midi-db-tempi (identifier collection-identifier version j@236: timebase database) j@236: (declare (ignore version)) j@236: (let ((tempo-rows (clsql:query (concatenate 'string " j@236: SELECT start, duration, microsecs_per_crotchet, version j@236: FROM midi_db_tempi j@236: WHERE collection_id = " (princ-to-string (collection-id collection-identifier)) " j@236: AND composition_id = " (princ-to-string (composition-id identifier))) j@236: ;AND version = " (princ-to-string version)) j@236: :flatp t j@236: :database database))) j@236: (%init-midi-db-tempi tempo-rows timebase))) j@236: j@236: (defun %init-midi-db-tempi (tempo-rows timebase) j@236: (loop for tempo-row in tempo-rows j@236: collecting (init-midi-db-tempo tempo-row timebase) j@236: into tempi j@236: finally (return tempi))) j@236: j@236: (defun init-midi-db-tempo (tempo-row timebase) j@236: (destructuring-bind (start duration microsecs-per-crotchet version) j@236: tempo-row j@236: (make-midi-db-tempo (/ start timebase) (/ duration timebase) j@236: microsecs-per-crotchet version))) j@236: j@236: (defun %get-midi-db-timesigs (identifier collection-identifier version j@236: timebase database) j@236: (declare (ignore version)) j@236: (let ((timesig-rows (clsql:query (concatenate 'string " j@236: SELECT start, duration, numerator, denominator, version j@236: FROM midi_db_timesigs j@236: WHERE collection_id = " (princ-to-string (collection-id collection-identifier)) " j@236: AND composition_id = " (princ-to-string (composition-id identifier))) j@236: ;AND version = " (princ-to-string version)) j@236: :flatp t j@236: :database database))) j@236: (%init-midi-db-timesigs timesig-rows timebase))) j@236: j@236: (defun %init-midi-db-timesigs (timesig-rows timebase) j@236: (loop for timesig-row in timesig-rows j@236: collecting (init-midi-db-timesig timesig-row timebase) j@236: into timesigs j@236: finally (return timesigs))) j@236: j@236: (defun init-midi-db-timesig (timesig-row timebase) j@236: (destructuring-bind (start duration numerator denominator version) j@236: timesig-row j@236: (make-midi-db-timesig (/ start timebase) (/ duration timebase) j@236: numerator denominator version))) j@236: j@236: (defun %get-midi-db-keysigs (identifier collection-identifier version j@236: timebase database) j@236: (declare (ignore version)) j@236: (let ((keysig-rows (clsql:query (concatenate 'string " j@236: SELECT start, duration, mode, sharp_count, version j@236: FROM midi_db_keysigs j@236: WHERE collection_id = " (princ-to-string (collection-id collection-identifier)) " j@236: AND composition_id = " (princ-to-string (composition-id identifier))) j@236: ;AND version = " (princ-to-string version)) j@236: :flatp t j@236: :database database))) j@236: (%init-midi-db-keysigs keysig-rows timebase))) j@236: j@236: (defun %init-midi-db-keysigs (keysig-rows timebase) j@236: (loop for keysig-row in keysig-rows j@236: collecting (init-midi-db-keysig keysig-row timebase) j@236: into keysigs j@236: finally (return keysigs))) j@236: j@236: (defun init-midi-db-keysig (keysig-row timebase) j@236: (destructuring-bind (start duration mode sharp-count version) j@236: keysig-row j@236: (make-midi-db-keysig (/ start timebase) (/ duration timebase) j@236: mode sharp-count version)))