No internet connection
  1. Home
  2. Macro and Script Help

Identify Beat script not working

By Vince Soliveri @Vince_Soliveri
    2024-09-08 18:34:06.515Z

    Title

    Identify Beat script not working

    What do you expect to happen when you run the script/macro?

    This script is supposed to open the Identify Beat window, round up or down the End location and click "ok".

    Every time i try to run this script, I am given an error message specifying something wrong with Line 10.

    Are you seeing an error?

    It specifies something is wrong with line 10

    What happens when you run this script?

    The Identify Beat window opens, after a few seconds the error message appears, then i have to manually exit the window

    How were you running this script?

    I clicked the "Run Script" or "Run Macro" button in SoundFlow

    How important is this issue to you?

    5

    Details

    {
        "inputExpected": "This script is supposed to open the Identify Beat window, round up or down the End location and click \"ok\".\n\nEvery time i try to run this script, I am given an error message specifying something wrong with Line 10. ",
        "inputIsError": true,
        "inputError": "It specifies something is wrong with line 10",
        "inputWhatHappens": "The Identify Beat window opens, after a few seconds the error message appears, then i have to manually exit the window",
        "inputHowRun": {
            "key": "-MpfwYA4I6GGlXgvp5j1",
            "title": "I clicked the \"Run Script\" or \"Run Macro\" button in SoundFlow"
        },
        "inputImportance": 5,
        "inputTitle": "Identify Beat script not working"
    }

    Source

    //Activate Pro Tools
    sf.ui.proTools.appActivateMainWindow();
    
    //Open Identify Beat window
    sf.ui.proTools.menuClick({
        menuPath: ["Event", "Identify Beat..."],
    });
    
    //Wait for the Identify Beat window to open
    sf.ui.proTools.windows.whoseTitle.is('Add Bar | Beat Marker').first.elementWaitFor();
    
    //The number of ticks in a 4/4 bar, which gives you a way to easily get ticks per beat regardless of the type of beat.
    const ticksMultiplier = 3840 
    
    //Retrieve the number of beats in each bar and setup all the variables we need to do the rounding
    var numberOfBeatsInEachBar = Number(sf.ui.proTools.windows.whoseTitle.is('Add Bar | Beat Marker').first.textFields.allItems[1].value.value);
    var typeOfBeats = Number(sf.ui.proTools.windows.whoseTitle.is('Add Bar | Beat Marker').first.textFields.allItems[2].value.value);
    var ticksPerBeat = ticksMultiplier/typeOfBeats;
    var ticksPerBar = numberOfBeatsInEachBar * ticksPerBeat;
    
    //Get Bars:Beats:Ticks
    var barsAndBeatsVariable = sf.ui.proTools.windows.whoseTitle.is('Add Bar | Beat Marker').first.textFields.first.value.value;
    
    //Split barsAndBeatsVariable variable into an array.
    var barsAndBeatsSplitArray = barsAndBeatsVariable.split("|");
    
    //Bars Variable
    var selectedBars = Number(barsAndBeatsSplitArray[0]);
    
    //Beats Variable
    var selectedBeats = Number(barsAndBeatsSplitArray[1]);
    
    //Ticks Variable
    var selectedTicks = Number(barsAndBeatsSplitArray[2]);
    
    // Where are we in the bar?
    
    //Evaluate Ticks
    var selectedInTicks = selectedBeats * ticksPerBeat + selectedTicks;
    if (selectedInTicks >= ticksPerBar/2) {
        selectedBars = selectedBars + 1;
    };
    
    //Set up variable for rounded bar number
    var roundedBarNumber = String(selectedBars);
    
    //Update rounded bar number
    sf.keyboard.type({
        text: roundedBarNumber,
    });
    
    //Create variable for while loop
    var textField = sf.ui.proTools.windows.whoseTitle.is('Add Bar | Beat Marker').first.textFields.first;
    
    //Wait for Bars and Beats Location field to update
    var i = 0;
    while (textField.value.invalidate().value.trim() !== (roundedBarNumber+"| 1| 000")) {
        sf.wait({ intervalMs: 50 });
        if (i++ > 10) throw `Value didn't update after 10 attempts. Value entered: "${roundedBarNumber}". Value found: "${textField.value.value}"`;
    };
    
    //Click OK
    sf.ui.proTools.windows.whoseTitle.is('Add Bar | Beat Marker').first.buttons.whoseTitle.is('OK').first.elementClick();
    
    //Wait for Identify Beat window to disappear
    sf.ui.proTools.windows.whoseTitle.is('Add Bar | Beat Marker').first.elementWaitFor({
        waitType: "Disappear",
    });
    

    Links

    User UID: afuiFI4OyahjwfvMCdUjjizzo6B3

    Feedback Key: sffeedback:afuiFI4OyahjwfvMCdUjjizzo6B3:-O6HuXQesNmPfdTT5AkR

    Feedback ZIP: luYuYF0ptILDQLCzcgHGfaOjDapKsPTryG6Gn5zcO+JKoa5o7x5L1pF02BtQopnQtc7L5T8cME0srAKGsowOVdGcUYFVJkFTXcdx0SiEkSGHjIiLmTgra0p3Wx+JXEQK+KZtgIiCq+EylE4lL+huKa5wtKxIAZoawEQlBdgLgztuOT0+tHVV4GLjOpQWgBlI7SFZe+vwGSWbD/JP8bZ8QMpRCHHZqng+A6DNBIm8E3F56iERipF3pZGDYctrEMBjLB7v0+em1Mv/s2nGcPMoQajQHOm/KI81fH7HWLMDQLmLbk0zl+qX3Fb8+tL9Jo4/6/B/8ll1m7JDDF5sOKbGoG6hcZNYK+xMQ2u1cdIx6Kg=

    • 1 replies
    1. Hi Vince,

      I just tried your script here and it works fine for me.
      It might be helpful for our team and the community if you can share a screen recording.

      I notice on my end that the "Add Bar | Beat Marker" window shows up correctly for me, and it continues with the script as it should. Did you write this script yourself or did you find it somewhere? If you found it somewhere, it might be helpful if you can tag the user who created the script.