Go Down

Topic: Pro Tools Rec Light (Read 1 time) previous topic - next topic

gabermusic

Hello!
I'm trying to make Pro Tools Rec Light. And I actually made it . But I have a strong desire that Pro Tools sends messages to Arduino through HUI protocol.

Ok.   
I have Arduino Uno. Midi shield. M-audio card with MIDI Out. First I thought that there should be Sysex data mess
but (how lucky I am) it sends Control Change messages.
So PT sends messages, Arduino gets them, the Lights are ON/Off.

That's the code:
Code: [Select]
#include <MIDI.h>

MIDI_CREATE_DEFAULT_INSTANCE();

       void setup()
{
 pinMode(13,OUTPUT);
  MIDI.begin();
  MIDI.setHandleControlChange(MyCC);
 
}
       void loop() {
 
       
MIDI.read();
 
 }

void MyCC(byte channel, byte controller, byte value ) {

   
  if(channel==1)

 if(controller==44)

 if(value==69)

 digitalWrite(13,HIGH);

 if(channel==1)

 if(controller==44)

 if(value==5) 
 
  digitalWrite(13,LOW);
 

 }
 





Everything is perfect! Except one small thing: when I press alt/opt button ....Rec lights are also ON!
With the help of Midi Monitor I've learned that this cunning HUI sends at least two messages for all the buttons.

So : to turn the REC On PT sends

1) channel 1,  controller 12, value 14
2) channel 1,  controller 44, value 69

to turn the REC Off

1) channel 1,  controller 12, value 14
2) channel 1,  controller 44, value 5


I've got theory: first message is some kind of a name of a button and the second one is the command itself.


And ALT/OPT button (by the way I hate it for now))) sends:
1) channel 1,  controller 12, value 8
2) channel 1,  controller 44, value 69


And here is the point: I'm a beginner with Arduino and I can't figure out how I can make the board react on two messages and  interpret them as one.


Please help.
Thank you! And sorry for my English it's not a native language for me.





Grumpy_Mike

Quote
I've got theory: first message is some kind of a name of a button and the second one is the command itself.
Officially
CC 12 is Effect Control 1
CC 44 is LSB for Control 12 (Effect control 1)

So one way to do this would have each CC message set the appropriate part of the number then combine them like this.
Code: [Select]
effectsController = (ccMessage1Value << 7) | ( ccMessage44Value & 0x7F);

gabermusic

Thank you!
I'll try to fight this through))

gabermusic

I vaguely understand  but I work on it. One question before I take a deep dive into it:
Code: [Select]
effectsController = (ccMessage1Value << 7) | ( ccMessage44Value & 0x7F);  - all the the values are just examples? I'm a bit confused with 0x7F (since PT doesn't send value 127, at least connected with Rec button). Sorry to bother.

Grumpy_Mike

Quote
I'm a bit confused with 0x7F
This value is a bit mask, it ensures that the value you are adding to the number is restricted to the range 0 to 127. It should already be in this range but just to make sure it does no harm to force it not to overflow.

Quote
all the the values are just examples?
Not sure what you mean by values? Do you mean variables? If so yes the variables have names that illustrate what sort of value they hold. It is a good idea to write your code like this so you know what sort of values these variables will contain.

gabermusic

I'm sorry I'm too slow at programming languages. ))
I went to the reference and read about <<, | and &. It helped a bit but not too much.

oook. I understand that I 've got a lot of questions but:
Am I right considering this:  
Code: [Select]
effectsController = (ccMessage1Value << 7) | ( ccMessage44Value & 0x7F); - as a math expression? And if yes  should I get a resulting numeric value?  And again if yes, what is the numeric value of this expression?   

If we consider that:
ccMessage1Value =14
ccMessage44Value=69

Will it be correct to write it down like this:

Code: [Select]
effectsController = (14 << 7) | ( 69 & 0x7F); ?

Thank you!

Grumpy_Mike

#6
Oct 14, 2016, 11:45 pm Last Edit: Oct 14, 2016, 11:45 pm by Grumpy_Mike
Quote
Am I right considering this:  
Code: [Select]

effectsController = (ccMessage1Value << 7) | ( ccMessage44Value & 0x7F);

- as a math expression?
Not quite it is a program statement. If it were maths the = would mean "is equal to" but as a program statement the = means "make it equal to"

Quote
If we consider that:
ccMessage1Value =14
ccMessage44Value=69

Will it be correct to write it down like this:......
Yes.

So what will the value of the variable effectsController be?

Basically you are making one number from two part numbers. The one number has 14 bits and the two part numbers have 7 bits each.


gabermusic

Thank you! Now I got it!  It's beautiful.

And of course the coding. It took me pretty long but I'm not sure if I used the idea correctly:
Code: [Select]
#include <MIDI.h>

byte ExpressionContr1;
byte ExpressionContr2;
byte ExpressionContr3;

MIDI_CREATE_DEFAULT_INSTANCE();

     void setup()
{
pinMode(13,OUTPUT);
MIDI.begin();
MIDI.setHandleControlChange(MyCC);

}
     void loop() {
 
MIDI.read();
}

void MyCC( byte channel, byte controller, byte value ) {

if (ExpressionContr1=(channel==1<<7)|(channel==1&15 ))
if (ExpressionContr2=(controller==0xC <<7) | (controller==0x2C&0x7F ))
if (ExpressionContr3=(value ==0xE <<7) | (value ==0x45&0x7F ))

digitalWrite(13,HIGH);

if (ExpressionContr1=(channel==1<<7)|(channel==1&15 ))
if (ExpressionContr2=(controller==0xC <<7) | (controller==0x2C&0x7F ))
if (ExpressionContr3=(value ==0xE <<7) | (value ==0x5&0x7F ))
digitalWrite(13,LOW);

}


Since it still works as before (i.e. alt/opt also turns the lights on) something is wrong. May be I shouldn't declare "ExpressionContrs" as bytes?
Thank you!

Grumpy_Mike

Quote
May be I shouldn't declare "ExpressionContrs" as bytes?
That's right.

As the variables ExpressionContr are trying to hold a 14 bit number then bytes will not be big enough. While the value variables can be bytes ( a byte is 8 bits ) when you combine the two you need a type of variable with more bits. Use a int type variable, this will hold a maximum of 16 bits. The fact you only need 14 of them is not important because an int is the smallest variable type that will fit your number.

gabermusic

I changed  "bytes" to "ints" but "alt/opt" still lights the Led. I suppose that there is something wrong with my "if" statements. Somehow the board can't differ the messages.

Code: [Select]
#include <MIDI.h>

int ExpressionContr1;
int ExpressionContr2;
int ExpressionContr3;

MIDI_CREATE_DEFAULT_INSTANCE();

    void setup()
{
pinMode(13,OUTPUT);
MIDI.begin();
MIDI.setHandleControlChange(MyCC);

}
    void loop() {

MIDI.read();
}

void MyCC( byte channel, byte controller, byte value ) {

if (ExpressionContr1=(channel==1<<7)|(channel==1 & 15 ))
if (ExpressionContr2=(controller==0xC <<7) | (controller==0x2C & 0x7F ))
if (ExpressionContr3=(value ==0xE <<7) | (value ==0x45 & 0x7F ))

digitalWrite(13,HIGH);

if (ExpressionContr1=(channel==1<<7)|(channel==1 & 15 ))
if (ExpressionContr2=(controller==0xC <<7) | (controller==0x2C & 0x7F ))
if (ExpressionContr3=(value ==0xE <<7) | (value ==0x5 & 0x7F ))
digitalWrite(13,LOW);

}

Grumpy_Mike

Yes they are all wrong. First off you need a double equal sign in them to compare anything. But the big mistake is that you first fill your Expression control variable with a value you device from the MIDI messages and then you test it with an if statement to see if it is the number you are looking for.
When you find that it is that number then you do something about it like controlling your LED. The if statement when true will execute the statement following or the block following defined in curly braces.

You need to post all the code you have not just a part as I suspect more of it is totally wrong like this.

gabermusic

You need to post all the code you have not just a part as I suspect more of it is totally wrong like this.
That is all code I've got. I just want to make this rec light to shine and nothing more. :)



First off you need a double equal sign in them to compare anything. But the big mistake is that you first fill your Expression control variable with a value you device from the MIDI messages and then you test it with an if statement to see if it is the number you are looking for.
When you find that it is that number then you do something about it like controlling your LED. The if statement when true will execute the statement following or the block following defined in curly braces.
I changed the code a bit and again I'm not sure I did it correctly:
Code: [Select]
#include <MIDI.h>

int ExpressionContr1 = 1;
int ExpressionContr2 = (0xC, 0x2C) ;
int ExpressionContr3 = (0xE ,0x45) ;
int ExpressionContr4 = (0xE,0x5);
MIDI_CREATE_DEFAULT_INSTANCE();

     void setup()
{
pinMode(13,OUTPUT);
MIDI.begin();
MIDI.setHandleControlChange(MyCC);

}
     void loop() {
 
MIDI.read();
}

void MyCC( byte channel, byte controller, byte value ) {
 

if (ExpressionContr1==(channel==1<<7)|(channel==1 & 15 ))
if (ExpressionContr2==(controller==0xC <<7) | (controller==0x2C & 0x7F ))
if (ExpressionContr3==(value ==0xE <<7) | (value ==0x45 & 0x7F ))

digitalWrite(13,HIGH);

if (ExpressionContr1==(channel==1<<7)|(channel==1 & 15 ))
if (ExpressionContr2==(controller==0xC <<7) | (controller==0x2C & 0x7F ))
if (ExpressionContr4==(value ==0xE <<7) | (value ==0x5 ))
digitalWrite(13,LOW);

}


But something is still wrong.
Tried different ways to write the variables:
Code: [Select]
int ExpressionContr2 = 0xC| 0x2C ;

Code: [Select]
int ExpressionContr2 = (0xC)| (0x2C) ;
Alt/opt still disturbs.


I experimented with the  code: when I change the placements of notes ("reversed sequence") alt/opt is out of the game, but now the "play" button turns the light on(for a short time). Argh!

Grumpy_Mike

#12
Oct 16, 2016, 05:59 pm Last Edit: Oct 16, 2016, 09:02 pm by Grumpy_Mike
OK that code it totally screwed in many many ways.
This is something on the right track. I have not tested it but it does compile. See if you can understand what it is doing. The "magic numbers" might not be right.

Code: [Select]

#include <MIDI.h>
// I assume these are the right magic numbers
int ExpressionContr1 = 1;
int ExpressionContr2 = (0xC << 7) | 0x2C ;
int ExpressionContr3 = (0xE<< 7) | 0x45 ;
int ExpressionContr4 = (0xE<<7) | 0x5;
int controlRecieved;
byte ccMessage12Value;
byte ccMessage44Value;
boolean ledState;

MIDI_CREATE_DEFAULT_INSTANCE();

void setup(){
pinMode(13,OUTPUT);
MIDI.begin();
MIDI.setHandleControlChange(MyCC);
}

void loop() {
MIDI.read();
}

void MyCC( byte channel, byte controller, byte value ) {
 // build up your full message
  if(controller == 44){
  ccMessage44Value = value;
  ccMessage12Value = 0; // blank MSB of message to stop rapid on / off of LEDs
 }

 if(controller == 12){
  ccMessage12Value = value;

// now put them together into one variable
controlRecieved = (ccMessage12Value << 7) | ( ccMessage44Value & 0x7F);
// now see if you have anything of intrest
// here you seem to test the same thing to turn it on or off so you need a variable to hold the state you last put the LED
if( (ledState == false) && (controlRecieved == ExpressionContr1 || controlRecieved == ExpressionContr2 ||controlRecieved == ExpressionContr3) ){
      digitalWrite(13,HIGH);
      ledState = true;
    } else {
if( (ledState == true) && (controlRecieved == ExpressionContr1 || controlRecieved == ExpressionContr2 ||controlRecieved == ExpressionContr4) ){
      digitalWrite(13,LOW);
      ledState = false;
     }
    }
  }
}


Please come back with questions about it.

gabermusic

If I could I would hug you!
Thank you million times for your patience and knowledge.
For these three days I've learned much more than for the last 6 months.
It works!   :)

Looking at the code it seems easy and everything is clear now. But I understand that it would take me a year or two (or may be never) to write it!

Thank you!

gabermusic

If I'm right this code will work with any DAW. Will check it tomorrow with Cubase and will post here. ))

Go Up