usb-device-midi: Add additional console output on TX.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
Angus Gratton 2024-04-09 14:07:40 +10:00
rodzic 87cc34e202
commit eb583b49e5
1 zmienionych plików z 23 dodań i 4 usunięć

Wyświetl plik

@ -14,6 +14,16 @@ import time
class MIDIExample(MIDIInterface):
# Very simple example event handler functions, showing how to receive note
# and control change messages sent from the host to the device.
#
# If you need to send MIDI data to the host, then it's fine to instantiate
# MIDIInterface class directly.
def on_open(self):
super().on_open()
print("Device opened by host")
def on_note_on(self, channel, pitch, vel):
print(f"RX Note On channel {channel} pitch {pitch} velocity {vel}")
@ -35,17 +45,26 @@ while not m.is_open():
print("Starting MIDI loop...")
# TX constants
CHANNEL = 0
PITCH = 60
CONTROLLER = 64
control_val = 0
channel = 0
while m.is_open():
time.sleep(1)
m.note_on(channel, 60)
print(f"TX Note On channel {CHANNEL} pitch {PITCH}")
m.note_on(CHANNEL, PITCH) # Velocity is an optional third argument
time.sleep(0.5)
m.note_off(channel, 60)
print(f"TX Note Off channel {CHANNEL} pitch {PITCH}")
m.note_off(CHANNEL, PITCH)
time.sleep(1)
m.control_change(channel, 64, control_val)
print(f"TX Control channel {CHANNEL} controller {CONTROLLER} value {control_val}")
m.control_change(CHANNEL, CONTROLLER, control_val)
control_val += 1
if control_val == 0x7F:
control_val = 0
time.sleep(1)
print("USB host has reset device, example done.")