No internet connection
  1. Home
  2. How to

repeat macro using n times variable w/ user prompt

By @briannaas
    2023-03-21 21:29:22.712Z

    Hi,

    I'm looking to create a macro which:

    • prompts for a number variable
    • then repeats a macro by that number

    In this case, I am looking to run the iZotope Loudness Control plugin on a given region, clicking the "analyze" then "render" buttons, then selecting the next clip in the timeline.

    I think I understand the scripts for the each element but I don't know how to tie them together. The macro to be repeated is:

    sf.ui.proTools.audioSuiteOpenPlugin({
        category: "Sound Field",
        name: "iZotope RX Loudness Control",
    });
    
    sf.ui.proTools.firstAudioSuiteWindow.audioSuiteSelectPreset({
        presetMenuPath: ["Calm_2"],
    });
    
    sf.ui.proTools.firstAudioSuiteWindow.buttons.whoseTitle.is('Analyze').first.elementClick();
    
    sf.wait({
        intervalMs: 3500,
    });
    
    sf.ui.proTools.firstAudioSuiteWindow.audioSuiteRender();
    
    sf.wait({
        intervalMs: 3000,
    });
    
    /* sf.ui.proTools.clipSelectNextFullClip(); */
    
    sf.keyboard.press({
        keys: "up, tab, shift+tab",
    });
    

    I know this script is the "repeat n times"

    /**@type {{
      repetitions,
      action?: () => void,
    }} */
    const { repetitions, action } = event.props;
    
    for (var i = 0; i < repetitions; i++) {
      action();
    }
    

    And the user prompt is something like:

    var repeat = prompt("How many?");
    

    I just don't know how to tie all these things together.

    Thanks!

    • 4 replies
    1. Hi Brian,

      You should be able to do something like this:

      var repetitions = Number(prompt("How many?"));
      if (isNaN(repetitions)) throw 0; //Cancel if they didn't enter a number
      
      //repeat n times
      for(var i=0; i<repetitions; i++) {
      
          //insert here what should be repeated
          log(`This is iteration ${i+1}`);
      
      }
      
      1. then selecting the next clip in the timeline

        SoundFlow has built-in functions to help doing something for each selected clip.
        Here's an example:

        1. In reply tochrscheuer:
          B@briannaas
            2023-05-06 16:52:50.051Z

            This is perfect, thanks Christian! As a different variation, is there a way that a number prompt can trigger different macros? Eg, if I enter "1" it will run macro A, "2" it will run macro B, etc.

            1. Yes, you could set that up, but it'd be better to start as a new thread :)