No internet connection
  1. Home
  2. How to

How to repeat an action

By Tilman Hahn @Tilman_Hahn
    2020-10-02 14:28:30.184Z

    Is there a way to repeat a macro x times or loop it?

    Solved in post #3, click to view
    • 7 replies
    1. Hi Tilman,

      Currently, we don't have control flow actions for the Macro Editor.
      But you can convert your macro into a script and in your script, you can do repetition via a for loop or while loop, etc.

      Do you need your repetition to always be the same number, or based on a number the user presses, or using some even different logic? That's what scripts are great for.

      You can see an example here, where we're repeating an action until the end of the original selection is reached.

      There are many options, so the best way to achieve the desired logic, is to try to list up the step-by-step actions you wish your macro to take, and then we'll take it from there.

      1. The simplest loop form in a script would be the for loop.

        Usually, for loops count from 0 and then iterate as long as the iteration variable is less than the desired number of iterations.
        So, if we use i for the iteration variable and we start a 0 and we want 5 total iterations, we'd put it like this:

        //Loop 5 times
        for(let i=0; i<5; i++) {
        
            //Here you put the stuff you want repeated 5 times
        
        }
        
        Reply1 LikeSolution
        1. TTilman Hahn @Tilman_Hahn
            2020-10-07 09:19:50.596Z

            Hi Christian,
            thanks that worked really well!
            I'm now trying to let the loop recognize that there are no more clips left on the timeline and that he should jump back to the start of the session, to perform the same loop on the track below. The main problem for me is to tell the loop to stop when there are no more clips or tracks left.

            1. Hi Tilman,

              We have built-in functions in SoundFlow for iterating through all clips in the timeline, and also for each selected track. But it's much easier to help you if we know what you'd like to do for each clip / the overall workflow. Can you explain a bit more what exactly you'd like to happen?

            2. In reply tochrscheuer:
              Andrew Piland @Andrew_Piland
                2024-06-21 11:36:22.700Z

                This script has done wonders for me. Is there any way to have a window pop up beforehand asking how many times you want the script looped instead of going into the code and manually adjusting it?

                1. Yes :)

                  
                  var numberOfTimes = Number(prompt(`How many times would you like to repeat this action?`));
                  if (isNaN(numberOfTimes)) throw `Please specify a number`;
                  
                  //Loop `numberOfTimes` times
                  for(let i=0; i<numberOfTimes; i++) {
                  
                      //Here you put the stuff you want repeated `numberOfTimes` times
                  
                  }
                  
                  1. Andrew Piland @Andrew_Piland
                      2024-06-21 15:24:38.890Z

                      That works perfectly, thanks!