Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 6 of 6

Thread: Virtual MIDIx4

Hybrid View

  1. #1
    Member
    Join Date
    Jan 2018
    Location
    Brazil
    Posts
    36

    Virtual MIDIx4

    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

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    26,823
    Use usbMIDI.sendPitchBend(value, channel, cable); where "cable" is 0 to 3.

  3. #3
    Member
    Join Date
    Jan 2018
    Location
    Brazil
    Posts
    36
    So simple!!!
    thanks

  4. #4
    Junior Member
    Join Date
    Jan 2018
    Posts
    2
    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--;
      }
    }

  5. #5
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    26,823
    Quote Originally Posted by KnutB. View Post
    Where do I have to insert the cable number?
    Use usbMIDI.getCable() to read which cable received the message.

    Details here:

    https://www.pjrc.com/teensy/td_midi.html

  6. #6
    Junior Member
    Join Date
    Jan 2018
    Posts
    2
    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--;
      }
    }

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •