Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions examples/midi_simpletest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

# simple_test
import time
import random
Expand All @@ -11,23 +10,22 @@
from adafruit_midi.note_on import NoteOn
from adafruit_midi.pitch_bend import PitchBend

midi = adafruit_midi.MIDI(midi_out=usb_midi.ports[1], out_channel=0)

print(usb_midi.ports)
midi = adafruit_midi.MIDI(
midi_in=usb_midi.ports[0], in_channel=0, midi_out=usb_midi.ports[1], out_channel=0
)
print("Midi test")

# Convert channel numbers at the presentation layer to the ones musicians use
print("Default output channel:", midi.out_channel + 1)
print(
"Listening on input channel:",
midi.in_channel + 1 if midi.in_channel is not None else None,
)

print("Listening on input channel:", midi.in_channel + 1)
while True:
midi.send(NoteOn(44, 120)) # G sharp 2nd octave
time.sleep(0.25)
a_pitch_bend = PitchBend(random.randint(0, 16383))
midi.send(a_pitch_bend)
time.sleep(0.25)
# note how a list of messages can be used
midi.send([NoteOff("G#2", 120), ControlChange(3, 44)])
time.sleep(0.5)
msg = midi.receive()
if msg is not None:
print("Received:", msg, "at", time.monotonic())