Beispiel #1
0
 def key_signature(self, sf, mi):
     """
     sf: is a byte specifying the number of flats (-ve) or sharps 
         (+ve) that identifies the key signature (-7 = 7 flats, -1 
         = 1 flat, 0 = key of C, 1 = 1 sharp, etc).
     mi: is a byte specifying a major (0) or minor (1) key.
     """
     self.meta_slice(KEY_SIGNATURE, fromBytes([sf, mi]))
Beispiel #2
0
 def tempo(self, value):
     """
     value: 0-2097151
     tempo in us/quarternote
     (to calculate value from bpm: int(60,000,000.00 / BPM))
     """
     hb, mb, lb = (value >> 16 & 0xff), (value >> 8 & 0xff), (value & 0xff)
     self.meta_slice(TEMPO, fromBytes([hb, mb, lb]))
Beispiel #3
0
 def pitch_bend(self, channel, value):
     """
     channel: 0-15
     value: 0-16383
     """
     msb = (value >> 7) & 0xFF
     lsb = value & 0xFF
     slc = fromBytes([PITCH_BEND + channel, msb, lsb])
     self.event_slice(slc)
Beispiel #4
0
 def time_signature(self, nn, dd, cc, bb):
     """
     nn: Numerator of the signature as notated on sheet music
     dd: Denominator of the signature as notated on sheet music
         The denominator is a negative power of 2: 2 = quarter 
         note, 3 = eighth, etc.
     cc: The number of MIDI clocks in a metronome click
     bb: The number of notated 32nd notes in a MIDI quarter note 
         (24 MIDI clocks)        
     """
     self.meta_slice(TIME_SIGNATURE, fromBytes([nn, dd, cc, bb]))
Beispiel #5
0
 def end_of_track(self):
     """
     Writes the track to the buffer.
     """
     raw = self.raw_out
     raw.writeSlice(TRACK_HEADER)
     track_data = self._current_track_buffer.getvalue()
     # wee need to know size of track data.
     eot_slice = writeVar(self.rel_time()) + fromBytes([META_EVENT, END_OF_TRACK, 0])
     raw.writeBew(len(track_data)+len(eot_slice), 4)
     # then write
     raw.writeSlice(track_data)
     raw.writeSlice(eot_slice)
Beispiel #6
0
 def smtp_offset(self, hour, minute, second, frame, framePart):
     """
     hour,
     minute,
     second: 3 bytes specifying the hour (0-23), minutes (0-59) and 
             seconds (0-59), respectively. The hour should be 
             encoded with the SMPTE format, just as it is in MIDI 
             Time Code.
     frame: A byte specifying the number of frames per second (one 
            of : 24, 25, 29, 30).
     framePart: A byte specifying the number of fractional frames, 
                in 100ths of a frame (even in SMPTE-based tracks 
                using a different frame subdivision, defined in the 
                MThd chunk).
     """
     self.meta_slice(SMTP_OFFSET,
                     fromBytes([hour, minute, second, frame, framePart]))
Beispiel #7
0
 def meta_event(self, meta_type, data):
     """
     Handles any undefined meta events
     """
     self.meta_slice(meta_type, fromBytes(data))
Beispiel #8
0
 def meta_slice(self, meta_type, data_slice):
     "Writes a meta event"
     slc = fromBytes([META_EVENT, meta_type]) + \
                      writeVar(len(data_slice)) +  data_slice
     self.event_slice(slc)
Beispiel #9
0
 def song_select(self, songNumber):
     """
     songNumber: 0-127
     """
     self.event_slice(fromBytes([SONG_SELECT, songNumber]))