/
instruments.py
296 lines (229 loc) · 8.3 KB
/
instruments.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
import mingus.containers.Instrument as Instrument
from mingus.containers.Instrument import MidiInstrument
import mingus.containers.Note as Note
import string
#--------------------------------------------------
# all intruments (by category and family):
instruments = dict()
# instrument categories:
woodwinds = dict()
strings = dict()
percussion = dict()
# instrument families:
# woodwinds:
clarinets = list()
saxophones = list()
flutes = list()
# strings:
violins = list()
plucked_strings = list()
# percussion
pitched_percussion = list()
keyboards = list()
#--------------------------------------------------
def print_instrument_family(family):
"""Prints a displays of the instruments in the given instrument family."""
print string.ljust('#', 5) + string.ljust('Name', 20) + string.ljust('Key', 10) + string.ljust('Range', 15)
print '-' * 50
for index, instr in enumerate(family):
print string.ljust(str(index+1), 5) + string.ljust(instr.name, 20) + string.ljust(instr.key, 10) + string.ljust(str(instr.range), 15)
def print_instruments():
"""Prints a display of all instruments by category and family"""
for title, category in instruments.iteritems():
print "\n" + string.center(" " + title + " ", 50, "~")
for name, family in category.iteritems():
print "\n" + string.center(" " + name + " ", 50, "-") + "\n"
print_instrument_family(family)
#--------------------------------------------------
def get_instrument_families(category):
"""Returns the list of instrument families within the given instrument category"""
families = list()
for name, family in category.iteritems():
families.append(name)
return families
def get_instrument_categories():
"""Returns a list of instrument categories"""
categories = list()
for title, category in instruments.iteritems():
categories.append(title)
return categories
#--------------------------------------------------
# clarinets:
def Clarinet():
"""Defines and returns a clarinet midi instrument (an instance of MidiInstrument())"""
instr = MidiInstrument()
instr.name = 'Clarinet'
instr.key = 'Bb'
instr.clef = 'Treble'
instr.set_range(tuple([Note('D', 3), Note('Bb', 6)]))
instr.instrument_nr = instr.names.index('Clarinet')
return instr
def Bass_Clarinet():
"""Defines and returns a bass clarinet midi instrument (an instance of MidiInstrument())"""
instr = MidiInstrument()
instr.name = 'Bass Clarinet'
instr.key = 'Bb'
instr.clef = 'Treble'
instr.set_range(tuple([Note('Bb', 1), Note('B', 5)]))
instr.instrument_nr = instr.names.index('Clarinet')
return instr
clarinets.append(Clarinet())
clarinets.append(Bass_Clarinet())
#--------------------------------------------------
# saxophones:
def Soprano_Saxophone():
"""Defines and returns a soprano saxophone midi instrument (an instance of MidiInstrument())"""
instr = MidiInstrument()
instr.name = 'Soprano Saxophone'
instr.key = 'Bb'
instr.clef = 'Treble'
instr.set_range(tuple([Note('Ab', 3), Note('E', 6)]))
instr.instrument_nr = instr.names.index('Soprano Sax')
return instr
def Alto_Saxophone():
"""Defines and returns an alto saxophone midi instrument (an instance of MidiInstrument())"""
instr = MidiInstrument()
instr.name = 'Alto Saxophone'
instr.key = 'Eb'
instr.clef = 'Treble'
instr.set_range(tuple([Note('Db', 3), Note('A', 5)]))
instr.instrument_nr = instr.names.index('Alto Sax')
return instr
def Tenor_Saxophone():
"""Defines and returns a tenor saxophone midi instrument (an instance of MidiInstrument())"""
instr = MidiInstrument()
instr.name = 'Tenor Saxophone'
instr.key = 'Bb'
instr.clef = 'Treble'
instr.set_range(tuple([Note('Ab', 2), Note('E', 5)]))
instr.instrument_nr = instr.names.index('Tenor Sax')
return instr
def Baritone_Saxophone():
"""Defines and returns a baritone saxophone midi instrument (an instance of MidiInstrument())"""
instr = MidiInstrument()
instr.name = 'Baritone Saxophone'
instr.key = 'Eb'
instr.clef = 'Treble'
instr.set_range(tuple([Note('C', 2), Note('A', 4)]))
instr.instrument_nr = instr.names.index('Baritone Sax')
return instr
saxophones.append(Soprano_Saxophone())
saxophones.append(Alto_Saxophone())
saxophones.append(Tenor_Saxophone())
saxophones.append(Baritone_Saxophone())
#--------------------------------------------------
# flutes:
def Flute():
"""Defines and returns a flute midi instrument (an instance of MidiInstrument())"""
instr = MidiInstrument()
instr.name = 'Flute'
instr.key = 'C'
instr.clef = 'Treble'
instr.set_range(tuple([Note('C', 4), Note('C', 7)]))
instr.instrument_nr = instr.names.index('Flute')
return instr
def Alto_Flute():
"""Defines and returns an alto flute midi instrument (an instance of MidiInstrument())"""
instr = MidiInstrument()
instr.name = 'Alto Flute'
instr.key = 'G'
instr.clef = 'Treble'
instr.set_range(tuple([Note('G', 3), Note('G', 6)]))
instr.instrument_nr = instr.names.index('Flute')
return instr
flutes.append(Flute())
flutes.append(Alto_Flute())
#--------------------------------------------------
# violins:
def Violin():
"""Defines and returns a violin midi instrument (an instance of MidiInstrument())"""
instr = MidiInstrument()
instr.name = 'Violin'
instr.key = 'C'
instr.clef = 'Treble'
instr.set_range(tuple([Note('G', 3), Note('E', 7)]))
instr.instrument_nr = instr.names.index('Violin')
return instr
def Viola():
"""Defines and returns a viola midi instrument (an instance of MidiInstrument())"""
instr = MidiInstrument()
instr.name = 'Viola'
instr.key = 'C'
instr.clef = 'Alto'
instr.set_range(tuple([Note('C', 3), Note('A', 7)]))
instr.instrument_nr = instr.names.index('Viola')
return instr
def Cello():
"""Defines and returns a cello midi instrument (an instance of MidiInstrument())"""
instr = MidiInstrument()
instr.name = 'Cello'
instr.key = 'C'
instr.clef = 'Bass'
instr.set_range(tuple([Note('C', 2), Note('E', 6)]))
instr.instrument_nr = instr.names.index('Cello')
return instr
def Contrabass():
"""Defines and returns a contrabass midi instrument (an instance of MidiInstrument())"""
instr = MidiInstrument()
instr.name = 'Contrabass'
instr.key = 'C'
instr.clef = 'Bass'
instr.set_range(tuple([Note('E', 1), Note('G', 5)]))
instr.instrument_nr = instr.names.index('Contrabass')
return instr
violins.append(Violin())
violins.append(Viola())
violins.append(Cello())
violins.append(Contrabass())
#--------------------------------------------------
# plucked_strings:
def Orchestral_Harp():
"""Defines and returns an orchestral harp midi instrument (an instance of MidiInstrument())"""
instr = MidiInstrument()
instr.name = 'Orchestral Harp'
instr.key = 'C'
instr.clef = 'Treble & Bass'
instr.set_range(tuple([Note('C', 1), Note('G', 7)]))
instr.instrument_nr = instr.names.index('Orchestral Harp')
return instr
plucked_strings.append(Orchestral_Harp())
#--------------------------------------------------
# keyboards:
def Piano():
"""Defines and returns a piano midi instrument (an instance of MidiInstrument())"""
instr = MidiInstrument()
instr.name = 'Piano'
instr.key = 'C'
instr.clef = 'Treble & Bass'
instr.set_range(tuple([Note('A', 0), Note('C', 8)]))
instr.instrument_nr = instr.names.index('Acoustic Grand Piano')
return instr
keyboards.append(Piano())
#--------------------------------------------------
# pitched_percussion:
def Vibraphone():
"""Defines and returns a vibraphone midi instrument (an instance of MidiInstrument())"""
instr = MidiInstrument()
instr.name = 'Vibraphone'
instr.key = 'C'
instr.clef = 'Treble'
instr.set_range(tuple([Note('F', 3), Note('F', 6)]))
instr.instrument_nr = instr.names.index('Vibraphone')
return instr
def Marimba():
"""Defines and returns a marimba midi instrument (an instance of MidiInstrument())"""
instr = MidiInstrument()
instr.name = 'Marimba'
instr.key = 'C'
instr.clef = 'Treble & Bass'
instr.set_range(tuple([Note('C', 2), Note('C', 7)]))
instr.instrument_nr = instr.names.index('Marimba')
return instr
pitched_percussion.append(Vibraphone())
pitched_percussion.append(Marimba())
#--------------------------------------------------
# instruments:
woodwinds = {'Clarinets': clarinets, 'Saxophones': saxophones, 'Flutes': flutes}
strings = {'Violins': violins, 'Plucked_strings': plucked_strings}
percussion = {'Pitched Percussion': pitched_percussion, 'Keyboards': keyboards}
instruments = {'Woodwinds': woodwinds, 'Strings': strings, 'Percussion': percussion}