2 different controllers in the same script. Help!

Post Reply New Topic
RELATED
PRODUCTS

Post

Hi folks,
I'm trying to write a script but I'm stuck.
I would like to detect 2 different controllers on the same script: a midi flute (USB plug) and a midi foot controller (plugged in Midi IN on my Focusrite), in order to have all the automation lanes on the same track and also, to avoid mapping every time.

I've taken the "Generic MIDI Keyboard.control.js" as base, I've modified the name and UUID and the number of midi port like that: host.defineMidiPorts(2,0)

Code: Select all

loadAPI(2);

host.setShouldFailOnDeprecatedUse(true);

host.defineController("Generic", "TEST Midi flute + Foot controller", "1.0", "6969FAD0-174B-11E9-B56E-0800200C9A66");
host.defineMidiPorts(2,0);
host.addDeviceNameBasedDiscoveryPair(["MIDI Wind controller","Focusrite USB MIDI"],[]);

Until here, it works fine, in the settings, it asks 2 controllers IN ans no controller OUT, it's what I want:
Image

My problem is that the script doesn't take the input of both controllers. Only the second one.
In this case, only the foot controller plugged on the Focusrite will answer but not the Midi flute.


Do you have any idea to help me?

Thanks a lot, have a nice evening

Post

Mathiross wrote: Sat Oct 05, 2019 5:34 pm I've taken the "Generic MIDI Keyboard.control.js" as base, I've modified the name and UUID and the number of midi port like that: host.defineMidiPorts(2,0)
You also need to configure the 2nd input. Look for: host.getMidiInPort(0). Add a host.getMidiInPort(1) and register callbacks, create note inputs etc.

Post

Hi progressive rock comrade ! Still you ! Thanks again for the advises !
I've added

Code: Select all

  midiIn = host.getMidiInPort(1);
  midiIn.setMidiCallback(onMidi);
  allChannels = midiIn.createNoteInput("All Channels", "??????");
  allChannels.setShouldConsumeEvents(false);
but it's still the same. I'm searching on the Control Surface API but I can't find anything.

I've discovered some precisions: it's not a matter of first or second, it just that my 2 controllers appears separately in the INPUTS propositions with the same names, but each input filter the other one then, only one controller work at the time.

Image

So, I've compared my code with many controller scripts which has several midi IN and now, it's grouped as one controller but still one controller work at the time.

Here is my actual code:

Code: Select all

loadAPI(2);

host.defineController("Aodyo", "TEST Sylphyo + Pedal", "1.3.3", "6969FAD0-174B-11E9-B56E-0800200C9A66");
host.defineMidiPorts(2,0);
host.addDeviceNameBasedDiscoveryPair(["Sylphyo","Focusrite USB MIDI"],[]);
host.addDeviceNameBasedDiscoveryPair(["Sylphyo Link","Focusrite USB MIDI"],[]);

var LOWEST_CC = 1;
var HIGHEST_CC = 119;


function init() {
note = host.getMidiInPort(0).createNoteInput("All Channels", "??????");
    note.setShouldConsumeEvents(false);

    host.getMidiInPort(0).setMidiCallback(onMidi0);
	
	userControls = host.createUserControls(HIGHEST_CC - LOWEST_CC + 1);
		
}

function init() {
note = host.getMidiInPort(1).createNoteInput("All Channels", "??????");
    note.setShouldConsumeEvents(false);

    host.getMidiInPort(1).setMidiCallback(onMidi1);
	
	userControls = host.createUserControls(HIGHEST_CC - LOWEST_CC + 1);
		
}

function onMidi0(status, data1, data2){
         var index = data1 - LOWEST_CC;
         userControls.getControl(index).set(data2, 128);
      }

function onMidi1(status, data1, data2){
         var index = data1 - LOWEST_CC;
         userControls.getControl(index).set(data2, 128);
      }

function exit()
{
}

If you have a moment...

Post

Mathiross wrote: Sun Oct 06, 2019 5:00 pm

If you have a moment...
You cannot have 2 init() functions...

Post

Hi !
No way to find... I tried hard, tested many configurations... still doesn't work or only 1 controller send midi message in my track. Never both.

My latest code where I tried every combinaisons between host.getMidiInPort(0 OR 1)
AND (onMidi0 OR 1)

Code: Select all

function init() {
note = host.getMidiInPort(0).createNoteInput("double MIDI input", "??????");
	host.getMidiInPort(0).setMidiCallback(onMidi0);
	host.getMidiInPort(1).setMidiCallback(onMidi1);
	
	userControls = host.createUserControls(HIGHEST_CC - LOWEST_CC + 1);
	}


function onMidi0(status, data1, data2){
         var index = data1 - LOWEST_CC;
         userControls.getControl(index).set(data2, 128);
      }

function onMidi1(status, data1, data2){
         var index = data1 - LOWEST_CC;
         userControls.getControl(index).set(data2, 128);
      }

What's missing? some hexadecimal stuff in there?
I found some clues here but it didn't help me...

NoteInput createNoteInput ( String name, String... masks )

Creates a note input that appears in the track input choosers in Bitwig Studio. This method must be called within the init() function of the script. The messages matching the given mask parameter will be fed directly to the application, and are not processed by the script.

Parameters
name the name of the note input as it appears in the track input choosers in Bitwig Studio
masks a filter string formatted as hexadecimal value with ? as wildcard. For example 80???? would match note-off on channel 1 (0). When this parameter is {}, a standard filter will be used to forward note-related messages on channel 1 (0).
If multiple note input match the same MIDI event then they'll all receive the MIDI event, and if one of them does not consume events then the events wont' be consumed.

Returns
the object representing the requested note input



Have a nice day !

Post

You also need to create a note input for the 2nd port. Bitwig does not support to merge several ports into one, if that is what you are after. You will have 2 inputs showing up in Bitwig. It might be possible to monitor the midi data of the 2nd port and forward it to the 1st with sendRawMidi function but I never tried that.

Post

Ok, it's effectively what I'm trying to do. I'll try a SendRawMidi and if, by a miracle I manage, Ill post here my code.
Thanks again, and If someone has ever tried a 2 controllers merging in one track, let me know...

Post

Hello Mathiross, it's exactly what I try to do since one day. Did you succeed ?

@moss, it's not possible to merge 2 inputs into one with API v9, really?

Also Mathiross, you can use CooperLan (http://copperlan.org/) to create a virtual midi who merge your midi input, but in my case I have a little latence that I don't want, because I use 2 PC and I make a "loop" to reinject several signal, but for you, directly,it will be OK

Post

Not sure if this is of any use, but I came across it on Github. Haven't tried it myself :

https://github.com/accSone/Bitwig-midi-merger

Post

I am new to Bitwig scripting, but as I was reading through this thread I thought "Hang on, this should be really easy to do from what I've learned so far". So I decided to make a simple test script and blow me down it worked!

Code: Select all

loadAPI(10);
// Define our controller and give it 2 MIDI in ports
host.defineController("Hunting Mirages", "Combined Controller", "0.1", "fcfe64a0-9cb7-11ea-ab12-0800200c9a66", "Sam");
host.defineMidiPorts(2, 0);

function init() {
    // Create a noteInput for the first port that passes all MIDI data received straight through to the track
    noteInput0 = host.getMidiInPort(0).createNoteInput("Hunting Mirages", "??????");

    // Create a MIDI event callback for the second port that forwards all MIDI data received into first port's noteInput
    // Thus combining the two MIDI streams into one
    host.getMidiInPort(1).setMidiCallback((status, data1, data2) => {
        noteInput0.sendRawMidiEvent(status, data1, data2);
    });

    println("Combined Controller initialized!");
}
(Updated to remove unnecessary code)
(Updated again to add comments)

Enjoy

Post Reply

Return to “Controller Scripting”