Skip to content

Commit 8531101

Browse files
committed
add example description
1 parent c3e450d commit 8531101

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

examples/tmidi_simple_receiver.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2024 Tod Kurt
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
# This example shows how to receive MIDI NoteOn and NoteOff messages
6+
7+
import usb_midi
8+
import tmidi
9+
10+
midi_usb = tmidi.MIDI(midi_in=usb_midi.ports[0], midi_out=usb_midi.ports[1])
11+
12+
while True:
13+
if msg := midi_usb.receive():
14+
if msg.type == tmidi.NOTE_ON and msg.velocity > 0:
15+
print("note on: ", msg.note, msg.velocity)
16+
elif msg.type == tmidi.NOTE_OFF or msg.velocity == 0:
17+
print("note off:", msg.note, msg.velocity)

0 commit comments

Comments
 (0)