How to change a parameter (macro) on the second device of a track

Post Reply New Topic
RELATED
PRODUCTS

Post

Hi.

Here is a part of my code with the init function :

Code: Select all

loadAPI(19);

// Remove this if you want to be able to use deprecated methods without causing script to stop.
// This is useful during development.
host.setShouldFailOnDeprecatedUse(true);

host.defineController("Fracasse", "BCR2000 - 2", "0.1", "da16ecf7-8891-4112-9a8b-6a70d14cafa7", "Arnold");

host.defineMidiPorts(1, 1);

// Constantes
const incValue = 1;
const decValue = 127;

const firstMixerTrack = 0;

// Variables
let trackBank;
let deviceRemoteControls = [];
let cursorDevice;
let remoteControls;


let actualTrack = 0;
let chooseDevice = 0;

function init() {
   transport = host.createTransport();
   host.getMidiInPort(0).setMidiCallback(onMidi0);
   host.getMidiInPort(0).setSysexCallback(onSysex0);

   // TODO: Perform further initialization here.
   println("BCR2000 - 2 initialized!");
   
   
   trackBank = host.createTrackBank(8, 0, 0, false); 		// Bank de track
   
   trackBank.channelScrollPosition().markInterested();		// Intérêt pour scrollPosition
   trackBank.channelScrollPosition().set(firstMixerTrack);	// Positionnement à la première piste du mixer
   
   for ( let i = 0; i < 8 ; i++ ) {
		track = trackBank.getItemAt(i); // Utilisation de la première piste
		
		// markInterested
		track.name().markInterested();
		track.volume().value().markInterested();
		track.volume().value().displayedValue().markInterested();
		track.mute().markInterested();
		track.solo().markInterested();
		
		// Device EQ
		cursorDevice = track.createCursorDevice();
		cursorDevice.selectFirst();
		remoteControls = cursorDevice.createCursorRemoteControlsPage(8);
	
		for ( let s = 0; s < 8 ; s++ ) {
			remoteControls.getParameter(s).name().markInterested();
			remoteControls.getParameter(s).value().markInterested();
			remoteControls.getParameter(s).value().displayedValue().markInterested();
		}
		
		deviceRemoteControls.push(remoteControls);
  }
	
}

// Called when a short MIDI message is received on MIDI input port 0.
function onMidi0(status, data1, data2) {
   // TODO: Implement your MIDI input handling code here.
   println("Status : "+status.toString(16)+" Note : "+data1+" valeur : "+data2);
   
   if ( isCC(status) && (data1 < 24) ) {			// Si Macro pot
		
		
		if ( data2 == incValue ) {				// Si valeur d'incrémentation
		
			if ( chooseDevice == 0 ) {				// Si focus sur EQ
				deviceRemoteControls[returnColonne(data1)].getParameter(returnLigne(data1)).value().inc(1, 128);
			}
		
			if ( (chooseDevice == 1) && (returnLigne(data1) == 2) ) {	// Si focus sur Saturateur
				deviceRemoteControls[returnColonne(data1)].getParameter(7).value().inc(1, 128);
			}
		}
	
		if ( data2 == decValue ) {
		
			if ( chooseDevice == 0 ) {
				deviceRemoteControls[returnColonne(data1)].getParameter(returnLigne(data1)).value().inc(-1, 128);
			}
		
			if ( (chooseDevice == 1) && (returnLigne(data1) == 2) ) {
				deviceRemoteControls[returnColonne(data1)].getParameter(7).value().inc(-1, 128);
			}
		}
   } 
   
   
   if ( isButton(status) ) {
		
		// *********** Changement banque de piste
		if ( (data1 == 100) && (data2 == 127) ) { 
			trackBank.channelScrollPosition().set(firstMixerTrack);
		}
		
		if ( (data1 == 100) && (data2 == 127) ) { 
			trackBank.channelScrollPosition().set(firstMixerTrack+8);
		}
		
		// ************ Changement de Device
		if ( (data1 == 102) && (data2 == 127) ) {
	   
			if ( chooseDevice == 0 ) {
				deviceBank.getDevice(1).selectInEditor();
				chooseDevice = 1;
				println("Saturator : "+deviceRemoteControls[2].getParameter(7).name().get());
			} else {
				deviceBank.getDevice(0).selectInEditor();
				chooseDevice = 0;
				println("EQ");
			}
		}
		
   }
   
   
}

// Called when a MIDI sysex message is received on MIDI input port 0.
function onSysex0(data) {
   // MMC Transport Controls:
   switch (data) {
      case "f07f7f0605f7":
         transport.rewind();
         break;
      case "f07f7f0604f7":
         transport.fastForward();
         break;
      case "f07f7f0601f7":
         transport.stop();
         break;
      case "f07f7f0602f7":
         transport.play();
         break;
      case "f07f7f0606f7":
         transport.record();
         break;
   }
}

function flush() {
   // TODO: Flush any output to your controller here.
}

function exit() {

}
/*
function nextDeviceChoosen() {
	   if ( cursorDevice.hasNext() ) {
		cursorDevice.selectNext();
		println("Next Device");
	   }
}


function previousDeviceChoosen() {
	if ( cursorDevice.hasPrevious() ) {
		cursorDevice.selectPrevious();
		println("Previous Device");
	   }
}
*/
function isButton(status) {
	
	if ( status == 0x90 ) {
		return true;
	} else {
		return false;
	}
}

function isCC(status) {
	
	if ( status == 0xB0 ) {
		return true;
	} else {
		return false;
	}
}


function returnLigne(CC) {
	
	for ( let i=24; i<32; i++) {
		if ( CC == i ) {
			return 3;
		}
	}
	
	for ( let i=16; i<23; i++) {
		if ( CC == i ) {
			return 2;
		}
	}
	
	for ( let i=8; i<15; i++) {
		if ( CC == i ) {
			return 1;
		}
	}

	for ( let i=0; i<7; i++) {
		if ( CC == i ) {
			return 0;
		}
	}
	
}

function returnColonne(CC) {
		println("Ligne : "+CC % 8);	// Debug
		return (CC % 8);
}

With my BCR2000, I want to control the Low, Mid and High of the native EQ DJ device, and when touching a button, controling the gain of the saturator.

I achieve to control the Low, Mid and High of the native EQ DJ device, but, when I change the cursorTrack to select the Saturator (second device), Bitwig change the Low freq (7th parameter of EQ DJ).

If I read correctly "cursorDevice.selectNext();" should change the focused device. But nothing append, without error. Here my code is the version with "getDevice()" to force the change of the device, but also the device didn't change.

I am missing something ?

Post Reply

Return to “Controller Scripting”