Virtual MIDIx4

Status
Not open for further replies.

Lenogi

Active member
Hello,
Sorry for my poor english.
I can't understand how to transmit messages via usbMIDI using virtual cables/ports.
I'm not using Serial Transmission.
I would like an example to understand the operation.

Teensy 3.6 >> DAW
(Port 1) - usbMIDI.sendPitchBend(value, channel);
(Port 2) - usbMIDI.sendPitchBend(value, channel);
(Port 3) - usbMIDI.sendPitchBend(value, channel);

I hope someone can help me

Thank you :)
 
simple and brilliant, thank you so much. Is the same possible for reading the different cables? Where do I have to insert the cable number? I want to read from two different MIDI Mashines (cable1 = X32 (Monitor Mute); cable2 = X-Touch (Recording Light)

Code:
int bzaehler = 0;
int x32 = 0; //MIDI Interface (0= Anschluss 1)
void setup() {
  pinMode(11, OUTPUT); //Recording light
  pinMode(12, OUTPUT); //Mute Light
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  digitalWrite(2, !LOW); // relay module with optocoupler, inverted signal
  digitalWrite(3, !LOW); // relay module with optocoupler, inverted signal
  digitalWrite(4, !LOW); // relay module with optocoupler, inverted signal
  digitalWrite(5, !LOW); // relay module with optocoupler, inverted signal
  usbMIDI.setHandleNoteOn(onNoteOn) ;
  usbMIDI.setHandleControlChange(onControlChange);
}

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

//Recording light
void onNoteOn(byte kanal, byte note, byte velocity) {
  if ((kanal == 1) & (note == 95) & (velocity == 127)) {
    digitalWrite(11,HIGH);
  }
  if ((kanal == 1) & (note == 93) & (velocity == 127)) {
    digitalWrite(11,LOW);
  }
}
// Monitor Mute On through Mute Buttons

void onControlChange(byte kanal, byte control, byte value) {
  if ((bzaehler == 0) & (kanal == 2) & ((control == 0) || (control == 1) || (control == 2) || (control == 3) || (control == 4) || (control == 5)) & (value == 0)){
    digitalWrite(12,HIGH);
    digitalWrite(2,HIGH);
    usbMIDI.sendProgramChange(0, 2, x32);
  }
  if ((kanal == 2) & ((control == 0) || (control == 1) || (control == 2) || (control == 3) || (control == 4) || (control == 5)) & (value == 0)){
    bzaehler++;
  }



// Monitor Mute Off through Mute Buttons
  if ((bzaehler == 1) & (kanal == 2) & ((control == 0) || (control == 1) || (control == 2) || (control == 3) || (control == 4) || (control == 5)) & (value == 127)){
    digitalWrite(12,LOW);
    digitalWrite(2,LOW);
    usbMIDI.sendProgramChange(1, 2, x32);
  }
  if ((kanal == 2) & ((control == 0) || (control == 1) || (control == 2) || (control == 3) || (control == 4) || (control == 5)) & (value == 127)){
    bzaehler--;
  }
}
 
Hi, thank you for the hint. I read the td_midi already but could not figure out how to use the get.cable command. With the study of some other code I think I made it. In this version the teensy listens to specific ports and triggers action only when the right commands are comming from the right ports. Great! For anyone, who is interested in the project (Behringer X32core with X-touch, working as a broadcast console, so there is the need for monitor mute (Monitor mutes if mute status of ch1-6 is changed via snippet), redlight if Mic is open (via relays) and Rec light from Reaper).
Code:
int bzaehler = 0;
int x32 = 0; //MIDI Port für X32 (0= Anschluss 1)
int Xtouch = 1; //MIDI Port für XTouch (10 Anschluss 2)
void setup() {
  pinMode(11, OUTPUT); //Recording light
  pinMode(12, OUTPUT); //Mute Light
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  digitalWrite(2, !LOW); // relay module with optocoupler, inverted signal
  digitalWrite(3, !LOW); // relay module with optocoupler, inverted signal
  digitalWrite(4, !LOW); // relay module with optocoupler, inverted signal
  digitalWrite(5, !LOW); // relay module with optocoupler, inverted signal
  usbMIDI.setHandleNoteOn(onNoteOn) ;
  usbMIDI.setHandleControlChange(onControlChange);
}

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

//Recording light
void onNoteOn(byte kanal, byte note, byte velocity) {
  int midiport2;
  midiport2 = usbMIDI.getCable();
  if ((midiport2 == Xtouch) & (kanal == 1) & (note == 95) & (velocity == 127)) {
    digitalWrite(11,HIGH);
  }
  if ((midiport2 == Xtouch) & (kanal == 1) & (note == 93) & (velocity == 127)) {
    digitalWrite(11,LOW);
  }
}
// Monitor Mute On through Mute Buttons

void onControlChange(byte kanal, byte control, byte value) {
  int midiport1;
  midiport1 = usbMIDI.getCable();
  if ((midiport1 == x32) & (bzaehler == 0) & (kanal == 2) & ((control == 0) || (control == 1) || (control == 2) || (control == 3) || (control == 4) || (control == 5)) & (value == 0)){
    digitalWrite(12,HIGH);
    digitalWrite(2,HIGH);
    usbMIDI.sendProgramChange(0, 2, x32);
  }
  if ((midiport1 == x32) & (kanal == 2) & ((control == 0) || (control == 1) || (control == 2) || (control == 3) || (control == 4) || (control == 5)) & (value == 0)){
    bzaehler++;
  }



// Monitor Mute Off through Mute Buttons
  if ((midiport1 == x32) & (bzaehler == 1) & (kanal == 2) & ((control == 0) || (control == 1) || (control == 2) || (control == 3) || (control == 4) || (control == 5)) & (value == 127)){
    digitalWrite(12,LOW);
    digitalWrite(2,LOW);
    usbMIDI.sendProgramChange(1, 2, x32);
  }
  if ((midiport1 == x32) & (kanal == 2) & ((control == 0) || (control == 1) || (control == 2) || (control == 3) || (control == 4) || (control == 5)) & (value == 127)){
    bzaehler--;
  }
}
 
Status
Not open for further replies.
Back
Top