From c029a423d4fe5918d0dba3ea79e1639c01f49ad4 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Mon, 2 Jan 2012 15:10:15 +0000 Subject: [PATCH] genmidi: Add constants for MIDI notes. Constant definitions for MIDI notes, so that instrument definitions do not need to use meaningless numbers. --- lumps/genmidi/config.py | 29 ++++++++++++++-------------- lumps/genmidi/midi.py | 42 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 14 deletions(-) create mode 100644 lumps/genmidi/midi.py diff --git a/lumps/genmidi/config.py b/lumps/genmidi/config.py index 7346fdf7..00a35c0c 100644 --- a/lumps/genmidi/config.py +++ b/lumps/genmidi/config.py @@ -17,11 +17,12 @@ # event. Some instruments (especially percussion) always play the same # note. To specify a fixed note, do this: # -# Instrument("filename.sbi", note=16) +# Instrument("filename.sbi", note=On5.B) # -# (Where the value is the MIDI note number) +# Value is a MIDI note number; see midi.py for constant definitions. from instrument import Instrument, NullInstrument +from midi import * # General MIDI instruments: @@ -197,17 +198,17 @@ PERCUSSION = [ NullInstrument, # TODO - #67 High Agogo NullInstrument, # TODO - #68 Low Agogo NullInstrument, # TODO - #69 Cabasa - Instrument("perc70.sbi", note=16), # #70 Maracas - Instrument("perc71.sbi", note=16), # #71 Short Whistle - Instrument("perc72.sbi", note=16), # #72 Long Whistle - Instrument("perc73.sbi", note=16), # #73 Short Guiro - Instrument("perc74.sbi", note=16), # #74 Long Guiro - Instrument("perc75.sbi", note=16), # #75 Claves - Instrument("perc76.sbi", note=16), # #76 Hi Wood Block - Instrument("perc77.sbi", note=16), # #77 Low Wood Block - Instrument("perc78.sbi", note=16), # #78 Mute Cuica - Instrument("perc79.sbi", note=16), # #79 Open Cuica - Instrument("perc80.sbi", note=16), # #80 Mute Triangle - Instrument("perc81.sbi", note=16), # #81 Open Triangle + Instrument("perc70.sbi", note=On5.E), # #70 Maracas + Instrument("perc71.sbi", note=On5.E), # #71 Short Whistle + Instrument("perc72.sbi", note=On5.E), # #72 Long Whistle + Instrument("perc73.sbi", note=On5.E), # #73 Short Guiro + Instrument("perc74.sbi", note=On5.E), # #74 Long Guiro + Instrument("perc75.sbi", note=On5.E), # #75 Claves + Instrument("perc76.sbi", note=On5.E), # #76 Hi Wood Block + Instrument("perc77.sbi", note=On5.E), # #77 Low Wood Block + Instrument("perc78.sbi", note=On5.E), # #78 Mute Cuica + Instrument("perc79.sbi", note=On5.E), # #79 Open Cuica + Instrument("perc80.sbi", note=On5.E), # #80 Mute Triangle + Instrument("perc81.sbi", note=On5.E), # #81 Open Triangle ] diff --git a/lumps/genmidi/midi.py b/lumps/genmidi/midi.py new file mode 100644 index 00000000..f3858cb2 --- /dev/null +++ b/lumps/genmidi/midi.py @@ -0,0 +1,42 @@ + +# Constants for MIDI notes. +# +# For example: +# F# in Octave 3: O3.Fs +# C# in Octave -2: On2.Cs +# D-flat in Octave 1: O1.Db +# D in Octave 0: O0.D +# E in Octave 2: O2.E + +class Octave: + def __init__(self, base): + self.C = base + self.Cs = base + 1 + self.Db = base + 1 + self.D = base + 2 + self.Ds = base + 3 + self.Eb = base + 3 + self.E = base + 4 + self.F = base + 5 + self.Fs = base + 6 + self.Gb = base + 6 + self.G = base + 7 + self.Gs = base + 8 + self.Ab = base + 8 + self.A = base + 9 + self.As = base + 10 + self.Bb = base + 10 + self.B = base + 11 + +On5 = Octave(0) # Octave -5 +On4 = Octave(12) # Octave -4 +On3 = Octave(24) # Octave -3 +On2 = Octave(36) # Octave -2 +On1 = Octave(48) # Octave -1 +O0 = Octave(60) # Octave 0 +O1 = Octave(72) # Octave 1 +O2 = Octave(84) # Octave 2 +O3 = Octave(96) # Octave 3 +O4 = Octave(108) # Octave 4 +O5 = Octave(120) # Octave 5 +