Skip to content
Open
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
16 changes: 13 additions & 3 deletions samplerbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,13 +384,23 @@ def display(s):

if USE_SERIALPORT_MIDI:
import serial
ser = serial.Serial(SERIALPORT_PORT, baudrate=SERIALPORT_BAUDRATE)
def MidiSerialCallback():
message = [0, 0, 0]
ser = None
while True:
if ser is None:
try:
ser = serial.Serial(SERIALPORT_PORT, baudrate=SERIALPORT_BAUDRATE)
except serial.serialutil.SerialException:
continue
i = 0
while i < 3:
data = ord(ser.read(1)) # read a byte
while i < 3 and ser is not None:
try:
data = ord(ser.read(1)) # read a byte
except serial.serialutil.SerialException:
ser = None
message = [0, 0, 0]
break
if data >> 7 != 0:
i = 0 # status byte! this is the beginning of a midi message: http://www.midi.org/techspecs/midimessages.php
message[i] = data
Expand Down