Skip to content

Commit 0ca9036

Browse files
committed
midi_chords: check only first 4 bits for NoteOn/NoteOff
Before, it was only working for MIDI channel 1!
1 parent d33b6da commit 0ca9036

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

‎examples/midi_chords.py‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
import jack
1010
import struct
1111

12-
NOTEON = 0x90
13-
NOTEOFF = 0x80
12+
# First 4 bits of status byte:
13+
NOTEON = 0x9
14+
NOTEOFF = 0x8
1415

1516
INTERVALS = 3, 7 # minor triad
1617

@@ -26,10 +27,10 @@ def callback(frames, userdata):
2627
# Note: potential errors are ignored! If len(outdata) == 0 -> error
2728
outdata[:] = indata
2829
if len(indata) == 3:
29-
cmd, pitch, vel = struct.unpack('3B', indata)
30-
if cmd in (NOTEON, NOTEOFF):
30+
status, pitch, vel = struct.unpack('3B', indata)
31+
if status >> 4 in (NOTEON, NOTEOFF):
3132
for i in INTERVALS:
32-
outport.write_midi_event(offset, (cmd, pitch + i, vel))
33+
outport.write_midi_event(offset, (status, pitch + i, vel))
3334
# An exception will be raised if MIDI buffer is full
3435
return jack.CALL_AGAIN
3536

0 commit comments

Comments
 (0)