Example #1
0
 def continuous_controller(self, channel, controller, value):
     """
     channel: 0-15
     controller, value: 0-127
     """
     slc = fromBytes([CONTINUOUS_CONTROLLER + channel, controller, value])
     self.event_slice(slc)
Example #2
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)
Example #3
0
    def meta_slice(self, meta_type, data_slice):
        """
        Writes a meta event. Whatever that is.

        Parameters
        ----------
        meta_type :

        data_slice :

        """

        # EDIT: added try / except for debugging purposes! TG
#        try:
#            slc = fromBytes([META_EVENT, meta_type]) + \
#                    writeVar(len(data_slice)) +  data_slice
#
#            self.event_slice(slc)
#        except:
#            pass

        # Original code:
        slc = fromBytes([META_EVENT, meta_type]) + \
              writeVar(len(data_slice)) + data_slice

        self.event_slice(slc)
Example #4
0
    def time_signature(self, nn, dd, cc, bb):
        """
        Parameters
        ----------
        nn : number
            the numerator of the notated time signature. The
            number of beats that make up a full measure.

        dd : number
            represents the denominator of the notated time signature
            but NOT as the written number itself. It is

        cc : number
            number of MIDI clocks in a metronome click

        bb : number
            the number of notated 32nd notes in a MIDI quarter note
            (24 MIDI clocks)

#        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]))
Example #5
0
 def midi_time_code(self, msg_type, values):
     """
     msg_type: 0-7
     values: 0-15
     """
     value = (msg_type<<4) + values
     self.event_slice(fromBytes([MTC, value]))
Example #6
0
 def song_position_pointer(self, value):
     """
     value: 0-16383
     """
     lsb = (value & 0x7F)
     msb = (value >> 7) & 0x7F
     self.event_slice(fromBytes([SONG_POSITION_POINTER, lsb, msb]))
Example #7
0
 def patch_change(self, channel, patch):
     """
     channel: 0-15
     patch: 0-127
     """
     slc = fromBytes([PATCH_CHANGE + channel, patch])
     self.event_slice(slc)
Example #8
0
 def note_off(self, channel=0, note=0x40, velocity=0x40):
     """
     channel: 0-15
     note, velocity: 0-127
     """
     slc = fromBytes([NOTE_OFF + channel, note, velocity])
     self.event_slice(slc)
Example #9
0
 def aftertouch(self, channel=0, note=0x40, velocity=0x40):
     """
     channel: 0-15
     note, velocity: 0-127
     """
     slc = fromBytes([AFTERTOUCH + channel, note, velocity])
     self.event_slice(slc)
Example #10
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)
Example #11
0
 def midi_time_code(self, msg_type, values):
     """
     msg_type: 0-7
     values: 0-15
     """
     value = (msg_type << 4) + values
     self.event_slice(fromBytes([MIDI_TIME_CODE, value]))
Example #12
0
    def time_signature(self, nn, dd, cc, bb):
        """
        Parameters
        ----------
        nn : number
            the numerator of the notated time signature. The
            number of beats that make up a full measure.

        dd : number
            represents the denominator of the notated time signature
            but NOT as the written number itself. It is

        cc : number
            number of MIDI clocks in a metronome click

        bb : number
            the number of notated 32nd notes in a MIDI quarter note
            (24 MIDI clocks)

#        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]))
Example #13
0
 def channel_pressure(self, channel, pressure):
     """
     channel: 0-15
     pressure: 0-127
     """
     slc = fromBytes([CHANNEL_PRESSURE + channel, pressure])
     self.event_slice(slc)
Example #14
0
 def continuous_controller(self, channel, controller, value):
     """
     channel: 0-15
     controller, value: 0-127
     """
     slc = fromBytes([CONTINUOUS_CONTROLLER + channel, controller, value])
     self.event_slice(slc)
Example #15
0
    def meta_slice(self, meta_type, data_slice):
        """
        Writes a meta event. Whatever that is.

        Parameters
        ----------
        meta_type :

        data_slice :

        """

        # EDIT: added try / except for debugging purposes! TG
        #        try:
        #            slc = fromBytes([META_EVENT, meta_type]) + \
        #                    writeVar(len(data_slice)) +  data_slice
        #
        #            self.event_slice(slc)
        #        except:
        #            pass

        # Original code:
        slc = fromBytes([META_EVENT, meta_type]) + \
              writeVar(len(data_slice)) + data_slice

        self.event_slice(slc)
Example #16
0
 def patch_change(self, channel, patch):
     """
     channel: 0-15
     patch: 0-127
     """
     slc = fromBytes([PATCH_CHANGE + channel, patch])
     self.event_slice(slc)
Example #17
0
 def channel_pressure(self, channel, pressure):
     """
     channel: 0-15
     pressure: 0-127
     """
     slc = fromBytes([CHANNEL_PRESSURE + channel, pressure])
     self.event_slice(slc)
Example #18
0
 def song_position_pointer(self, value):
     """
     value: 0-16383
     """
     lsb = (value & 0x7F)
     msb = (value >> 7) & 0x7F
     self.event_slice(fromBytes([SONG_POSITION_POINTER, lsb, msb]))
Example #19
0
 def note_off(self, channel=0, note=0x40, velocity=0x40):
     """
     channel: 0-15
     note, velocity: 0-127
     """
     slc = fromBytes([NOTE_OFF + channel, note, velocity])
     self.event_slice(slc)
Example #20
0
 def aftertouch(self, channel=0, note=0x40, velocity=0x40):
     """
     channel: 0-15
     note, velocity: 0-127
     """
     slc = fromBytes([AFTERTOUCH + channel, note, velocity])
     self.event_slice(slc)
Example #21
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]))
Example #22
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]))
Example #23
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]))
Example #24
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]))
Example #25
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)
Example #26
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)
Example #27
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]))
Example #28
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]))
Example #29
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]))
Example #30
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)
Example #31
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)
Example #32
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]))
Example #33
0
    def patch_change(self, channel, patch):
        """
        Parameters
        ----------
        channel : number
            the MIDI channel number, possible values: 0-15

         patch : number
             the patch number (instrument/sound), possible values: 0-127

#       channel: 0-15
#        patch: 0-127
        """
        slc = fromBytes([PATCH_CHANGE + channel, patch])
        self.event_slice(slc)
Example #34
0
    def patch_change(self, channel, patch):
        """
        Parameters
        ----------
        channel : number
            the MIDI channel number, possible values: 0-15

         patch : number
             the patch number (instrument/sound), possible values: 0-127

#       channel: 0-15
#        patch: 0-127
        """
        slc = fromBytes([PATCH_CHANGE + channel, patch])
        self.event_slice(slc)
Example #35
0
    def midi_time_code(self, msg_type, values):
        """
        Quarter-frame messages.

        Parameters
        ----------
        msg_type : number
            range is 0-7

        values : number
            range is 0-15

#        msg_type: 0-7
#        values: 0-15
        """
        value = (msg_type << 4) + values
        self.event_slice(fromBytes([MTC, value]))
Example #36
0
    def midi_time_code(self, msg_type, values):
        """
        Quarter-frame messages.

        Parameters
        ----------
        msg_type : number
            range is 0-7

        values : number
            range is 0-15

#        msg_type: 0-7
#        values: 0-15
        """
        value = (msg_type << 4) + values
        self.event_slice(fromBytes([MIDI_TIME_CODE, value]))
Example #37
0
    def pitch_bend(self, channel, value):
        """
        Parameters
        ----------
        channel : number

        value : number
            the pitch bend controller value. Note that this doesn't
            tell straight away by what amount the pitch is bent (e.g. in
            cents = 100th part of a semi-tone). CHECK this!

#        channel: 0-15
#        value: 0-16383
        """
        msb = (value >> 7) & 0xFF
        lsb = value & 0xFF
        slc = fromBytes([PITCH_BEND + channel, msb, lsb])
        self.event_slice(slc)
Example #38
0
    def pitch_bend(self, channel, value):
        """
        Parameters
        ----------
        channel : number

        value : number
            the pitch bend controller value. Note that this doesn't
            tell straight away by what amount the pitch is bent (e.g. in
            cents = 100th part of a semi-tone). CHECK this!

#        channel: 0-15
#        value: 0-16383
        """
        msb = (value>>7) & 0xFF
        lsb = value & 0xFF
        slc = fromBytes([PITCH_BEND + channel, msb, lsb])
        self.event_slice(slc)
Example #39
0
    def note_on(self, channel=0, note=0x40, velocity=0x40):
        """
        (0x40 = 64)

        Parameters
        ----------
        channel : number, optional. Default: 0
            the MIDI channel number. Possible range is 0-15

        note : hex number, optional. Default: 0x40
            the MIDI note number.

        velocity : hex number, optional. Default: 0x40
            the note velocity, possible range is 0-127 (0x00 - 0x7F)

#        channel: 0-15
#        note, velocity: 0-127
        """
        slc = fromBytes([NOTE_ON + channel, note, velocity])
        self.event_slice(slc)
Example #40
0
    def note_on(self, channel=0, note=0x40, velocity=0x40):
        """
        (0x40 = 64)

        Parameters
        ----------
        channel : number, optional. Default: 0
            the MIDI channel number. Possible range is 0-15

        note : hex number, optional. Default: 0x40
            the MIDI note number.

        velocity : hex number, optional. Default: 0x40
            the note velocity, possible range is 0-127 (0x00 - 0x7F)

#        channel: 0-15
#        note, velocity: 0-127
        """
        slc = fromBytes([NOTE_ON + channel, note, velocity])
        self.event_slice(slc)
Example #41
0
 def meta_event(self, meta_type, data):
     """
     Handles any undefined meta events
     """
     self.meta_slice(meta_type, fromBytes(data))
Example #42
0
    def song_select(self, songNumber):

        """
        songNumber: 0-127
        """
        self.event_slice(fromBytes([SONG_SELECT, songNumber]))
Example #43
0
 def song_select(self, songNumber):
     """
     songNumber: 0-127
     """
     self.event_slice(fromBytes([SONG_SELECT, songNumber]))
Example #44
0
 def meta_event(self, meta_type, data):
     """
     Handles any undefined meta events
     """
     self.meta_slice(meta_type, fromBytes(data))