No internet connection
  1. Home
  2. How to

How to handle better the "No Audio Was Selected" If we don't have any audio select?

Hi,

Some scripts need to have audio clip(s) selected at the beginning, what it's the best way to "handle" this and then continue do to the work if everything is ok?

Here is the code to

1- Create a session with two audio clips (I think it could be dummy files)
- Don't select any clip It should click in the Warning and close AS plugins
- Select the first clip
- Behaviour - Sometimes the prompt question appears and sometimes it doesn't

2- Uncomment the line "//sf.wait({ intervalMs: 750 }); //Disable to see a different behaviour"

Behaviour:
1st- I have 99% sure that it work when there's no audio clip selected and do what he need to
2nd- The prompt not always appear!!!

I think is my lack of code to figure this out.... HELP!!!!

Thank you Christian / Kitch / Jesper and everyone :)

ps: later I will add a video showing the video

sf.ui.proTools.appActivateMainWindow();

function moveAsProLimiter() {
    var asWinPro = sf.ui.proTools.getAudioSuiteWindow("Pro Limiter");
    if (!asWinPro.exists) {
        asWinPro = sf.ui.proTools.audioSuiteOpenPlugin({
            category: 'Dynamics',
            name: "Pro Limiter"
        }).window;
        sf.ui.proTools.firstAudioSuiteWindow.buttons.whoseTitle.is('Target button').first.elementClick();
    }

    //This will move AS window
    var screenIndex = 0;
    var screenFrame = sf.ui.screens.allScreens[screenIndex].visibleFrame;
    var windowFrame = asWinPro.frame;
    asWinPro.windowMove({
        position: {
            x: screenFrame.x + screenFrame.w / 1 - windowFrame.w / 1,
            y: screenFrame.y + screenFrame.h / 2 - windowFrame.h / 3,
        }
    });

}

function moveAsAnlzrProLimiter() {
    var asWinAnlzr = sf.ui.proTools.getAudioSuiteWindow("Pro Limiter Loudness Analyzer");
    if (!asWinAnlzr.exists) {
        asWinAnlzr = sf.ui.proTools.audioSuiteOpenPlugin({
            category: 'Other',
            name: "Pro Limiter Loudness Analyzer"
        }).window;
        sf.ui.proTools.firstAudioSuiteWindow.buttons.whoseTitle.is('Target button').first.elementClick();
    }

    //This will move AS window
    var screenIndex = 0;
    var screenFrame = sf.ui.screens.allScreens[screenIndex].visibleFrame;
    var windowFrame = asWinAnlzr.frame;
    asWinAnlzr.windowMove({
        position: {
            x: screenFrame.x + screenFrame.w / 1 - windowFrame.w / 1,
            y: screenFrame.y + screenFrame.h / 3 - windowFrame.h / 1,
        }
    });
}

function AvidProLimiterRender(higherResult) {

    sf.soundflow.bypass();

    sf.keyboard.type({
        text: '' + higherResult
    });

    sf.keyboard.press({ keys: 'return' });
    sf.soundflow.bypass();

    var asWinPro = sf.ui.proTools.getAudioSuiteWindow("Pro Limiter");
    if (!asWinPro.exists) {
        asWinPro = sf.ui.proTools.audioSuiteOpenPlugin({
            category: 'Dynamics',
            name: "Pro Limiter"
        }).window;
    }

    asWinPro.audioSuiteSetOptions({
        processingInputMode: "EntireSelection",
        processingOutputMode: "OverwriteFiles",
    });

    asWinPro.getFirstWithTitle("Render").elementClick();

    sf.ui.proTools.confirmationDialog.elementWaitFor();
    sf.ui.proTools.confirmationDialog.buttons.whoseTitle.is('Continue').first.elementClick();

    asWinPro.audioSuiteSetOptions({
        processingInputMode: "EntireSelection",
        processingOutputMode: "CreateContinuousFile",
    });

    var asWin = sf.ui.proTools.getFloatingWindowWithTitleStartingWith("Audio Suite: Pro Limiter Loudness Analyzer");
    asWin.getFirstWithTitle("Analyze").elementClick();

    log('We Have a Winner! Touché')

    closeAsWindows()
}

function closeAsWindows() {

    var asWinPro = sf.ui.proTools.getAudioSuiteWindow("Pro Limiter");
    if (!asWinPro.exists) {
        asWinPro = sf.ui.proTools.audioSuiteOpenPlugin({
            category: 'Dynamics',
            name: "Pro Limiter"
        }).window;
    }

    var asWinAnlzr = sf.ui.proTools.getAudioSuiteWindow("Pro Limiter Loudness Analyzer");
    if (!asWinAnlzr.exists) {
        asWinAnlzr = sf.ui.proTools.audioSuiteOpenPlugin({
            category: 'Other',
            name: "Pro Limiter Loudness Analyzer"
        }).window;
    }

    asWinPro.windowClose();
    asWinAnlzr.windowClose();
}

moveAsProLimiter()
moveAsAnlzrProLimiter()


try {
    var asWin = sf.ui.proTools.getFloatingWindowWithTitleStartingWith("Audio Suite: Pro Limiter Loudness Analyzer");
    asWin.getFirstWithTitle("Analyze").elementClick();

    //sf.wait({ intervalMs: 750 }); //Disable to see a different behaviour

    var noAudioSelected = sf.ui.proTools.windows.whoseTitle.is('').first.buttons.whoseTitle.is('OK');

    if (noAudioSelected.exists) {
        log('No Audio is selected')
        //sf.wait({ intervalMs: 500 });
        sf.ui.proTools.windows.whoseTitle.is('').first.buttons.whoseTitle.is('OK').first.elementClick();
        closeAsWindows()
    }
    else {
        var lufs = sf.interaction.popupText({ popupIdentifier: 'What value is in Integrated box' }).text;
        log("here we go")
    }
} catch (err) {
    //log('Try again');
    throw 0; //abort the script
}
  • 10 replies
  1. Hi Marco.

    One way would be to check for the existence or the enabled-ness of a menu item that would only be present/enabled when audio is selected.

    1. Didn't think on that. Gonna try it.
      Thank you

      1. In reply tochrscheuer:

        Hi Christian,
        Check this out! Is this supposed to do?
        1- Open any Audio Suite plugin, click render, a Popup Dialog will appear leave it there then try this

        try {
            sf.ui.proTools.getMenuItem('File', 'Create New...').elementClick();
        
        
        } catch (err) {
            log('Try again');
            throw 0; //abort the script
        }
        

        The first time normally will open "Create New Window" but it not supposed, because it isn't available when the "dialog window" is still in front, if you try the second time Pro Tools might crash with the Crash log window (take that in care)
        I can't use the Shortcut but when scripting it can open :)

        1. OOliver Momm @Oliver_Momm
            2020-08-07 18:04:04.942Z2020-08-08 06:50:02.412Z
            // If "Clip -> Group" is not enabled (no audio is selected), quit the script
            if (!sf.ui.proTools.getMenuItem('Clip', 'Group').isEnabled)
                throw 0;```
            1. Thanks @Oliver_Momm gonna test it.

              1. In reply toOliver_Momm:
                Dustin Harris @Dustin_Harris
                  2020-08-10 23:27:30.988Z

                  Unfortunately, 'Clip -> Group' seems to not require audio being selected, just a selection being present.

                  this might be (marginally) more reliable?

                  if (!sf.ui.proTools.getMenuItem('Clip', 'Rename...').isEnabled) throw 0;
                  
                  
                  1. Hi Dustin,

                    I've found another issue before this, I will try your suggestion too. I'll let you know if it worked.
                    Thank you so much.

            2. O
              In reply tombernardo:
              Oliver Momm @Oliver_Momm
                2020-08-07 18:06:42.078Z

                I forgot how to format code correctly as I haven't contributed since ages, sorry about that.

                1. To format text to code put three ticks ( ``` ([below the esc key]) above and below the script/code.

                2. O
                  In reply tombernardo:
                  Oliver Momm @Oliver_Momm
                    2020-08-08 06:50:13.548Z

                    Thx Chris!