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