Might be of interest, a little enhancement about the note on/off handling
to avoid a note off to cut short any new playing note...
EDIT: I forgot to wrote channel check, added now ^_^
SID effect have also been done...:)
In your Teensy board code >>
add a variable to keep track of the latest MIDI note on number
byte p_pitch;
byte p_channel;
then in the function : void doNoteon ()
add:
p_pitch = pitch;
p_channel = channel;
each time there is a check for velocity >0
then in : void doNoteOff()
if(pitch == p_pitch) // avoid note cuts
{
velocityData[channel + (chip_select * 4)] = 0;
writeAmplitude(0, channel, chip_select);
}
else if((pitch != p_pitch) && (channel != p_channel))
{
velocityData[channel + (chip_select * 4)] = 0;
writeAmplitude(0, channel, chip_select);
}
then in in the function : void doMidiIn ()
//note on
Line : else if((data < 0x80) && (flag_previous == 1))
add , p_pitch = data;
Line :if((data >= 0x90) && (data < 0xa0) && (flag_previous == 0))
add, p_channel =channel;
this will keep track of the previous note played when there is a note off message next
//note off
else if((data < 0x80) && (flag_previous == -2))
{
velocity = data;
if(pitch == previous_pitch) // only if previous pitch is the same!...to avoid note cuts
{
doNoteOff(channel, pitch, velocity);
}
else if((pitch != p_pitch) && (channel != p_channel)) // if pitch is not the same BUT from another channel
{
velocityData[channel + (chip_select * 4)] = 0;
writeAmplitude(0, channel, chip_select);
}
flag_previous = 0;
}
Last edited by Aly James (Nov 19, 2013 7:31 am)