problem was that MIDI library has parameters in different orders for different functions:
void noteon(byte channel, byte note, byte velocity) {
MIDI.sendNoteOn( note + transpose, velocity, channel );
}
So, i wrote this code and it works. BUT got a new problem..
I added a midi panic button (that works preety well) and a "push button switch" for real time transposition.
When i press the button: messages are transposed
Problem is that if i press the button during a note off message, transposition starts from that message and the previous note on message keeps playing.
Example
Time note message
00 C1 ON
01 C1 OFF
02 C1 ON
03 D1 OFF <----- transpose button is pressed. Note off message for C1 is transposed. C1 keeps playing.
04 D1 ON C1 still ON
05 D1 OFF C1 still ON
... .. .... C1 still ON
So, i though that i should insert in void loop() a code like:
when the button state is HIGH
if the current message is a note off
don't traspose it
if the current message is a note on
transpose it
do this instruction just one time
when the button state is LOW
if the current message is a note off
don't transpose it
if the current message is a note on
transpose it
do this instruction just one time
What do you think about it? would it be the right way?
thanks for your attention..
#include <MIDI.h>
const int InputTriggerTranspose = 7; // port for the push button transpose switch
byte transpose = 0;
byte last_type, last_ch, last_note, last_vel;
const int InputTriggerPanic = 2; // port for the working midi panic button
int Panic = 0;
void noteon(byte channel, byte note, byte velocity) {
digitalWrite( 13, HIGH );
last_type = 1;
last_ch = channel;
last_note = note;
last_vel = velocity;
}
void noteoff(byte channel, byte note, byte velocity) {
digitalWrite( 13, LOW );
last_type = 2;
last_ch = channel;
last_note = note;
last_vel = velocity;
}
void setup() {
pinMode (2, INPUT);
pinMode (7, INPUT);
pinMode( 13, OUTPUT );
MIDI.begin();
MIDI.setInputChannel( MIDI_CHANNEL_OMNI ); // listen to all channels
MIDI.turnThruOff(); // turn off thru mode
MIDI.setHandleNoteOn(noteon); // call noteon when a note on message is received
MIDI.setHandleNoteOff(noteoff); // call noteoff when a note off message is received
last_type = 0;
}
void loop() {
Panic = digitalRead(InputTriggerPanic);
if (Panic == HIGH) {
MIDI.sendControlChange(120, 0, last_ch); // midi panic message
}
transpose = digitalRead(InputTriggerTranspose);
if (transpose == HIGH) {
transpose = 7;}