HISE Logo Forum
    • Categories
    • Register
    • Login

    Loris processCustom with Lambda arguments?

    Scheduled Pinned Locked Moved Scripting
    6 Posts 4 Posters 223 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • ?
      A Former User
      last edited by

      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)

      Dan KorneffD ospfeigrpO 2 Replies Last reply Reply Quote 0
      • Dan KorneffD
        Dan Korneff @A Former User
        last edited by

        @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)

        Dan Korneff - Producer / Mixer / Audio Nerd

        1 Reply Last reply Reply Quote 1
        • ospfeigrpO
          ospfeigrp @A Former User
          last edited by ospfeigrp

          @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); // ?
          
          1 Reply Last reply Reply Quote 0
          • ?
            A Former User
            last edited by

            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 ¯_(ツ)_/¯

            ? 1 Reply Last reply Reply Quote 0
            • ?
              A Former User @A Former User
              last edited by A Former User

              @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);
              
              Christoph HartC 1 Reply Last reply Reply Quote 1
              • Christoph HartC
                Christoph Hart @A Former User
                last edited by

                @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.

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post

                34

                Online

                1.8k

                Users

                12.1k

                Topics

                105.0k

                Posts