BBR 1 Ebene

Committer:
borlanic
Date:
Mon May 14 11:29:06 2018 +0000
Revision:
0:fbdae7e6d805
BBR

Who changed what in which revision?

UserRevisionLine numberNew contents of line
borlanic 0:fbdae7e6d805 1 from __future__ import print_function
borlanic 0:fbdae7e6d805 2 import sys
borlanic 0:fbdae7e6d805 3 import re
borlanic 0:fbdae7e6d805 4 import time
borlanic 0:fbdae7e6d805 5 import mido
borlanic 0:fbdae7e6d805 6 from mido import Message
borlanic 0:fbdae7e6d805 7
borlanic 0:fbdae7e6d805 8
borlanic 0:fbdae7e6d805 9 def test_midi_in(port):
borlanic 0:fbdae7e6d805 10 expected_messages_count=0
borlanic 0:fbdae7e6d805 11 while expected_messages_count < 7:
borlanic 0:fbdae7e6d805 12 for message in port.iter_pending():
borlanic 0:fbdae7e6d805 13 if message.type in ('note_on', 'note_off', 'program_change', 'sysex'):
borlanic 0:fbdae7e6d805 14 yield message
borlanic 0:fbdae7e6d805 15 expected_messages_count+=1
borlanic 0:fbdae7e6d805 16 time.sleep(0.1)
borlanic 0:fbdae7e6d805 17
borlanic 0:fbdae7e6d805 18 def test_midi_loopback(input_port):
borlanic 0:fbdae7e6d805 19 expected_messages_count=0
borlanic 0:fbdae7e6d805 20 while expected_messages_count < 1:
borlanic 0:fbdae7e6d805 21 for message in input_port.iter_pending():
borlanic 0:fbdae7e6d805 22 print('Test MIDI OUT loopback received {}'.format(message.hex()))
borlanic 0:fbdae7e6d805 23 expected_messages_count+=1
borlanic 0:fbdae7e6d805 24
borlanic 0:fbdae7e6d805 25 def test_midi_out_loopback(output_port,input_port):
borlanic 0:fbdae7e6d805 26 print("Test MIDI OUT loopback")
borlanic 0:fbdae7e6d805 27 output_port.send(Message('program_change', program=1))
borlanic 0:fbdae7e6d805 28 test_midi_loopback(input_port)
borlanic 0:fbdae7e6d805 29
borlanic 0:fbdae7e6d805 30 output_port.send(Message('note_on', note=21))
borlanic 0:fbdae7e6d805 31 test_midi_loopback(input_port)
borlanic 0:fbdae7e6d805 32
borlanic 0:fbdae7e6d805 33 output_port.send(Message('note_off', note=21))
borlanic 0:fbdae7e6d805 34 test_midi_loopback(input_port)
borlanic 0:fbdae7e6d805 35
borlanic 0:fbdae7e6d805 36 output_port.send(Message('sysex', data=[0x7E,0x7F,0x09,0x01]))
borlanic 0:fbdae7e6d805 37 test_midi_loopback(input_port)
borlanic 0:fbdae7e6d805 38
borlanic 0:fbdae7e6d805 39 output_port.send(Message('sysex', data=[0x7F,0x7F,0x04,0x01,0x7F,0x7F]))
borlanic 0:fbdae7e6d805 40 test_midi_loopback(input_port)
borlanic 0:fbdae7e6d805 41
borlanic 0:fbdae7e6d805 42 output_port.send(Message('sysex', data=[0x41,0x10,0x42,0x12,0x40,0x00,0x7F,0x00,0x41]))
borlanic 0:fbdae7e6d805 43 test_midi_loopback(input_port)
borlanic 0:fbdae7e6d805 44
borlanic 0:fbdae7e6d805 45 output_port.send(Message('sysex', data=[0x41,0x10,0x42,0x12,0x40,0x00,0x04,0x7F,0x3D]))
borlanic 0:fbdae7e6d805 46 test_midi_loopback(input_port)
borlanic 0:fbdae7e6d805 47
borlanic 0:fbdae7e6d805 48 portname=""
borlanic 0:fbdae7e6d805 49
borlanic 0:fbdae7e6d805 50 while portname=="":
borlanic 0:fbdae7e6d805 51 print("Wait for MIDI IN plug ...")
borlanic 0:fbdae7e6d805 52 for name in mido.get_input_names():
borlanic 0:fbdae7e6d805 53 matchObj = re.match( r'Mbed', name)
borlanic 0:fbdae7e6d805 54
borlanic 0:fbdae7e6d805 55 if matchObj:
borlanic 0:fbdae7e6d805 56 portname=name
borlanic 0:fbdae7e6d805 57 time.sleep( 1 )
borlanic 0:fbdae7e6d805 58
borlanic 0:fbdae7e6d805 59 try:
borlanic 0:fbdae7e6d805 60 input_port = mido.open_input(portname)
borlanic 0:fbdae7e6d805 61 output_port = mido.open_output(portname)
borlanic 0:fbdae7e6d805 62
borlanic 0:fbdae7e6d805 63 print('Using {}'.format(input_port))
borlanic 0:fbdae7e6d805 64
borlanic 0:fbdae7e6d805 65 print("Test MIDI IN")
borlanic 0:fbdae7e6d805 66
borlanic 0:fbdae7e6d805 67 for message in test_midi_in(input_port):
borlanic 0:fbdae7e6d805 68 print('Test MIDI IN received {}'.format(message.hex()))
borlanic 0:fbdae7e6d805 69
borlanic 0:fbdae7e6d805 70 test_midi_out_loopback(output_port,input_port)
borlanic 0:fbdae7e6d805 71 except KeyboardInterrupt:
borlanic 0:fbdae7e6d805 72 pass