switch(MIDI.getType()) - working only first process #267
-
Hello, if i'm use processing with getType(), working only first case with noteOn, second ControlChange not working. If exchange it, first CC and second NoteOn, working only CC case. With handle processing, without getType() working all fine. switch(MIDI.getType())
{
case midi::NoteOn: // this working OK
uint8_t note = MIDI.getData1();
if (note==33||note==35||note==36) kickstate = 1;
break;
case midi::ControlChange: // not working
digitalWrite(13, HIGH); // for indication, defined in setup as output, not used elsewhere
uint8_t cc = MIDI.getData1();
uint8_t val = MIDI.getData2();
if (cc==102 && val > 0 && val < 17) count=val;
if (cc==103 && val > 0 && val < 9) scene=val-1;
break;
default:
break;
} Arduino IDE 1.8.9, Atmega328P without bootloader in my own board programmed via usbasp Best Regards! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
Can I see the rest of your code please?
I would generally suggest to use callbacks to perform this kind of "if this type of message arrived, then do this" switching. In your case: void handleNoteOn(byte channel, byte note, byte velocity) {
if (note==33||note==35||note==36) kickstate = 1;
}
void handleControlChange(byte channel, byte number, byte value) {
digitalWrite(13, HIGH); // for indication, defined in setup as output, not used elsewhere
if (number==102 && value > 0 && value < 17) count=value;
if (number==103 && value > 0 && value < 9) scene=value-1;
}
void setup() {
MIDI.begin();
MIDI.setHandleNoteOn(handleNoteOn);
MIDI.setHandleControlChange(handleControlChange);
}
void loop() {
MIDI.read();
} |
Beta Was this translation helpful? Give feedback.
Can I see the rest of your code please?
MIDI.getType
only returns the type of the last message received, so depending on where and when you call it, it may behave differently.I would generally suggest to use callbacks to perform this kind of "if this type of message arrived, then do this" switching.
In your case: