diff options
author | Jun Wako <wakojun@gmail.com> | 2015-04-24 16:26:14 +0900 |
---|---|---|
committer | Jun Wako <wakojun@gmail.com> | 2015-04-24 16:26:14 +0900 |
commit | a3d96d3aa96318d339a67de1085e0ae495d57c84 (patch) | |
tree | db85c16d03b52399d6c109eda7ea0341a0de0b1d /tmk_core/tool/mbed/mbed-sdk/workspace_tools/host_tests/midi.py | |
parent | 1d5bac21dc6f1425b8ef4bbe7935330c37c3a93e (diff) | |
parent | 1fe4406f374291ab2e86e95a97341fd9c475fcb8 (diff) | |
download | firmware-a3d96d3aa96318d339a67de1085e0ae495d57c84.tar.gz firmware-a3d96d3aa96318d339a67de1085e0ae495d57c84.tar.bz2 firmware-a3d96d3aa96318d339a67de1085e0ae495d57c84.zip |
Merge commit '1fe4406f374291ab2e86e95a97341fd9c475fcb8'
Diffstat (limited to 'tmk_core/tool/mbed/mbed-sdk/workspace_tools/host_tests/midi.py')
-rw-r--r-- | tmk_core/tool/mbed/mbed-sdk/workspace_tools/host_tests/midi.py | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/tmk_core/tool/mbed/mbed-sdk/workspace_tools/host_tests/midi.py b/tmk_core/tool/mbed/mbed-sdk/workspace_tools/host_tests/midi.py new file mode 100644 index 000000000..67f34ea6f --- /dev/null +++ b/tmk_core/tool/mbed/mbed-sdk/workspace_tools/host_tests/midi.py @@ -0,0 +1,72 @@ +from __future__ import print_function +import sys +import re +import time +import mido +from mido import Message + + +def test_midi_in(port): + expected_messages_count=0 + while expected_messages_count < 7: + for message in port.iter_pending(): + if message.type in ('note_on', 'note_off', 'program_change', 'sysex'): + yield message + expected_messages_count+=1 + time.sleep(0.1) + +def test_midi_loopback(input_port): + expected_messages_count=0 + while expected_messages_count < 1: + for message in input_port.iter_pending(): + print('Test MIDI OUT loopback received {}'.format(message.hex())) + expected_messages_count+=1 + +def test_midi_out_loopback(output_port,input_port): + print("Test MIDI OUT loopback") + output_port.send(Message('program_change', program=1)) + test_midi_loopback(input_port) + + output_port.send(Message('note_on', note=21)) + test_midi_loopback(input_port) + + output_port.send(Message('note_off', note=21)) + test_midi_loopback(input_port) + + output_port.send(Message('sysex', data=[0x7E,0x7F,0x09,0x01])) + test_midi_loopback(input_port) + + output_port.send(Message('sysex', data=[0x7F,0x7F,0x04,0x01,0x7F,0x7F])) + test_midi_loopback(input_port) + + output_port.send(Message('sysex', data=[0x41,0x10,0x42,0x12,0x40,0x00,0x7F,0x00,0x41])) + test_midi_loopback(input_port) + + output_port.send(Message('sysex', data=[0x41,0x10,0x42,0x12,0x40,0x00,0x04,0x7F,0x3D])) + test_midi_loopback(input_port) + +portname="" + +while portname=="": + print("Wait for MIDI IN plug ...") + for name in mido.get_input_names(): + matchObj = re.match( r'Mbed', name) + + if matchObj: + portname=name + time.sleep( 1 ) + +try: + input_port = mido.open_input(portname) + output_port = mido.open_output(portname) + + print('Using {}'.format(input_port)) + + print("Test MIDI IN") + + for message in test_midi_in(input_port): + print('Test MIDI IN received {}'.format(message.hex())) + + test_midi_out_loopback(output_port,input_port) +except KeyboardInterrupt: + pass
\ No newline at end of file |