Package midi :: Module constants
[hide private]
[frames] | no frames]

Source Code for Module midi.constants

  1  """Constants relating to MIDI data. 
  2   
  3  These constants are used by MIDI data operations. 
  4   
  5  I'm not convinced all of these are useful. It might be nice to tidy  
  6  them up a bit and make it clear what they're all for. 
  7   
  8  """ 
  9  OCTAVE_MAX_VALUE = 12 
 10  OCTAVE_VALUES = range( OCTAVE_MAX_VALUE ) 
 11   
 12  NOTE_NAMES = ['C','C#','D','D#','E','F','F#','G','G#','A','A#','B'] 
 13  """A set of names for each note in the 12-tet octave.""" 
 14   
 15  WHITE_KEYS = [0, 2, 4, 5, 7, 9, 11] 
 16  """Indices in the octave of the white notes on a piano keyboard.""" 
 17   
 18  BLACK_KEYS = [1, 3, 6, 8, 10] 
 19  """Indices in the octave of the black notes on a piano keyboard.""" 
 20   
 21  NOTE_PER_OCTAVE = len( NOTE_NAMES ) 
 22  NOTE_VALUES = range( OCTAVE_MAX_VALUE * NOTE_PER_OCTAVE ) 
 23  NOTE_NAME_MAP_FLAT = {} 
 24  NOTE_VALUE_MAP_FLAT = [] 
 25  NOTE_NAME_MAP_SHARP = {} 
 26  NOTE_VALUE_MAP_SHARP = [] 
 27   
 28  for value in range( 128 ): 
 29      noteidx = value % NOTE_PER_OCTAVE 
 30      octidx = value / OCTAVE_MAX_VALUE 
 31      name = NOTE_NAMES[noteidx] 
 32      if len( name ) == 2: 
 33          # sharp note 
 34          flat = NOTE_NAMES[noteidx+1] + 'b' 
 35          NOTE_NAME_MAP_FLAT['%s-%d' % (flat, octidx)] = value 
 36          NOTE_NAME_MAP_SHARP['%s-%d' % (name, octidx)] = value 
 37          NOTE_VALUE_MAP_FLAT.append( '%s-%d' % (flat, octidx) ) 
 38          NOTE_VALUE_MAP_SHARP.append( '%s-%d' % (name, octidx) ) 
 39          globals()['%s_%d' % (name[0] + 's', octidx)] = value 
 40          globals()['%s_%d' % (flat, octidx)] = value 
 41      else: 
 42          NOTE_NAME_MAP_FLAT['%s-%d' % (name, octidx)] = value 
 43          NOTE_NAME_MAP_SHARP['%s-%d' % (name, octidx)] = value 
 44          NOTE_VALUE_MAP_FLAT.append( '%s-%d' % (name, octidx) ) 
 45          NOTE_VALUE_MAP_SHARP.append( '%s-%d' % (name, octidx) ) 
 46          globals()['%s_%d' % (name, octidx)] = value 
 47   
 48  BEATNAMES = ['whole', 'half', 'quarter', 'eighth', 'sixteenth', 'thiry-second', 'sixty-fourth'] 
 49  BEATVALUES = [4, 2, 1, .5, .25, .125, .0625] 
 50  WHOLE = 0 
 51  HALF = 1 
 52  QUARTER = 2 
 53  EIGHTH = 3 
 54  SIXTEENTH = 4 
 55  THIRTYSECOND = 5 
 56  SIXTYFOURTH = 6 
 57   
 58  DEFAULT_MIDI_HEADER_SIZE = 14 
 59   
 60   
 61  CONTROL_MESSAGE_DICTIONARY = \ 
 62  {0:'Bank Select, MSB', 
 63   1:'Modulation Wheel', 
 64   2:'Breath Controller', 
 65   4:'Foot Controller', 
 66   5:'Portamento Time', 
 67   6:'Data Entry', 
 68   7:'Channel Volume', 
 69   8:'Balance', 
 70   10:'Pan', 
 71   11:'Expression Controller', 
 72   12:'Effect Control 1', 
 73   13:'Effect Control 2', 
 74   16:'Gen Purpose Controller 1', 
 75   17:'Gen Purpose Controller 2', 
 76   18:'Gen Purpose Controller 3', 
 77   19:'Gen Purpose Controller 4', 
 78   32:'Bank Select, LSB', 
 79   33:'Modulation Wheel', 
 80   34:'Breath Controller', 
 81   36:'Foot Controller', 
 82   37:'Portamento Time', 
 83   38:'Data Entry', 
 84   39:'Channel Volume', 
 85   40:'Balance', 
 86   42:'Pan', 
 87   43:'Expression Controller', 
 88   44:'Effect Control 1', 
 89   45:'Effect Control 2', 
 90   48:'General Purpose Controller 1', 
 91   49:'General Purpose Controller 2', 
 92   50:'General Purpose Controller 3', 
 93   51:'General Purpose Controller 4', 
 94   64:'Sustain On/Off', 
 95   65:'Portamento On/Off', 
 96   66:'Sostenuto On/Off', 
 97   67:'Soft Pedal On/Off', 
 98   68:'Legato On/Off', 
 99   69:'Hold 2 On/Off', 
100   70:'Sound Controller 1  (TG: Sound Variation;   FX: Exciter On/Off)', 
101   71:'Sound Controller 2   (TG: Harmonic Content;   FX: Compressor On/Off)', 
102   72:'Sound Controller 3   (TG: Release Time;   FX: Distortion On/Off)', 
103   73:'Sound Controller 4   (TG: Attack Time;   FX: EQ On/Off)', 
104   74:'Sound Controller 5   (TG: Brightness;   FX: Expander On/Off)', 
105   75:'Sound Controller 6   (TG: Decay Time;   FX: Reverb On/Off)', 
106   76:'Sound Controller 7   (TG: Vibrato Rate;   FX: Delay On/Off)', 
107   77:'Sound Controller 8   (TG: Vibrato Depth;   FX: Pitch Transpose On/Off)', 
108   78:'Sound Controller 9   (TG: Vibrato Delay;   FX: Flange/Chorus On/Off)', 
109   79:'Sound Controller 10   (TG: Undefined;   FX: Special Effects On/Off)', 
110   80:'General Purpose Controller 5', 
111   81:'General Purpose Controller 6', 
112   82:'General Purpose Controller 7', 
113   83:'General Purpose Controller 8', 
114   84:'Portamento Control (PTC)   (0vvvvvvv is the source Note number)   (Detail)', 
115   91:'Effects 1 (Reverb Send Level)', 
116   92:'Effects 2 (Tremelo Depth)', 
117   93:'Effects 3 (Chorus Send Level)', 
118   94:'Effects 4 (Celeste Depth)', 
119   95:'Effects 5 (Phaser Depth)', 
120   96:'Data Increment', 
121   97:'Data Decrement', 
122   98:'Non Registered Parameter Number (LSB)', 
123   99:'Non Registered Parameter Number (MSB)', 
124   100:'Registered Parameter Number (LSB)', 
125   101:'Registered Parameter Number (MSB)', 
126   120:'All Sound Off', 
127   121:'Reset All Controllers', 
128   122:'Local Control On/Off', 
129   123:'All Notes Off', 
130   124:'Omni Mode Off (also causes ANO)', 
131   125:'Omni Mode On (also causes ANO)', 
132   126:'Mono Mode On (Poly Off; also causes ANO)', 
133   127:'Poly Mode On (Mono Off; also causes ANO)'} 
134