Recording Lights are looking for advice || help

Hello!
I'm making "ON AIR" sign. It seemed an easy task. I got Arduino UNO, installed HairlessMIDI , wrote something that looks like a code. Everything works great: Cubase sends MIDI message when I press REC/STOP buttons - HairlessMIDI converts it to Serial - Arduino turns the LED on/off. I was happy for some time but then I noticed a strange thing: when I add a new track in Cubase project it seems that something goes wrong because after that Arduino does't respond and it lasts up to the moment when I turn the HairlessMidi off or (!!!) do Command-Z (undo). I checked the MidiMonitor and it turned out that in a moment I create a new track, Cubase sends tons of midi messages to Arduino. Unfortunately I'm a beginner with Arduino and don't know how to make it to ignore this crazy message flush. Also it is impossible to make Cubase not to send these messages.
In Cubase I used Mackie Control to send midi to Arduino through the IAC driver.

I think that there is some mistake/s in my coding or I need to add something to it (may be something that should clean the buffer or reboot Arduino after creating a new track). Or may be that's just the lack of HairlessMIDI soft and I should solder the midi shield (I'll do that anyway).

Don't want to give up and do need some help or advise. :confused:

Actually I have two versions of code (both of them work but none can survive Cubase message attack).

The "code":

byte incomingByte;
byte noteByte;
byte velocityByte;
byte noteOn=144;

void setup(){
  Serial.begin(38400);
  pinMode(12,OUTPUT);
}
void checkIn(){
    if(Serial.available () > 2){
      incomingByte = Serial.read();
      noteByte = Serial.read();
      velocityByte = Serial.read();
      if (incomingByte == noteOn){
    if (noteByte == 95 && velocityByte > 0){
                digitalWrite(12,HIGH);
}
}
      if (incomingByte == noteOn){
      if (noteByte == 93 && velocityByte >0){
                 digitalWrite(12,LOW);
}
}
}
}
void loop()
{
 checkIn(); 
}

Thank you!

Ok, small update: I edited the code and added:

else {
 
delay(1);         
Serial.begin(57600);

Partially it helped but I think that's not a correct way to flush the buffer since there is no consistency (sometimes it works, sometimes not).
Just for the case a full version of updated code:

byte incomingByte;
byte noteByte;
byte velocityByte;
byte noteOn=0x90;

void setup(){
  Serial.begin(57600);
  pinMode(12,OUTPUT);
}
void checkIn(){
    if(Serial.available () > 2){
      incomingByte = Serial.read();
      noteByte = Serial.read();
      velocityByte = Serial.read();
      if (incomingByte == noteOn & noteByte == 95 & velocityByte > 0){
                digitalWrite(12,HIGH);
}
else {
    if (incomingByte == noteOn & noteByte == 93 & velocityByte >0){
                 digitalWrite(12,LOW);
}   

else {
delay(1);         
Serial.begin(57600);
}
}
}
}

void loop()
{
 checkIn(); 
}

Still need some advice :confused:

Oh! Arduino day! Now I got rid of the "void" and put everything in the loop leaving Serial.begin there as well.
I increased the baud rate up to 115200 and changed the stop note to the same as record but with the different velocity (it's more like DAW style).
As a result more consistency but still couple times during the testing the system refused to respond.

Any ideas?

Now it looks like this:

byte incomingByte;
byte noteByte;
byte velocityByte;
byte noteOn=0x90;


void setup(){
Serial.begin(115200);
pinMode(12,OUTPUT);
}

void loop()
{
    delay(2);         
    Serial.begin(115200);
{
   if(Serial.available () > 2){
     incomingByte = Serial.read();
     noteByte = Serial.read();
     velocityByte = Serial.read();
     if (incomingByte == noteOn & noteByte == 95 & velocityByte > 0){
               digitalWrite(12,HIGH);
}
else 
   if (incomingByte == noteOn & noteByte == 95 & velocityByte ==0){
                digitalWrite(12,LOW);
}   
}
}
}

Ok, found the problem in my project. I was testing the system in empty Cubase project (without any plugins and fx tracks etc.). Today during mixing decided to test it in actual project and here we are - some compressor sends (!!!) midi messages!!! That's a catastrophe cause Arduino stopped responding again.
I'm in despair!!!
Ate a chicken and a cake - didn't help.
I do not understand why Arduino acts like this. Does anybody know any issues with HairlessMidi and Arduino? Or is it my crap coding skills? Need a midi expert. Help!!??? Please!

Eh! So it seems to me that the chicken and the cake worked well enough. Found the solution!
My first (and the main) mistake was to use the Mackie Control protocol to send the REC/STOP messages to Arduino. I thought I hadn't had a choice because my mixing console also use it (a guess was since it works with the console it will work with Arduino). Wrong! Cubase sends tons of midi messages through that protocol during any actions the user takes. Arduino can't live with that. And so do I. Well when I was done with the food suddenly a simple decision came up to me: I can use Generic Remote to send the same messages (happy thought). I changed the code a bit and voila - everything works! Of course it should be roughly tested during some recording session. I'll post the results tomorrow after the session both with the (I hope) working code.
Sorry for that "story of my life" but that's my first Arduino project and when somethings works as it was planned it makes me so happy (well, until it works). :slight_smile:

Glad to hear you got it working! Cake always helps! :slight_smile:

I'm not as advanced on audio yet, but was interested in your problem. Let us know how it goes! :slight_smile:

Hey! Thanks!))

Ok, now as promised - a report.
It works! 6 hours session and the LED on Arduino shines every time I press Rec button! It's beautiful
(LEDs actually always beautiful but this one is the best!)!
For now the first step is over.
Actually there should be 3 of them:
Next step:
a) soldering the midi shield (in oder to get rid of HairlessMidi - it's great but don't want to start it every time I start the computer. And also can't stop checking if it is on or off).
b) connecting the wires to the signs.
The third one (it frightens me the most): soldering GPIO (RS232) shield and coding to make the Tascam CD Recoder start recording whenever the the REC button in Cubase is pressed. Well, may be this time it will take less time. Hope to unite two codes. But that's for another post.

Code (may be someone will find it helpful):

byte incomingByte;
byte noteByte;
byte velocityByte;
byte noteOn=0x90;

void setup(){
Serial.begin(38400);
pinMode(12,OUTPUT);
}

void loop()
{
     if(Serial.available () > 2){
       incomingByte = Serial.read();
        noteByte = Serial.read();
          velocityByte = Serial.read();
     if (incomingByte == noteOn & noteByte == 95 & velocityByte ==127){
                digitalWrite(12,HIGH);
}
else if (incomingByte == noteOn & noteByte == 93 & velocityByte ==127){
                 digitalWrite(12,LOW);
}   
}
}

It's simple but it works. May be someone could suggest more elegant version - I'd be thankful.

That's it!
Hope to post later about all the steps how to make Recoding Lights work for Cubase and Pro Tools.
I'd be glad to help if somebody has any questions about the project. :slight_smile:

Thanks!

hi, gabermusic, haven't recieved your feedback so far, i use cubase on windows platform and i have the same task as u. but you described the scheme of solving task in general , i still need some help on this topic, could u please answer me?