annotate implementations/midi-db/db-setup.lisp @ 236:a5d065905f6d

Add midi-db. Ignore-this: c6f4fc32efa4453ddbdc478793eedd52 A basic implementation for working with MIDI files stored in the database. It is a test case for `versioned' data, but only partially implemented at the moment. darcs-hash:20100223152703-16a00-4388d2720907d777a1c6c6b3a010885ce0fe06a7.gz committer: Jamie Forth <j.forth@gold.ac.uk>
author j.forth <j.forth@gold.ac.uk>
date Thu, 24 Feb 2011 11:23:18 +0000
parents
children
rev   line source
j@236 1 (cl:in-package #:amuse-midi-db)
j@236 2
j@236 3 ;; Creating tables
j@236 4
j@236 5 (defun create-midi-db-tables (database)
j@236 6 (%create-midi-collections-table database)
j@236 7 (%create-midi-compositions-table database)
j@236 8 (%create-midi-events-table database)
j@236 9 (%create-midi-tempi-table database)
j@236 10 (%create-midi-timesigs-table database)
j@236 11 (%create-midi-keysigs-table database))
j@236 12
j@236 13 (defun %create-midi-collections-table (database)
j@236 14 #.(clsql:locally-enable-sql-reader-syntax)
j@236 15 (clsql:create-table "midi_db_collections"
j@236 16 '(([|collection-id|] clsql:smallint :unsigned
j@236 17 :not-null :auto-increment :primary-key)
j@236 18 ([|collection-name|] (clsql:varchar 255)
j@236 19 :not-null)
j@236 20 ([|description|] (clsql:varchar 255)
j@236 21 :not-null))
j@236 22 :database database
j@236 23 :transactions t)
j@236 24 #.(clsql:locally-disable-sql-reader-syntax))
j@236 25
j@236 26 (defun %create-midi-compositions-table (database)
j@236 27 (clsql:execute-command "
j@236 28 CREATE TABLE midi_db_compositions (
j@236 29 collection_id SMALLINT UNSIGNED NOT NULL,
j@236 30 composition_id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
j@236 31 filename VARCHAR(255) NOT NULL,
j@236 32 timebase SMALLINT UNSIGNED NOT NULL,
j@236 33 start INT UNSIGNED NOT NULL,
j@236 34 duration INT UNSIGNED NOT NULL,
j@236 35 owner CHAR(16) NULL,
j@236 36 version SMALLINT UNSIGNED NOT NULL DEFAULT 1,
j@236 37 creation_timestamp TIMESTAMP NULL,
j@236 38 deletion_timestamp TIMESTAMP NULL,
j@236 39 INDEX midi_composition_index (
j@236 40 collection_id, composition_id, version))
j@236 41 engine = innodb;"
j@236 42 :database database)
j@236 43 (%create-midi-composition-header-triggers database))
j@236 44
j@236 45 (defun %create-midi-composition-header-triggers (database)
j@236 46 (clsql:execute-command "
j@236 47 CREATE TRIGGER pre_insert_comp BEFORE INSERT ON midi_db_compositions
j@236 48 FOR EACH ROW
j@236 49 BEGIN
j@236 50 SET NEW.owner = SUBSTRING_INDEX(USER(),'@',1);
j@236 51 SET NEW.creation_timestamp = CURRENT_TIMESTAMP;
j@236 52 END;"
j@236 53 :database database))
j@236 54
j@236 55 (defun %create-midi-events-table (database)
j@236 56 (clsql:execute-command "
j@236 57 CREATE TABLE midi_db_events (
j@236 58 collection_id SMALLINT UNSIGNED NOT NULL,
j@236 59 composition_id SMALLINT UNSIGNED NOT NULL,
j@236 60 event_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
j@236 61 track SMALLINT UNSIGNED NOT NULL,
j@236 62 channel TINYINT UNSIGNED NOT NULL,
j@236 63 patch TINYINT UNSIGNED NOT NULL,
j@236 64 pitch TINYINT UNSIGNED NOT NULL,
j@236 65 velocity TINYINT UNSIGNED NOT NULL,
j@236 66 start INTEGER UNSIGNED NOT NULL,
j@236 67 duration INTEGER UNSIGNED NOT NULL,
j@236 68 version SMALLINT UNSIGNED NOT NULL DEFAULT 1,
j@236 69 INDEX collection_composition (collection_id, composition_id))
j@236 70 engine = innodb;"
j@236 71 :database database))
j@236 72
j@236 73 (defun %create-midi-tempi-table (database)
j@236 74 (clsql:execute-command "
j@236 75 CREATE TABLE midi_db_tempi (
j@236 76 collection_id SMALLINT UNSIGNED NOT NULL,
j@236 77 composition_id SMALLINT UNSIGNED NOT NULL,
j@236 78 constituent_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
j@236 79 start INT UNSIGNED NOT NULL,
j@236 80 duration INT UNSIGNED NOT NULL,
j@236 81 microsecs_per_crotchet INTEGER UNSIGNED NOT NULL,
j@236 82 version SMALLINT UNSIGNED NOT NULL DEFAULT 1,
j@236 83 INDEX collection_composition (collection_id, composition_id, constituent_id))
j@236 84 engine = innodb;"
j@236 85 :database database))
j@236 86
j@236 87 (defun %create-midi-timesigs-table (database)
j@236 88 (clsql:execute-command "
j@236 89 CREATE TABLE midi_db_timesigs (
j@236 90 collection_id SMALLINT UNSIGNED NOT NULL,
j@236 91 composition_id SMALLINT UNSIGNED NOT NULL,
j@236 92 constituent_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
j@236 93 start INT UNSIGNED NOT NULL,
j@236 94 duration INT UNSIGNED NOT NULL,
j@236 95 numerator TINYINT UNSIGNED NOT NULL,
j@236 96 denominator TINYINT UNSIGNED NOT NULL,
j@236 97 version SMALLINT UNSIGNED NOT NULL DEFAULT 1,
j@236 98 INDEX collection_composition (collection_id, composition_id, constituent_id))
j@236 99 engine = innodb;"
j@236 100 :database database))
j@236 101
j@236 102 (defun %create-midi-keysigs-table (database)
j@236 103 (clsql:execute-command "
j@236 104 CREATE TABLE midi_db_keysigs (
j@236 105 collection_id SMALLINT UNSIGNED NOT NULL,
j@236 106 composition_id SMALLINT UNSIGNED NOT NULL,
j@236 107 constituent_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
j@236 108 start INT UNSIGNED NOT NULL,
j@236 109 duration INT UNSIGNED NOT NULL,
j@236 110 mode TINYINT UNSIGNED NOT NULL,
j@236 111 sharp_count TINYINT UNSIGNED NOT NULL,
j@236 112 version SMALLINT UNSIGNED NOT NULL DEFAULT 1,
j@236 113 INDEX collection_composition (collection_id, composition_id, constituent_id))
j@236 114 engine = innodb;"
j@236 115 :database database))
j@236 116
j@236 117 ;; Deleting tables
j@236 118
j@236 119 (defun drop-midi-db-tables (database)
j@236 120 (%drop-midi-collections-table database)
j@236 121 (%drop-midi-compositions-table database)
j@236 122 (%drop-midi-events-table database)
j@236 123 (%drop-midi-tempi-table database)
j@236 124 (%drop-midi-timesigs-table database)
j@236 125 (%drop-midi-keysigs-table database))
j@236 126
j@236 127 (defun %drop-midi-collections-table (database)
j@236 128 (clsql:drop-table "midi_db_collections"
j@236 129 :if-does-not-exist :ignore
j@236 130 :database database))
j@236 131
j@236 132 (defun %drop-midi-compositions-table (database)
j@236 133 (clsql:drop-table "midi_db_compositions"
j@236 134 :if-does-not-exist :ignore
j@236 135 :database database))
j@236 136
j@236 137 (defun %drop-midi-events-table (database)
j@236 138 (clsql:drop-table "midi_db_events"
j@236 139 :if-does-not-exist :ignore
j@236 140 :database database))
j@236 141
j@236 142 (defun %drop-midi-constituent-headers-table (database)
j@236 143 (clsql:drop-table "midi_db_constituent_headers"
j@236 144 :if-does-not-exist :ignore
j@236 145 :database database))
j@236 146
j@236 147 (defun %drop-midi-tempi-table (database)
j@236 148 (clsql:drop-table "midi_db_tempi"
j@236 149 :if-does-not-exist :ignore
j@236 150 :database database))
j@236 151
j@236 152 (defun %drop-midi-timesigs-table (database)
j@236 153 (clsql:drop-table "midi_db_timesigs"
j@236 154 :if-does-not-exist :ignore
j@236 155 :database database))
j@236 156
j@236 157 (defun %drop-midi-keysigs-table (database)
j@236 158 (clsql:drop-table "midi_db_keysigs"
j@236 159 :if-does-not-exist :ignore
j@236 160 :database database))