HISE Logo Forum
    • Categories
    • Register
    • Login

    Purging all samplers

    Scheduled Pinned Locked Moved Scripting
    5 Posts 2 Posters 1.2k 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.
    • d.healeyD
      d.healey
      last edited by

      I have a project with multiple samplers in a number of containers, all the samples in all the samplers have the same number of mic positions. Is there an easy way to purge a mic channel from all of the samplers in one go without having to manually create an array containing all of the samplers by name? Or could this be done by traversing the tree and selecting each sampler in a loop?

      Libre Wave - Freedom respecting instruments and effects
      My Patreon - HISE tutorials
      YouTube Channel - Public HISE tutorials

      1 Reply Last reply Reply Quote 0
      • Christoph HartC
        Christoph Hart
        last edited by Christoph Hart

        I think iterating over an array is the best solution (performance and clarity wise):

        const var names = ["Sine Wave Generator", "Sine Wave Generator2"];
        const var synths = [];
        
        // Create the synth array
        for(name in names) synths.insert(-1, Synth.getChildSynth(name));
        
        // Do something for every module
        for(synth in synths) synth.setAttribute(0, 0.5);
        

        I could write a helper function that returns an array with the IDs of all modules of a given type, which you can use to get the names array:

        /** Searches all child processors and returns a list of all names with the given type. */
        Array Synth.getIdList(String typename)
        

        so you can just say:

        const var names = Synth.getIdList("Sampler");
        

        And if you really want to take advantage of Javascript's awesomeness, you can use a custom function as argument to do something like this:

        const var names = ["Sine Wave Generator", "Sine Wave Generator2"];
        const var synths = [];
        
        for(name in names) synths.insert(-1, Synth.getChildSynth(name));
        for(synth in synths) synth.setAttribute(0, 0.5);
        
        inline function doSomethingForEverySynth(f)
        {
        	for(synth in synths) f(synth);
        }
        
        doSomethingForEverySynth(function(s){s.setAttribute(0, 1.0);});
        
        1 Reply Last reply Reply Quote 0
        • d.healeyD
          d.healey
          last edited by

          That seems like a great solution, and the helper function will be a very useful addition.

          Libre Wave - Freedom respecting instruments and effects
          My Patreon - HISE tutorials
          YouTube Channel - Public HISE tutorials

          1 Reply Last reply Reply Quote 0
          • Christoph HartC
            Christoph Hart
            last edited by

            Alright, I commited the additional method.

            Usage:

            namespace PurgeEverything
            {
            	const var names = Synth.getIdList("Sampler");
            	const var samplers = [];
            
            	for(n in names) samplers.insert(-1, Synth.getSampler(n));
            
            	inline function yes()
            	{
            		for(s in samplers) s.setAttribute(12, 1);
            	};
            	
            	inline function no()
            	{
            		for(s in samplers) s.setAttribute(12, 0);
            	};
            };
            
            PurgeEverything.yes(); // the beauty of having a namespace :)
            

            This purges everything, but you can change it to only purge selected channels.

            1 Reply Last reply Reply Quote 1
            • d.healeyD
              d.healey
              last edited by

              Wow that was fast! I'll try it out soon

              Libre Wave - Freedom respecting instruments and effects
              My Patreon - HISE tutorials
              YouTube Channel - Public HISE tutorials

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

              32

              Online

              1.7k

              Users

              11.7k

              Topics

              102.0k

              Posts