annotate implementations/midi-db/classes.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 (defclass midi-db-object (amuse-object) ())
j@236 4
j@236 5 (defclass midi-db-identifier (identifier midi-db-object) ())
j@236 6
j@236 7 (defclass midi-db-collection-identifier (midi-db-identifier)
j@236 8 ((collection-id :initarg :collection-id
j@236 9 :accessor collection-id
j@236 10 :initform nil))
j@236 11 (:documentation "Class to represent midi-db collection identifiers."))
j@236 12
j@236 13 (defun make-midi-db-collection-identifier (collection-id)
j@236 14 (make-instance 'midi-db-collection-identifier
j@236 15 :collection-id collection-id))
j@236 16
j@236 17 (defclass midi-db-composition-identifier (composition-identifier
j@236 18 midi-db-identifier)
j@236 19 ((composition-id :reader composition-id
j@236 20 :initarg :composition-id))
j@236 21 (:documentation "Class to represent midi-db composition identifiers."))
j@236 22
j@236 23 (defun make-midi-db-composition-identifier (composition-id)
j@236 24 (make-instance 'midi-db-composition-identifier
j@236 25 :composition-id composition-id))
j@236 26
j@236 27 (defclass midi-db-composition (midi-composition midi-db-object)
j@236 28 ((collection-identifier :initarg :collection-identifier
j@236 29 :reader collection-identifier)
j@236 30 (filename :initarg :filename
j@236 31 :reader filename)
j@236 32 (owner :initarg :owner
j@236 33 :reader owner)
j@236 34 (version :initarg :version
j@236 35 :reader version)
j@236 36 (creation-timestamp :initarg :creation-timestamp
j@236 37 :reader creation-timestamp)
j@236 38 (deletion-timestamp :initarg :deletion-timestamp
j@236 39 :reader deletion-timestamp))
j@236 40 (:documentation "Midi-db class with slots for additional database
j@236 41 fields. FIXME: This should perhaps be a subclass of 'versioned
j@236 42 constituents'?"))
j@236 43
j@236 44 (defun make-midi-db-composition (events start duration tempi timesigs
j@236 45 keysigs identifier
j@236 46 collection-identifier timebase
j@236 47 filename owner version
j@236 48 creation-timestamp
j@236 49 deletion-timestamp)
j@236 50 "Make a midi-db composition. This does not do the usual
j@236 51 adjust-sequence initialisation (calling
j@236 52 %recompute-standard-composition-period). FIXME: Is this bad?"
j@236 53 (make-instance 'midi-db-composition
j@236 54 :%data events
j@236 55 :time start
j@236 56 :interval duration
j@236 57 :time-signatures timesigs
j@236 58 :tempi tempi
j@236 59 :key-signatures keysigs
j@236 60 :identifier identifier
j@236 61 :collection-identifier collection-identifier
j@236 62 :midi-timebase timebase
j@236 63 :filename filename
j@236 64 :owner owner
j@236 65 :version version
j@236 66 :creation-timestamp creation-timestamp
j@236 67 :deletion-timestamp deletion-timestamp))
j@236 68
j@236 69 (defmethod initialize-instance :after ((composition
j@236 70 midi-db-composition) &key)
j@236 71 "Initialize each event so that it knows what composition it belongs
j@236 72 to."
j@236 73 (sequence:dosequence (e composition t)
j@236 74 (%set-composition composition e)))
j@236 75
j@236 76 (defclass midi-db-event (midi-db-object linked-event)
j@236 77 ((collection-identifier :initarg :collection-identifier
j@236 78 :reader collection-identifier)
j@236 79 (composition-identifier :initarg :composition-identifier
j@236 80 :reader composition-identifier)
j@236 81 (identifier :initarg :identifier
j@236 82 :reader identifier)
j@236 83 (version :initarg :version
j@236 84 :reader version)))
j@236 85
j@236 86 (defclass midi-db-pitched-event (midi-pitched-event midi-db-event)
j@236 87 ()
j@236 88 (:documentation "Midi-db class with slots for additional database
j@236 89 fields. FIXME: This should perhaps be a subclass of 'versioned
j@236 90 constituents'?"))
j@236 91
j@236 92 (defclass midi-db-percussive-event (midi-percussive-event midi-db-event)
j@236 93 ()
j@236 94 (:documentation "Midi-db class with slots for additional database
j@236 95 fields. FIXME: This should perhaps be a subclass of 'versioned
j@236 96 constituents'?"))
j@236 97
j@236 98 (defun make-midi-db-pitched-event (collection-identifier
j@236 99 composition-identifier
j@236 100 event-identifier track channel
j@236 101 patch pitch velocity start duration
j@236 102 version &optional composition)
j@236 103 (make-instance 'midi-db-pitched-event
j@236 104 :collection-identifier collection-identifier
j@236 105 :composition-identifier composition-identifier
j@236 106 :identifier event-identifier
j@236 107 :track track
j@236 108 :channel channel
j@236 109 :patch patch
j@236 110 :number pitch
j@236 111 :velocity velocity
j@236 112 :time start
j@236 113 :interval duration
j@236 114 :version version
j@236 115 :composition composition))
j@236 116
j@236 117 (defun make-midi-db-percussive-event (collection-identifier
j@236 118 composition-identifier
j@236 119 event-identifier track channel
j@236 120 patch drum-sound velocity start
j@236 121 duration version &optional
j@236 122 composition)
j@236 123 (make-instance 'midi-db-percussive-event
j@236 124 :collection-identifier collection-identifier
j@236 125 :composition-identifier composition-identifier
j@236 126 :identifier event-identifier
j@236 127 :track track
j@236 128 :channel channel
j@236 129 :patch patch
j@236 130 :sound drum-sound
j@236 131 :velocity velocity
j@236 132 :time start
j@236 133 :interval duration
j@236 134 :version version
j@236 135 :composition composition))
j@236 136
j@236 137 (defclass midi-db-tempi (standard-tempo-period midi-db-object)
j@236 138 ((version :initarg :version
j@236 139 :reader version))
j@236 140 (:documentation "FIXME: subclass versioned constituent"))
j@236 141
j@236 142 (defun make-midi-db-tempo (start duration microsecs-per-crotchet version)
j@236 143 (make-instance 'midi-db-tempi
j@236 144 :time start
j@236 145 :interval duration
j@236 146 :bpm (microsecond-per-crotchet-to-bpm
j@236 147 microsecs-per-crotchet)
j@236 148 :version version))
j@236 149
j@236 150 (defclass midi-db-timesig (standard-time-signature-period
j@236 151 midi-db-object)
j@236 152 ((version :initarg :version
j@236 153 :reader version))
j@236 154 (:documentation "FIXME: subclass versioned constituent"))
j@236 155
j@236 156 (defun make-midi-db-timesig (start duration numerator denominator
j@236 157 version)
j@236 158 (make-instance 'midi-db-timesig
j@236 159 :time start
j@236 160 :interval duration
j@236 161 :numerator numerator
j@236 162 :denominator denominator
j@236 163 :version version))
j@236 164
j@236 165 (defclass midi-db-keysig (midi-key-signature-period
j@236 166 midi-db-object)
j@236 167 ((version :initarg :version
j@236 168 :reader version))
j@236 169 (:documentation "FIXME: subclass versioned constituent"))
j@236 170
j@236 171 (defun make-midi-db-keysig (start duration mode sharp-count version)
j@236 172 (make-instance 'midi-db-keysig
j@236 173 :time start
j@236 174 :interval duration
j@236 175 :mode mode
j@236 176 :sharp-count sharp-count
j@236 177 :version version))