I was writing this program for a new system im designing and (im a midi noob) ran into the time clock that all systems seem to output (except ableton, which I have been using this whole time). Because of the way my program is written it seems to be overloaded when the clock is running. I would like to just filter out the clock and other things so that it can run as it was before, just on the note commands (on/off/channel, note played, velocity). I could turn them off in the recording program, but I need the to go thru
arduino 328
usbtinyisp
here is my code:
#include <MIDI.h>
#include <EEPROM.h>
byte commandByte;
byte noteByte;
byte velocityByte;
byte c=0;
byte v=0;
int x=0;
int i=0;
int MIDIchannel=0;
byte y=1;
int pbIn=0;
byte chan=EEPROM.read(0);
byte note=EEPROM.read(1);
int syncLED=13; //LED that turns on when sync button is pushed
int syncpin=2; // Pin that is checked if sync button is pushed
byte a=0;
byte b=0;
MIDI_CREATE_DEFAULT_INSTANCE();
//......................................................................................
void setup(){
for ( i=2; i<18; i++) // set digital/analog outputs
{
pinMode(i,OUTPUT);
analogWrite(i,LOW);
}
digitalWrite(syncpin,HIGH);
MIDI.begin(MIDI_CHANNEL_OMNI); //accept all midi channels for filtering later
}
//...
void loop(){
if(digitalRead(syncpin)==HIGH) //check to see if momentary off button is pushed
sync();
checkMIDI(); // check for incoming signals
delay(10);
}
//...
void sync(){ //check for sync and input note+channel designation
digitalWrite(syncLED, HIGH);
do{
if (Serial.available()>2){ //if any messages are incoming to be processed
commandByte = Serial.read();//read first
noteByte = Serial.read();//read next byte
chan=commandByte;
note=noteByte;
velocityByte = Serial.read();//read final byte
if( EEPROM.read(0) != chan) // store channel and note values for retrievel when unit is turned off and on
EEPROM.write(0,chan); // wont rewrite unless different then stored value
if( EEPROM.read(1) != note)
EEPROM.write(1,note);
digitalWrite(syncLED,LOW);
}
}
while(digitalRead (syncLED)==HIGH);
}
//....................................................................
boolean checkChannel(byte c , byte v){ //read and compare voltage numbers
if( c-v==0 || c-v+16==0){ // compare the saved value to the incoming value (for both on and off in any particular channel)
return(true); // off is always 16 numbers apart from on so I just saved some time and used math
}
else
return(false);
}
boolean checkNote(byte a, byte b){
if (a-b==0)
return(true);
else
return(false);
}
//........................................................................
void checkMIDI(){
do{
if (Serial.available()>2){ //if any messages are incoming to be processed
commandByte = Serial.read();//read first
Serial.write(commandByte);
noteByte = Serial.read();//read next byte
Serial.write(noteByte); // all Serial.writes are for midi out
velocityByte = Serial.read();//read final byte
Serial.write(velocityByte);
if (checkChannel(commandByte,chan)==true && checkNote(noteByte,note)==true){
if(commandByte >= 144 && commandByte <= 159) //check if on command
analogWrite(9,velocityByte);//turn on led 9
if(commandByte >=128 && commandByte <= 143) //check if off command
digitalWrite (9,LOW); //turn off led 9
break; //break the loop
}
}
}
while (Serial.available()>2);//when at least three bytes available
}
moderator: added code tags == # button above smileys