Midi-Channel

P
Pete posted Feb 23 '19, 16:42:

How can i change the MIDI-Channel...? The code-line "if messagechannel ==2:" don't work... What is the correct modification in "samplerbox.py" ?

Regards
Pete

P
Pete posted Feb 24 '19, 16:13:

Hello again...

What must be changed in this code below, for using only one midi-channel in Samplerbox...?

def MidiCallback(message, time_stamp):
global playingnotes, sustain, sustainplayingnotes
global preset
messagetype = message[0] >> 4
messagechannel = (message[0] & 15) + 1
note = message[1] if len(message) > 1 else None
midinote = note
velocity = message[2] if len(message) > 2 else None

Kind Regards
Peter

H
HansEhv posted Feb 24 '19, 22:45:

Hi Pete,
You used the correct code-line. Possible pitfalls:
1)
The channel numbering: if you need channel 1 (default=keyboard), the test should be "..==1"; midi sends channel 1-16 as 0-15 in the protocol, hence the "...+ 1" in the code.
2)
Did you indent all statements following it (belonging to this if statement) ?
Python does not have an end-if, the if statements are regocnized by level of indentation, so you need to be precise with that.

J
Joe posted Mar 28 '19, 01:42:

I was able to get this working - I set a variable I called MIDI_CHAN = 14 in the LOCAL CONFIG section

then in the AUDIO AND MIDI CALLBACKS section I modified as below:

def MidiCallback(message, time_stamp):
global playingnotes, sustain, sustainplayingnotes
global preset
messagetype = message[0] >> 4
messagechannel = (message[0] & 15) + 1
note = message[1] if len(message) > 1 else None
midinote = note
velocity = message[2] if len(message) > 2 else None

existing code above

if messagechannel != MIDI_CHAN:                                   # These lines check the MIDI_CHAN variable and discard any messages  
    return                                                                             # that don't match the channel 

Existing code below

if messagetype == 9 and velocity == 0:
    messagetype = 8
...

  (not published)
  I want to post as guest
 

Post