|
2 | 2 | # |
3 | 3 | # SPDX-License-Identifier: Unlicense |
4 | 4 |
|
5 | | -import audiopwmio |
6 | 5 | import board |
| 6 | +import busio |
7 | 7 | import synthio |
8 | 8 | import adafruit_midi |
9 | 9 | import adafruit_usb_host_midi |
10 | 10 | import usb.core |
11 | 11 | from adafruit_midi.note_on import NoteOn |
12 | 12 | from adafruit_midi.note_off import NoteOff |
| 13 | +from adafruit_midi.control_change import ControlChange |
| 14 | +from adafruit_midi.pitch_bend import PitchBend |
13 | 15 |
|
14 | 16 | print("Looking for midi device") |
15 | 17 | raw_midi = None |
|
21 | 23 | except ValueError: |
22 | 24 | continue |
23 | 25 |
|
24 | | -# This setup is for pin D4 on Feather RP2040 with USB Type A Host |
25 | | -# You must wire this up yourself to an RC filter and headphones or line in of an amp |
26 | | -audio = audiopwmio.PWMAudioOut(board.D4) |
27 | | -synth = synthio.Synthesizer(sample_rate=22050) |
28 | | -audio.play(synth) |
| 26 | +# This setup is to use TX pin on Feather RP2040 with USB Type A Host as MIDI out |
| 27 | +# You must wire up the needed resistors and jack yourself |
| 28 | +# This will forward all MIDI messages from the device to hardware uart MIDI |
| 29 | +uart = busio.UART(rx=board.RX, tx=board.TX, baudrate=31250, timeout=0.001) |
29 | 30 |
|
30 | | -midi = adafruit_midi.MIDI(midi_in=raw_midi, in_channel=0) |
| 31 | +midi_device = adafruit_midi.MIDI(midi_in=raw_midi, in_channel=0) |
| 32 | +midi_uart = adafruit_midi.MIDI(midi_out=uart, midi_in=uart) |
31 | 33 |
|
32 | | -pressed = {} |
33 | 34 |
|
34 | 35 | while True: |
35 | | - msg = midi.receive() |
36 | | - if isinstance(msg, NoteOn) and msg.velocity != 0: |
37 | | - note = synthio.Note(synthio.midi_to_hz(msg.note)) |
38 | | - print("noteOn: ", msg.note, "vel:", msg.velocity) |
39 | | - synth.press(note) |
40 | | - pressed[msg.note] = note |
41 | | - elif (isinstance(msg,NoteOff) or (isinstance(msg,NoteOn) and msg.velocity==0)) and msg.note in pressed: |
42 | | - print("noteOff:", msg.note, "vel:", msg.velocity) |
43 | | - note = pressed[msg.note] |
44 | | - synth.release(note) |
45 | | - del pressed[msg.note] |
| 36 | + msg = midi_device.receive() |
| 37 | + if msg: |
| 38 | + print("midi msg:",msg) |
| 39 | + midi_uart.send(msg) |
0 commit comments