Exemplo n.º 1
0
 def handle_systemcommon(self, status, data):
     handler_name, fmt = midispec.SYSTEM_COMMON_HANDLERS.get(status,
         (None, None))
     msgdata = miditools.unpack(fmt, data)
     return self._call(
         l(handler_name, *msgdata),
         l('system_common', status, handler_name, *msgdata))
Exemplo n.º 2
0
 def handle_systemrealtime(self, status, data):
     handler_name, fmt = midispec.SYSTEM_REALTIME_HANDLERS.get(status,
         (None, None))
     msgdata = miditools.unpack(fmt, data)
     return self._call(
         l(handler_name, *msgdata),
         l('system_realtime', status, handler_name, *msgdata))
Exemplo n.º 3
0
            mtyp, chan = miditools.nibbles(status)
            return self.handle_channelmessage(mtyp, chan, bytestr[1:])
        elif 0xF0 <= status <= 0xFF:
            return self.handle_systemmessage(status, bytestr[1:])
        else:
            return ValueError()

    def handle_channelmessage(self, mtyp, chan, data):
        # should probably get controller name here for CC stuff
        if mtyp == MIDI_CONTROLCHANGE:
            try:
                return self.handle_controlchange(chan, data)
            except NotImplementedError, e:
                pass
        handler_name, fmt = midispec.CHANNEL_VOICE_HANDLERS[mtyp]
        msgdata = miditools.unpack(fmt, data)
        return self._call(
            l(handler_name, chan, *msgdata),
            l('channel_voice', mtyp, handler_name, chan, *msgdata))

    def handle_controlchange(self, chan, data):
        cc, val = miditools.stringtobytes(data)
        cc_name = midispec.CONTROLLERS.get(cc)
        return self._call(
            (cc_name, chan, val),
            ('control_change', cc, cc_name, chan, val))

    def handle_systemmessage(self, status, data):
        try:
            if status == 0xF0:
                return self.handle_sysex(data)
Exemplo n.º 4
0
def test_unpack():
    # check special case
    assert miditools.unpack(None, 'foo') == ['foo']

    assert miditools.unpack('', '') == []
    assert miditools.unpack('>4B', '\x01\x02\x03\x04') == [1, 2, 3, 4]