Loris processCustom with Lambda arguments?
-
Pretty sure I've asked something like this before but I can't find the thread, is there a way to pass arguments to the processCustom lambda function?
inline function myCoolFunction(obj, f) { obj.frequency = f; } lorisManager.processCustom(audio, myCoolFunction(440.0)); // ?
Inline function call myCoolFunction: parameter amount mismatch: 1 (Expected: 2)
-
@iamlamprey said in Loris processCustom with Lambda arguments?:
myCoolFunction(440.0)
I'm not sure about Loris, but the source of the error is because your function is expecting 2 parameters (obj, f) and you're only sending one (440.0)
-
@iamlamprey said in Loris processCustom with Lambda arguments?:
lorisManager.processCustom(audio, myCoolFunction(440.0)); // ?
lorisManager.processCustom(audio, myCoolFunction(obj, 440.0)); // ?
Example
Content.makeFrontInterface(600, 600); var obj = {"frequency": 0}; inline function myCoolFunction(obj, f) { obj.frequency = f; Console.print(trace(obj)); } myCoolFunction(obj,440.0); // ?
-
Yeah that works for regular functions but Loris is a bit different:
// works function myCoolFunction(obj) { // even Console.print(obj.frequency) here crashes HISE obj.frequency = 440.0; // works } // doesn't work function myLessCoolFunction(obj, f) { obj.frequency = f; } // obj is already defined by a separate Loris process: lorisManager.analyse(file, f0); // this is our obj, we don't need to declare it or pass it to the function // works lorisManager.processCustom(file, myCoolFunction); // no parameters, just the function name // breaks lorisManager.processCustom(file, myLessCoolFunction(obj, 440.0)); // standard lambdas also break lorisManager.processCustom(file, function [obj, 440.0](myLessCoolFunction)); // "can't capture anonymous expression"
It's not a huge deal, I can just make a few variants of the function ¯_(ツ)_/¯
-
@iamlamprey Okay a simple workaround is to just call another inline function inside the Loris one:
inline function adjustHarmonicGain(partial, freq, target, tolerance, multiplier) { // Adjusts the gains of any partials that lie within the tolerance of a target frequency local spectralDistance = freq > target ? freq - target : target - freq; if (spectralDistance < tolerance) partial.gain *= multiplier; } inline function myCoolFunction(obj) { adjustHarmonicGain(obj, obj.frequency, 440.0, 50.0, 0.0); // works } lorisManager.processCustom(file, myCoolFunction);
-
@iamlamprey yes, loris calls into the function with a single argument containing the data object, so if you supply more arguments it will be ignored.
The lambda way would also work, but you cannot pass literal values (in this case the 440.0), but it needs to be a locally scoped variable.
Another option would be to use a variable outside of the function that you set to 440.0.