Hey there.
I am trying to make a simple script to read record and stop status from a device that uses MCU Mackie HUI control.
I can get it to see MCU::RECORD and MCU::STOP, so I can trigger it. But I can not figure out how to see the status changes to trigger events.
Currently just trying to fire LED to show status. I've searched the forums here and found multiple approaches but none of them seem to work for me.
One Attempt:
#include <MIDI.h>
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();
MIDI_CREATE_INSTANCE(decltype(Serial), Serial, MIDI);
void setup(){
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
digitalWrite(10, HIGH);
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(9,HIGH);
digitalWrite(10, LOW);
ledState = true;
} else {
if( (ledState == true) && (controlRecieved == ExpressionContr1 || controlRecieved == ExpressionContr2 ||controlRecieved == ExpressionContr4) ){
digitalWrite(9,LOW);
digitalWrite(10, HIGH);
ledState = false;
}
}
}
}
Another Attempt:
#include <Control_Surface.h>
const auto record_led_pin = 9;
const auto stop_led_pin = 10;
// The MIDI over USB interface to use
USBMIDI_Interface midi;
// Custom MIDI callback that keeps track of the selected HUI zone.
struct MyMIDI_Callbacks : FineGrainedMIDI_Callbacks<MyMIDI_Callbacks> {
static constexpr uint8_t zone_select_command = 0x0C; // Taken from HUI.pdf (https://forum.cockos.com/showthread.php?t=101328)
static constexpr uint8_t switch_port_command = 0x2C;
static constexpr uint8_t record_zone = 0x0e;
static constexpr uint8_t record_port = 5;
uint8_t zone = 0xFF;
// Function that is called whenever a MIDI Control Change message is received.
void onControlChange(Channel channel, uint8_t controller, uint8_t value, Cable) {
if (channel != Channel_1)
return;
if (controller == zone_select_command) {
zone = value;
} else if (controller == switch_port_command) {
uint8_t port = value & 0x0F;
bool led_state = value & 0x40;
if (zone == record_zone && port == record_port)
digitalWrite(record_led_pin, led_state ? HIGH : LOW);
digitalWrite(stop_led_pin, led_state ? HIGH : LOW);
}
}
} callback;
void setup() {
pinMode(record_led_pin, OUTPUT);
pinMode(stop_led_pin, OUTPUT);
digitalWrite(stop_led_pin, HIGH);
midi.begin(); // Initialize the MIDI interface
midi.setCallbacks(callback); // Attach the custom callback
}
void loop() {
midi.update(); // Continuously handle MIDI input
}
I took the above script and added it sending commands, and it is connecting and triggering.
#include <Control_Surface.h>
const auto record_led_pin = 9;
const auto stop_led_pin = 10;
int looper = 0;
// The MIDI over USB interface to use
USBMIDI_Interface midi;
constexpr uint8_t MCU_RECORD_NOTE = 0x5F;
const int MCU_STOP_NOTE = MCU::STOP;
// Custom MIDI callback that keeps track of the selected HUI zone.
struct MyMIDI_Callbacks : FineGrainedMIDI_Callbacks<MyMIDI_Callbacks> {
static constexpr uint8_t zone_select_command = 0x0C; // Taken from HUI.pdf (https://forum.cockos.com/showthread.php?t=101328)
static constexpr uint8_t switch_port_command = 0x2C;
static constexpr uint8_t record_zone = 0x0e;
static constexpr uint8_t record_port = 5;
uint8_t zone = 0xFF;
// Function that is called whenever a MIDI Control Change message is received.
void onControlChange(Channel channel, uint8_t controller, uint8_t value, Cable) {
if (channel != Channel_1)
return;
if (controller == zone_select_command) {
zone = value;
} else if (controller == switch_port_command) {
uint8_t port = value & 0x0F;
bool led_state = value & 0x40;
if (zone == record_zone && port == record_port)
digitalWrite(record_led_pin, led_state ? HIGH : LOW);
}
}
} callback;
void setup() {
pinMode(record_led_pin, OUTPUT);
pinMode(stop_led_pin, OUTPUT);
digitalWrite(stop_led_pin, HIGH); // Indicate that the system is ready
midi.begin(); // Initialize the MIDI interface
midi.setCallbacks(callback); // Attach the custom callback
}
void loop() {
midi.update(); // Continuously handle MIDI input
if (looper < 5){
midi.update(); // Continuously handle MIDI input
midi.sendNoteOn(MCU_RECORD_NOTE, 127); // SEND RECORD ON
delay(500);
midi.sendNoteOff(MCU_RECORD_NOTE, 0); // RELEASE RECORD
delay(8000);
midi.update(); // Continuously handle MIDI input
midi.sendNoteOn(MCU_STOP_NOTE, 127); // SEND RECORD ON
delay(1500);
midi.sendNoteOff(MCU_STOP_NOTE, 0); // RELEASE RECORD
delay(1000);
looper = looper + 1;
}
}
Any suggestions on what I am doing wrong?
