Midi interface + Control Surface?

Hey, I've been having a blast with the teensy 4.1's
I'm working on my 4th addition, but am running into a problem.

I had been using the control surface library (https://github.com/tttapa/Control-Surface)
(The encoders and the software button debouncing was a lot more complex than any of my rookie programming attempts.)

The problem--> declaring
#include <Control_Surface.h>
USBMIDI_Interface midi;

brings up the message
"Compilation error: 'cs::USBMIDI_Interface midi' redeclared as different kind of entity"
when I select midi 4x4 from the board menu.

I only need the midi in jacks, none of the outs, but here is the code


#include <Control_Surface.h>
#include <MIDI.h>
USBMIDI_Interface midi;

// Create the Serial MIDI ports
MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI1);
MIDI_CREATE_INSTANCE(HardwareSerial, Serial2, MIDI2);
MIDI_CREATE_INSTANCE(HardwareSerial, Serial3, MIDI3);
// A variable to know how long the LED has been turned on
elapsedMillis ledOnMillis;
CCButton buttons [] {
{0, {6, Channel_1}},//
{1, {7, Channel_1}},//
{2, {8, Channel_1}},//
{3, {10, Channel_1}},//
{4, {12, Channel_1}},//
{5, {13, Channel_1}},//
{6, {16, Channel_1}},//
{7, {32, Channel_1}},//
{8, {33, Channel_1}},//
{9, {34, Channel_1}},//
{10, {35, Channel_1}},//
{11, {36, Channel_1}},//
{12, {37, Channel_1}},//
{24, {38, Channel_1}},//
{25, {39, Channel_1}},//
{26, {40, Channel_1}},//
void setup() {
Serial.begin(115200);
pinMode(13, OUTPUT); // LED pin
digitalWrite(13, LOW);
MIDI1.begin(MIDI_CHANNEL_OMNI);
MIDI2.begin(MIDI_CHANNEL_OMNI);
MIDI3.begin(MIDI_CHANNEL_OMNI);
Control_Surface.begin();
}

void loop() {
bool activity = false;
if (MIDI1.read()) {
// get a MIDI IN1 (Serial) message
byte type = MIDI1.getType();
byte channel = MIDI1.getChannel();
byte data1 = MIDI1.getData1();
byte data2 = MIDI1.getData2();
// forward the message to USB MIDI virtual cable #0
if (type != midi::SystemExclusive) {
// Normal messages, simply give the data to the usbMIDI.send()
usbMIDI.send(type, data1, data2, channel, 0);
} else {
// SysEx messages are special. The message length is given in data1 & data2
unsigned int SysExLength = data1 + data2 * 256;
usbMIDI.sendSysEx(SysExLength, MIDI1.getSysExArray(), true, 0);
}
activity = true;
}
if (MIDI2.read()) {
// get a MIDI IN2 (Serial) message
byte type = MIDI2.getType();
byte channel = MIDI2.getChannel();
byte data1 = MIDI2.getData1();
byte data2 = MIDI2.getData2();
// forward the message to USB MIDI virtual cable #1
if (type != midi::SystemExclusive) {
// Normal messages, simply give the data to the usbMIDI.send()
usbMIDI.send(type, data1, data2, channel, 1);
} else {
// SysEx messages are special. The message length is given in data1 & data2
unsigned int SysExLength = data1 + data2 * 256;
usbMIDI.sendSysEx(SysExLength, MIDI1.getSysExArray(), true, 1);
}
activity = true;
}
if (MIDI3.read()) {
// get a MIDI IN1 (Serial) message
byte type = MIDI3.getType();
byte channel = MIDI3.getChannel();
byte data1 = MIDI3.getData1();
byte data2 = MIDI3.getData2();
// forward the message to USB MIDI virtual cable #0
if (type != midi::SystemExclusive) {
// Normal messages, simply give the data to the usbMIDI.send()
usbMIDI.send(type, data1, data2, channel, 2);
} else {
// SysEx messages are special. The message length is given in data1 & data2
unsigned int SysExLength = data1 + data2 * 256;
usbMIDI.sendSysEx(SysExLength, MIDI1.getSysExArray(), true, 2);
}
activity = true;
}
if (usbMIDI.read()) {
// get the USB MIDI message, defined by these 5 numbers (except SysEX)
byte type = usbMIDI.getType();
byte channel = usbMIDI.getChannel();
byte data1 = usbMIDI.getData1();
byte data2 = usbMIDI.getData2();
byte cable = usbMIDI.getCable();
// forward this message to 1 of the 3 Serial MIDI OUT ports
if (type != usbMIDI.SystemExclusive) {
// Normal messages, first we must convert usbMIDI's type (an ordinary
// byte) to the MIDI library's special MidiType.
midi::MidiType mtype = (midi::MidiType)type;
// Then simply give the data to the MIDI library send()
switch (cable) {
case 0:
MIDI1.send(mtype, data1, data2, channel);
break;
case 1:
MIDI2.send(mtype, data1, data2, channel);
break;
case 2:
MIDI3.send(mtype, data1, data2, channel);
break;
}
} else {
// SysEx messages are special. The message length is given in data1 & data2
unsigned int SysExLength = data1 + data2 * 256;
switch (cable) {
case 0:
MIDI1.sendSysEx(SysExLength, usbMIDI.getSysExArray(), true);
break;
case 1:
MIDI2.sendSysEx(SysExLength, usbMIDI.getSysExArray(), true);
break;
case 2:
MIDI3.sendSysEx(SysExLength, usbMIDI.getSysExArray(), true);
break;
}
}
activity = true;
}
// blink the LED when any activity has happened
if (activity) {
digitalWriteFast(13, HIGH); // LED on
ledOnMillis = 0;
}
if (ledOnMillis > 15) {
digitalWriteFast(13, LOW); // LED off
}
Control_Surface.loop();
}

and attached is the error message screenshot.
Screen Shot 2024-06-12 at 4.01.52 PM.png


I'd love some advice,
(I'm foremost an electrician by trade, so programming is a bit out of my expertise)
Thanks!
Remi
 
Probably 'midi' is used already in the Teensy MIDI library, so instantiating like this USBMIDI_Interface midi_usb; gets rid of the compilation error.

Also got rid of the CCButton 'brace-enclosed initializer list' error by changing Channel_1 to CHANNEL_1 and adding a }; at the end of the list, see below:

C++:
#include <Control_Surface.h>
#include <MIDI.h>
USBMIDI_Interface midi_usb;

// Create the Serial MIDI ports
MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI1);
MIDI_CREATE_INSTANCE(HardwareSerial, Serial2, MIDI2);
MIDI_CREATE_INSTANCE(HardwareSerial, Serial3, MIDI3);
// A variable to know how long the LED has been turned on
elapsedMillis ledOnMillis;

CCButton buttons[]{
  { 0, { 6, CHANNEL_1 } },    //
  { 1, { 7, CHANNEL_1 } },    //
  { 2, { 8, CHANNEL_1 } },    //
  { 3, { 10, CHANNEL_1 } },   //
  { 4, { 12, CHANNEL_1 } },   //
  { 5, { 13, CHANNEL_1 } },   //
  { 6, { 16, CHANNEL_1 } },   //
  { 7, { 32, CHANNEL_1 } },   //
  { 8, { 33, CHANNEL_1 } },   //
  { 9, { 34, CHANNEL_1 } },   //
  { 10, { 35, CHANNEL_1 } },  //
  { 11, { 36, CHANNEL_1 } },  //
  { 12, { 37, CHANNEL_1 } },  //
  { 24, { 38, CHANNEL_1 } },  //
  { 25, { 39, CHANNEL_1 } },  //
  { 26, { 40, CHANNEL_1 } },  //
};

Hope this helps,
Paul
 
Probably 'midi' is used already in the Teensy MIDI library, so instantiating like this USBMIDI_Interface midi_usb; gets rid of the compilation error.

Also got rid of the CCButton 'brace-enclosed initializer list' error by changing Channel_1 to CHANNEL_1 and adding a }; at the end of the list, see below:

C++:
#include <Control_Surface.h>
#include <MIDI.h>
USBMIDI_Interface midi_usb;

// Create the Serial MIDI ports
MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI1);
MIDI_CREATE_INSTANCE(HardwareSerial, Serial2, MIDI2);
MIDI_CREATE_INSTANCE(HardwareSerial, Serial3, MIDI3);
// A variable to know how long the LED has been turned on
elapsedMillis ledOnMillis;

CCButton buttons[]{
  { 0, { 6, CHANNEL_1 } },    //
  { 1, { 7, CHANNEL_1 } },    //
  { 2, { 8, CHANNEL_1 } },    //
  { 3, { 10, CHANNEL_1 } },   //
  { 4, { 12, CHANNEL_1 } },   //
  { 5, { 13, CHANNEL_1 } },   //
  { 6, { 16, CHANNEL_1 } },   //
  { 7, { 32, CHANNEL_1 } },   //
  { 8, { 33, CHANNEL_1 } },   //
  { 9, { 34, CHANNEL_1 } },   //
  { 10, { 35, CHANNEL_1 } },  //
  { 11, { 36, CHANNEL_1 } },  //
  { 12, { 37, CHANNEL_1 } },  //
  { 24, { 38, CHANNEL_1 } },  //
  { 25, { 39, CHANNEL_1 } },  //
  { 26, { 40, CHANNEL_1 } },  //
};

Hope this helps,
Paul
Thank you so much!!!!
 
Back
Top