How to use "makeIndexedFunction"

Post Reply New Topic
RELATED
PRODUCTS

Post

Hi.
I question myself about this function, I didn't figure out how to use it:

function makeIndexedFunction(index, f) {
function indexedFunc(value) {
f(index, value);
}
return indexedFunc
}

I know that help for writting observer callback functions, but can anyone explain me how it work exactly?

Post

E.g. if you want to handle the volume of 8 tracks but only write 1 function for the handling and then get the index of the track as a parameter.

Something like this:

Code: Select all

function volumeHandler (trackIndex, volume)
{
	println ("Volume changed of track " + trackIndex + ": " + volume);    
}

var index;
for (index = 0; index < 8; index++)
{
	callback = makeIndexedFunction(index, volumeHandler);
	// Register xxx.addObserver (callback);
}
You can also use that with objects. If you are interested how to do this download one of my old controller scripts and search for "doObjectIndex" which does the same but for objects:

http://www.mossgrabers.de/Software/Bitwig/Bitwig.html (download one of the scripts under 1.3.16).

Post

Thanks !

I have already download your last javascript package. i have not understand all the code you write, but yeah I plan to learn POO. I am a (old) procedural programmer...

Post Reply

Return to “Controller Scripting”