User Tools

This is an old revision of the document!


Chataigne

GrandMa2 fader automation

midi module script

function init() {}

var params_container = script.addContainer("Parameters");
var log_data = params_container.addBoolParameter("LogData", "Choose if you want to see a translation of the sysex", false);
var faders_container = script.addContainer("Faders");

function sysExEvent(data) {
	parseSysex(data);
}

function logData(data) {
	script.log("-------- sysex message start ---------");
	script.log("universal_sysex > "+ data[0]);
	script.log("device_id > "+ data[1]);
	script.log("msc > "+ data[2]);
	script.log("command_format > "+ data[3]);
	script.log("command > "+ data[4]);
	script.log("fader > "+ data[5]);
	script.log("fader_page > "+ data[6]);
	script.log("fine_value > "+ data[7]);
	script.log("coarse_value > "+ data[8]);
	script.log("-------- sysex message end ---------");
}

function hexToFader(coarse, fine) {
  return Math.floor(((fine / 128) + coarse) / 1.28);
}

function parseSysex(data) {
	if (data[4] == 6) {
		if (log_data.get())logData(data);
		
		var fader_level = hexToFader(data[8], data[7]);

		var parameter_name = "FaderValue"+data[5];
		faders_container.addFloatParameter(parameter_name,"Value of the fader Exec "+data[5],fader_level,0,100);
		var param = faders_container.getChild(parameter_name);
		param.set(fader_level);

		/*if (typeof param === "void") {
			script.log("Creating the fader parameter.");
			faders_container.addFloatParameter(parameter_name,"Value of the fader Exec "+data[5],fader_level,0,100);
		}
		else {
			param.set(fader_level);
		}*/
	}
}

sequence mapping filter

Create a custom variable group named “Execs” first.

function fixedIt(precision, value, num) {
  var num = "" + (Math.round(value * Math.pow(10, precision)));
  //return num.substring(0, num.length - precision) + "." + num.substring(num.length - precision, num.length);
  return "0."+num.substring(num.length - precision, num.length);
}

function faderToHex(fader_value) {
  var temp_coarse = fader_value * 1.28;
  var coarse = parseInt(Math.floor(temp_coarse));
  var coarse_hex = Integer.toHexString(coarse);
  if (coarse < 16) coarse_hex = "0"+ coarse_hex;

  //var coarse_decimals = (temp_coarse %1).toFixed(2);
  var coarse_decimals = parseFloat(fixedIt(2,temp_coarse %2));
  var temp_fine = coarse_decimals * 128;
  var fine = parseInt(Math.floor(temp_fine));
  var fine_hex = Integer.toHexString(fine);
  if (fine < 16) fine_hex = "0"+ fine_hex;

  return {
    'coarse': ""+coarse,
    'fine': ""+fine
  }
}

function filter(inputValue, min, max) {
  var hex_values = faderToHex(Math.abs(inputValue[0]));

  var parameter_name = script.getParent().getParent().getParent().getParent().getParent().name;

  //root.customVariables.execs.variables.addStringParameter(parameter_name+ "_coarse","Hex coarse value of mapping "+parameter_name,hex_values.coarse);
  root.customVariables.execs.variables.addStringParameter(parameter_name+ "_coarse","Hex coarse value of mapping "+parameter_name,hex_values.coarse);
  var param = root.customVariables.execs.variables.getChild(parameter_name+ "_coarse");
  param.set(hex_values.coarse);

  root.customVariables.execs.variables.addStringParameter(parameter_name+ "_fine","Hex fine value of mapping "+parameter_name,hex_values.coarse);
  var param = root.customVariables.execs.variables.getChild(parameter_name+ "_fine");
  param.set(hex_values.fine);

  return inputValue;
}

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also, you acknowledge that you have read and understand our Privacy Policy. If you do not agree, please leave the website.

More information