Exemplo n.º 1
0
    def system_commons(self, common_type, common_data):

        "Dispatches system common messages"

        stream = self.outstream

        # MTC Midi time dllib Quarter value
        if common_type == MTC:
            data = readBew(common_data)
            msg_type = (data & 0x07) >> 4
            values = (data & 0x0F)
            stream.midi_time_code(msg_type, values)

        elif common_type == SONG_POSITION_POINTER:
            hibyte, lobyte = toBytes(common_data)
            value = (hibyte << 7) + lobyte
            stream.song_position_pointer(value)

        elif common_type == SONG_SELECT:
            data = readBew(common_data)
            stream.song_select(data)

        elif common_type == TUNING_REQUEST:
            # no data then
            stream.tuning_request(time=None)
Exemplo n.º 2
0
    def system_commons(self, common_type, common_data):
    
        "Dispatches system common messages"
        
        stream = self.outstream
        
        # MTC Midi time code Quarter value
        if common_type == MTC:
            data = readBew(common_data)
            msg_type = (data & 0x07) >> 4
            values = (data & 0x0F)
            stream.midi_time_code(msg_type, values)
        
        elif common_type == SONG_POSITION_POINTER:
            hibyte, lobyte = toBytes(common_data)
            value = (hibyte<<7) + lobyte
            stream.song_position_pointer(value)

        elif common_type == SONG_SELECT:
            data = readBew(common_data)
            stream.song_select(data)

        elif common_type == TUNING_REQUEST:
            # no data then
            stream.tuning_request(time=None)
Exemplo n.º 3
0
    def meta_event(self, meta_type, data):

        "Dispatches meta events"

        stream = self.outstream

        # SEQUENCE_NUMBER = 0x00 (00 02 ss ss (seq-number))
        if meta_type == SEQUENCE_NUMBER:
            number = readBew(data)
            stream.sequence_number(number)

        # TEXT = 0x01 (01 len text...)
        elif meta_type == TEXT:
            stream.text(data)

        # COPYRIGHT = 0x02 (02 len text...)
        elif meta_type == COPYRIGHT:
            stream.copyright(data)

        # SEQUENCE_NAME = 0x03 (03 len text...)
        elif meta_type == SEQUENCE_NAME:
            stream.sequence_name(data)

        # INSTRUMENT_NAME = 0x04 (04 len text...)
        elif meta_type == INSTRUMENT_NAME:
            stream.instrument_name(data)

        # LYRIC = 0x05 (05 len text...)
        elif meta_type == LYRIC:
            stream.lyric(data)

        # MARKER = 0x06 (06 len text...)
        elif meta_type == MARKER:
            stream.marker(data)

        # CUEPOINT = 0x07 (07 len text...)
        elif meta_type == CUEPOINT:
            stream.cuepoint(data)

        # PROGRAM_NAME = 0x08 (05 len text...)
        elif meta_type == PROGRAM_NAME:
            stream.program_name(data)

        # DEVICE_NAME = 0x09 (09 len text...)
        elif meta_type == DEVICE_NAME:
            stream.device_name(data)

        # MIDI_CH_PREFIX = 0x20 (20 01 channel)
        elif meta_type == MIDI_CH_PREFIX:
            channel = readBew(data)
            stream.midi_ch_prefix(channel)

        # MIDI_PORT  = 0x21 (21 01 port (legacy stuff))
        elif meta_type == MIDI_PORT:
            port = readBew(data)
            stream.midi_port(port)

        # END_OFF_TRACK = 0x2F (2F 00)
        elif meta_type == END_OF_TRACK:
            stream.end_of_track()

        # TEMPO = 0x51 (51 03 tt tt tt (tempo in us/quarternote))
        elif meta_type == TEMPO:
            b1, b2, b3 = toBytes(data)
            # uses 3 bytes to represent time between quarter
            # notes in microseconds
            stream.tempo((b1 << 16) + (b2 << 8) + b3)

        # SMTP_OFFSET = 0x54 (54 05 hh mm ss ff xx)
        elif meta_type == SMTP_OFFSET:
            hour, minute, second, frame, framePart = toBytes(data)
            stream.smtp_offset(hour, minute, second, frame, framePart)

        # TIME_SIGNATURE = 0x58 (58 04 nn dd cc bb)
        elif meta_type == TIME_SIGNATURE:
            nn, dd, cc, bb = toBytes(data)
            stream.time_signature(nn, dd, cc, bb)

        # KEY_SIGNATURE = 0x59 (59 02 sf mi)
        elif meta_type == KEY_SIGNATURE:
            sf, mi = toBytes(data)
            stream.key_signature(sf, mi)

        # SPECIFIC = 0x7F (Sequencer specific event)
        elif meta_type == SPECIFIC:
            meta_data = toBytes(data)
            stream.sequencer_specific(meta_data)

        # Handles any undefined meta events
        else:  # undefined meta type
            meta_data = toBytes(data)
            stream.meta_event(meta_type, meta_data)
Exemplo n.º 4
0
 def readBew(self, n_bytes=1, move_cursor=1):
     """
     Reads n bytes of date from the current cursor position.
     Moves cursor if move_cursor is true
     """
     return readBew(self.nextSlice(n_bytes, move_cursor))
Exemplo n.º 5
0
 def meta_event(self, meta_type, data):
     
     "Dispatches meta events"
     
     stream = self.outstream
     
     # SEQUENCE_NUMBER = 0x00 (00 02 ss ss (seq-number))
     if meta_type == SEQUENCE_NUMBER:
         number = readBew(data)
         stream.sequence_number(number)
     
     # TEXT = 0x01 (01 len text...)
     elif meta_type == TEXT:
         stream.text(data)
     
     # COPYRIGHT = 0x02 (02 len text...)
     elif meta_type == COPYRIGHT:
         stream.copyright(data)
     
     # SEQUENCE_NAME = 0x03 (03 len text...)
     elif meta_type == SEQUENCE_NAME:
         stream.sequence_name(data)
     
     # INSTRUMENT_NAME = 0x04 (04 len text...)
     elif meta_type == INSTRUMENT_NAME:
         stream.instrument_name(data)
     
     # LYRIC = 0x05 (05 len text...)
     elif meta_type == LYRIC:
         stream.lyric(data)
     
     # MARKER = 0x06 (06 len text...)
     elif meta_type == MARKER:
         stream.marker(data)
     
     # CUEPOINT = 0x07 (07 len text...)
     elif meta_type == CUEPOINT:
         stream.cuepoint(data)
     
     # PROGRAM_NAME = 0x08 (05 len text...)
     elif meta_type == PROGRAM_NAME:
         stream.program_name(data)
     
     # DEVICE_NAME = 0x09 (09 len text...)
     elif meta_type == DEVICE_NAME:
         stream.device_name(data)
     
     # MIDI_CH_PREFIX = 0x20 (20 01 channel)
     elif meta_type == MIDI_CH_PREFIX:
         channel = readBew(data)
         stream.midi_ch_prefix(channel)
     
     # MIDI_PORT  = 0x21 (21 01 port (legacy stuff))
     elif meta_type == MIDI_PORT:
         port = readBew(data)
         stream.midi_port(port)
     
     # END_OFF_TRACK = 0x2F (2F 00)
     elif meta_type == END_OF_TRACK:
         stream.end_of_track()
     
     # TEMPO = 0x51 (51 03 tt tt tt (tempo in us/quarternote))
     elif meta_type == TEMPO:
         b1, b2, b3 = toBytes(data)
         # uses 3 bytes to represent time between quarter 
         # notes in microseconds
         stream.tempo((b1<<16) + (b2<<8) + b3)
     
     # SMTP_OFFSET = 0x54 (54 05 hh mm ss ff xx)
     elif meta_type == SMTP_OFFSET:
         try:
             hour, minute, second, frame, framePart = toBytes(data)
             stream.smtp_offset(
                     hour, minute, second, frame, framePart)
         except ValueError:
             pass
     
     # TIME_SIGNATURE = 0x58 (58 04 nn dd cc bb)
     elif meta_type == TIME_SIGNATURE:
         try:
             nn, dd, cc, bb = toBytes(data)
             stream.time_signature(nn, dd, cc, bb)
         except ValueError, e:
             pass