Purging all samplers



  • 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?


  • administrators

    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);});
    


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


  • administrators

    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.



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


Log in to reply
 

4
Online

343
Users

1.1k
Topics

7.1k
Posts

Looks like your connection to Forum was lost, please wait while we try to reconnect.