ModScripter Scripts

Hi, this thread should be a collection of scripts for the ModScripter.

Please only post scripts in here. If you have a question for a script, please open a new thread instead.

To use a script, simply copy it and paste it into the script editor of ModScripter.

4 Likes
getDescription = function () {
	return "MIDI Note Pitch To Modulation";
}

lastPitchNormalzied = 0.0;

lastPitch = 0;
minPitch = 0;
maxPitch = 127;

const noteNames = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"];

pitchToNoteName = function (p) {
	index = p % 12;
	octave = (p - index) / 12;
	return noteNames[index] + (octave - 2);
}

update = function () {
	min = 0.0;
	max = 0.0;
	if (minPitch <= maxPitch)
	{
		min = minPitch;
		max = maxPitch;
	}
	else
	{
		max = minPitch;
		min = maxPitch;
	}
	pitch = Math.max (min, lastPitch);
	pitch = Math.min (max, lastPitch);
	pitch -= min;
	lastPitchNormalzied = pitch / (max - min);
}

processModulation = function (inputValue, numSamples) {
	return lastPitchNormalzied;
}

onNoteOnEvent = function (channel, pitch, velocity, tuning, noteID) {
	lastPitch = pitch;
	update ();
}

onParamChange = function (paramIndex, newValue) {
	if (paramIndex == 1)
	{
		minPitch = newValue * 127;
		update ();
	}
	else if (paramIndex == 2)
	{
		maxPitch = newValue * 127;
		update ();
	}
}

paramValueToString = function (paramIndex, paramValue) {
	if (paramIndex == 1 || paramIndex == 2)
		return pitchToNoteName (Math.round (paramValue * 127));
}

stringToParamValue = function (paramIndex, string) {
	if (paramIndex == 1 || paramIndex == 2)
	{
		name = string.charAt (0);
		octStr = string.substring (1);
		oct = parseInt (octStr);
		if (oct != NaN)
		{
			index = noteNames.indexOf (name);
			if (index >= 0)
			{
				plainValue = ((oct+2) * 12 + index);
				normValue = plainValue / 127;
				return normValue;
			}
		}
	}
}

getParamTitle = function (paramIndex) {
	if (paramIndex == 1)
		return "Min Pitch";
	if (paramIndex == 2)
		return "Max Pitch";
}

getParamStepCount = function (paramIndex) {
	if (paramIndex == 1 || paramIndex == 2)
		return 126;
	return 0;
}
3 Likes

A post was split to a new topic: ModScripter API Documentation?

getDescription = function () {
	return "Sidechain Passthru";
}

sidechainSignal = 0.0;
gain = 1.;

processModulation = function (inputValue) {
	return ((sidechainSignal * gain) + 1.) * 0.5;
}

lastMin = 0.;
lastMax = 0.;

processSidechain = function (minSample, maxSample, absMinSample, absMaxSample) {
	if (lastMin < 0)
	{
		if (lastMax > maxSample)
			sidechainSignal = maxSample;
		else
			sidechainSignal = minSample;
	}
	else
	{
		if (lastMin > minSample)
			sidechainSignal = maxSample;
		else
			sidechainSignal = minSample;
	}
	lastMin = minSample;
	lastMax = maxSample;
}
5 Likes

A post was split to a new topic: ModScripter: how to get compression effect based on the input signal?

/* 
- Connect a MIDI Input to ModScripter
- Make a modulator connection to one of the Freq EQ Band parameters of the Frequency Plug-in.
- Set the connection to unipolar
- Set modulation Depth to +100%
- Set the Freq to 20 Hz
- Play notes thru the MIDI Input
*/

getDescription = function () {
	return "Play Frequency";
}

valueTable = [];
valueTable[0] = 0
valueTable[1] = 0
valueTable[2] = 0
valueTable[3] = 0
valueTable[4] = 0
valueTable[5] = 0
valueTable[6] = 0
valueTable[7] = 0
valueTable[8] = 0
valueTable[9] = 0
valueTable[10] = 0
valueTable[11] = 0
valueTable[12] = 0
valueTable[13] = 0
valueTable[14] = 0
valueTable[15] = 0
valueTable[16] = 0.09131784512134203
valueTable[17] = 0.11787874578167427
valueTable[18] = 0.13336154918960308
valueTable[19] = 0.14502527555439984
valueTable[20] = 0.1546850073223106
valueTable[21] = 0.16310003998756253
valueTable[22] = 0.1706661294059833
valueTable[23] = 0.17761773157148414
valueTable[24] = 0.18410607618948427
valueTable[25] = 0.19023484994460108
valueTable[26] = 0.19607850062305665
valueTable[27] = 0.20169245535962732
valueTable[28] = 0.2071192078852985
valueTable[29] = 0.2123921368738845
valueTable[30] = 0.21753800392000436
valueTable[31] = 0.22257864585966636
valueTable[32] = 0.22753215565516133
valueTable[33] = 0.23241372753099124
valueTable[34] = 0.23723627523992544
valueTable[35] = 0.24201089313356763
valueTable[36] = 0.24674720588769375
valueTable[37] = 0.2514536378062557
valueTable[38] = 0.25613762302097853
valueTable[39] = 0.2608057715703798
valueTable[40] = 0.2654640020767024
valueTable[41] = 0.2701176488105649
valueTable[42] = 0.2747715488867676
valueTable[43] = 0.2794301138819111
valueTable[44] = 0.2840973891180056
valueTable[45] = 0.2887771030923215
valueTable[46] = 0.29347270896917327
valueTable[47] = 0.2981874196273406
valueTable[48] = 0.30292423743808233
valueTable[49] = 0.307685979705555
valueTable[50] = 0.3124753005142861
valueTable[51] = 0.3172947095830464
valueTable[52] = 0.3221465886107552
valueTable[53] = 0.3270332055103952
valueTable[54] = 0.33195672685572647
valueTable[55] = 0.33691922880868924
valueTable[56] = 0.3419227067496198
valueTable[57] = 0.3469690837953769
valueTable[58] = 0.35206021836035073
valueTable[59] = 0.35719791089068564
valueTable[60] = 0.362383909881792
valueTable[61] = 0.3676199172724912
valueTable[62] = 0.37290759329525547
valueTable[63] = 0.3782485608504336
valueTable[64] = 0.38364440946267414
valueTable[65] = 0.38909669886962167
valueTable[66] = 0.39460696228610653
valueTable[67] = 0.4001767093812401
valueTable[68] = 0.4058074290009016
valueTable[69] = 0.4115005916638995
valueTable[70] = 0.4172576518565037
valueTable[71] = 0.42308005014696387
valueTable[72] = 0.42896921513898567
valueTable[73] = 0.4349265652808533
valueTable[74] = 0.44095351054491544
valueTable[75] = 0.4470514539904409
valueTable[76] = 0.45322179322136524
valueTable[77] = 0.45946592174915574
valueTable[78] = 0.46578523026989216
valueTable[79] = 0.47218110786367234
valueTable[80] = 0.47865494312358536
valueTable[81] = 0.4852081252207331
valueTable[82] = 0.491842044911111
valueTable[83] = 0.4985580954895674
valueTable[84] = 0.5053576736955377
valueTable[85] = 0.5122421805747878
valueTable[86] = 0.5192130223009895
valueTable[87] = 0.5262716109605885
valueTable[88] = 0.533419365304097
valueTable[89] = 0.5406577114666573
valueTable[90] = 0.5479880836604646
valueTable[91] = 0.5554119248414019
valueTable[92] = 0.5629306873520394
valueTable[93] = 0.5705458335429601
valueTable[94] = 0.5782588363742096
valueTable[95] = 0.5860711799985189
valueTable[96] = 0.5939843603278095
valueTable[97] = 0.6019998855843761
valueTable[98] = 0.6101192768380246
valueTable[99] = 0.6183440685303492
valueTable[100] = 0.6266758089872406
valueTable[101] = 0.6351160609206348
valueTable[102] = 0.6436664019204399
valueTable[103] = 0.6523284249375112
valueTable[104] = 0.6611037387584809
valueTable[105] = 0.6699939684731974
valueTable[106] = 0.6790007559354745
valueTable[107] = 0.6881257602178079
valueTable[108] = 0.6973706580606707
valueTable[109] = 0.7067371443169632
valueTable[110] = 0.7162269323921586
valueTable[111] = 0.7258417546806466
valueTable[112] = 0.7355833629987573
valueTable[113] = 0.7454535290149112
valueTable[114] = 0.7554540446773221
valueTable[115] = 0.7655867226396531
valueTable[116] = 0.7758533966850065
valueTable[117] = 0.7862559221486078
valueTable[118] = 0.7967961763395265
valueTable[119] = 0.8074760589617588
valueTable[120] = 0.8182974925349829
valueTable[121] = 0.829262422815283
valueTable[122] = 0.8403728192161236
valueTable[123] = 0.8516306752298473
valueTable[124] = 0.8630380088499504
valueTable[125] = 0.8745968629943918
valueTable[126] = 0.8863093059301672
valueTable[127] = 0.8981774316993841

lastPitch = 0;

processModulation = function (inputValue, numSamples) {
	return valueTable[lastPitch];
}

onNoteOnEvent = function (channel, pitch, velocity, tuning, noteID) {
	lastPitch = pitch;
}

4 Likes

A classical ADSR triggered via MIDI Input:

//-----------------------------------------------------------
getDescription = function () {
	return "ADSR";
}

//-----------------------------------------------------------
makeParameter = function (name) {
	var value = 0;
	var listeners = [];
	return {
		name: name, 
		units: "",
		stepCount: 0,
		toString: function (val) { return val; },
		fromString: function (str) { return parseFloat (str); },
		addListener: function (obj) { listeners.push (obj); },
		getValue: function () { return value; },
		getPlain: function () { return value; },
		setValue: function (val) {
			value = val;
			for (i = 0; i < listeners.length; ++i)
				listeners[i] (this);
		},
	};
}

//-----------------------------------------------------------
makeBoolParameter = function (name) {
	param = makeParameter (name);
	param.stepCount = 1;
	param.toString = function (value) { return value >= 0.5 ? "On" : "Off"; };
	param.fromString = function (str) { if (str == "On") return 1.; if (str == "Off") return 0.; };
	return param;
};

//-----------------------------------------------------------
makeRangeParameter = function (name, min, max, units, precision) {
	if (precision == undefined)
		precision = 2;
	var precision = Math.pow (10, precision);
	param = makeParameter (name);
	param.units = units;
	param.toString = function (value) {
		value = normalizedToPlain (min, max, value);
		value = Math.round (value * precision) / precision;
		return value + (this.units ? " " + this.units : "");
	};
	param.fromString = function (str) { 
		var v = parseFloat (str);
		if (!isNaN (v))
			return plainToNormalized (min, max, v);
	};
	param.getPlain = function () { return normalizedToPlain (min, max, this.getValue ()); };
	return param;
};

//-----------------------------------------------------------
makeADSR = function () {
	const Phase = { Attack: 1, Decay: 2, Hold: 3, Release: 4 };
	var attack = 0;
	var decay = 0;
	var sustain = 0;
	var release = 0;
	var phase = Phase.Attack;
	var value = 0;
	var time = -1;
	var doHold = 0;
	var doRetrigger = 0;
	obj = {
		setAttack: function (newValue) { attack = newValue;},
		setDecay: function (newValue) { decay = newValue; },
		setSustain: function (newValue) { sustain = newValue; },
		setRelease: function (newValue) { release = newValue; },
		setRetrigger: function (newValue) { doRetrigger = newValue > 0.5; },
		trigger: function () {
			if (doRetrigger)
			{
				time = 0;
			}
			else
			{
				time = value * attack;
			}
			phase = Phase.Attack; 
		},
		setHold: function (hold) { doHold = hold; },
		release: function () { 
			doHold = 0;
			if (phase == Phase.Hold)
			{
				phase = Phase.Release;
				time = 0;
			}
		},
		process: function (numSamples) {
			if (time < 0)
				return 0;
 			time += numSamples;
			if (phase == Phase.Attack)
			{
				if (time > attack)
				{
					phase = Phase.Decay;
					value = 1.;
					time -= attack;
				}
				else
				{
					value = time / attack;
				}
			}
			if (phase == Phase.Decay)
			{
				if (time > decay)
				{
					phase = Phase.Hold;
					time -= decay;
					value = sustain;
				}
				else
				{
					value = 1. - (1. - sustain) * time / decay;
				}
			}
			if (phase == Phase.Hold)
			{
				if (doHold == 0)
				{
					phase = Phase.Release;
				}
			}
			if (phase == Phase.Release)
			{
				if (time > release)
				{
					phase = Phase.Attack;
					time = -1;
					value = 0;
				}
				else
				{
					value = sustain * (1 - (time / release));
				}
			}
			return value;
		}
	};
	return obj;
};


const AttackIndex = 1;
const DecayIndex = 2;
const SustainIndex = 3;
const ReleaseIndex = 4;
const VelocityIndex = 5;
const RetriggerIndex = 6;

parameter = [];
parameter[AttackIndex]		= makeRangeParameter ("Attack", 0, 3000, "ms", 0);
parameter[DecayIndex]		= makeRangeParameter ("Decay", 0, 3000, "ms", 0);
parameter[SustainIndex]		= makeRangeParameter ("Sustain", 0, 100, "%", 0);
parameter[ReleaseIndex]		= makeRangeParameter ("Release", 0, 3000, "ms", 0);
parameter[VelocityIndex]	= makeRangeParameter ("Velocity", 0, 100, "%", 0);
parameter[RetriggerIndex]	= makeBoolParameter  ("Retrigger");

adsr = makeADSR ();

sr = getSampleRate () / 1000;

parameter[AttackIndex].addListener (function (param) { adsr.setAttack (param.getPlain () * sr); });
parameter[DecayIndex].addListener (function (param) { adsr.setDecay (param.getPlain () * sr); });
parameter[SustainIndex].addListener (function (param) { adsr.setSustain (param.getValue ()); });
parameter[ReleaseIndex].addListener (function (param) { adsr.setRelease (param.getPlain () * sr); });
parameter[RetriggerIndex].addListener (function (param) { adsr.setRetrigger (param.getPlain ()); });

key = {noteID: -1, velocity: 0};

//-----------------------------------------------------------
processModulation = function (inputValue, numSamples) {
	return adsr.process (numSamples) * key.velocity;
}

pressedNote = -1;
//-----------------------------------------------------------
onNoteOnEvent = function (channel, pitch, velocity, tuning, noteID) {
	if (key.noteID == -1)
	{
		
		key.noteID = noteID;
		velAmount = parameter[VelocityIndex].getValue ();
		key.velocity = 1. + (velocity * velAmount) - 1. * velAmount;
		adsr.trigger ();
		adsr.setHold (1);
	}
}

//-----------------------------------------------------------
onNoteOffEvent = function (channel, pitch, velocity, tuning, noteID) {
	if (key.noteID == noteID)
	{
		key.noteID = -1;
		adsr.release ();
	}
}

//-----------------------------------------------------------
onParamChange = function (paramIndex, newValue) {
	if (parameter[paramIndex])
		parameter[paramIndex].setValue (newValue);
}

//-----------------------------------------------------------
paramValueToString = function (paramIndex, paramValue) {
	if (parameter[paramIndex])
		return parameter[paramIndex].toString (paramValue);
}

//-----------------------------------------------------------
stringToParamValue = function (paramIndex, string) {
	if (parameter[paramIndex])
		return parameter[paramIndex].fromString (string);
}

//-----------------------------------------------------------
getParamTitle = function (paramIndex) {
	if (parameter[paramIndex])
		return parameter[paramIndex].name;
}

//-----------------------------------------------------------
getParamStepCount = function (paramIndex) {
	if (parameter[paramIndex])
		return parameter[paramIndex].stepCount;
}

3 Likes

Making the smallest of modifications to the Clamp preset from Cubase we can turn an incoming modulation signal into a pulswave signal.
The Low and Hi parameters define the respective values of the resulting pulse wave.

getDescription = function () {
    return "Pulser";
}
  
parameter = [];
parameter[1] = 0;
parameter[2] = 0;
  
min = 0;
max = 1;
  
processModulation = function (inputValue, numSamples) {
    if (inputValue < 0.5)
        return min;
    else if (inputValue >= 0.5)
        return max;
    return inputValue;
}
  
checkParameters = function () {
    if (parameter[1] < parameter[2])
    {
        min = parameter[1];
        max = parameter[2];
    }
    else
    {
        min = parameter[2];
        max = parameter[1];
    }
}
  
onParamChange = function (paramIndex, newValue) {
    if (paramIndex == 1)
    {
        parameter[1] = newValue;
        checkParameters ();
    }
    else if (paramIndex == 2)
    {
        parameter[2] = newValue;
        checkParameters ();
    }
}
  
getParamTitle = function (paramIndex) {
    if (paramIndex == 1)
        return "LowValue";
    if (paramIndex == 2)
        return "HiValue";
}

A post was split to a new topic: ModScripter LFO script in progress

Velocity to Modulation
Script by xbitz from the kvraudio.com forum. Modified to reset the modulation value only after the last key is released.

// Script by xbitz from the kvraudio.com forum. Modified to allow multiple keys being pressed.

getDescription = function () {
    return "Velocity to Modulation";
}

// Declare a variable to hold the current modulation value and amount of keys pressed
currentModulationValue = 0;
KeyCounter = 0;

//-----------------------------------------------------------
samesame = function () {
}

//-----------------------------------------------------------
processModulation = function (inputValue, numSamples) {
    return currentModulationValue;
}

//-----------------------------------------------------------
onNoteOnEvent = function (channel, pitch, velocity, tuning, noteID) {
    // Set currentModulationValue based on note velocity
    currentModulationValue = velocity;
    KeyCounter +=1;
    samesame ();
}

//-----------------------------------------------------------
onNoteOffEvent = function (channel, pitch, velocity, tuning, noteID) {
    KeyCounter -= 1;
    // Reset currentModulationValue to 0 when last key is released
    if (KeyCounter == 0)
    {
        currentModulationValue = 0;
    }
}