No internet connection
  1. Home
  2. How to

ELASTIC VARI SPEED 4 ALL SELECTED

By Juan B Caballero @Juan_B_Caballero
    2021-04-23 22:05:15.039Z2021-04-23 22:21:46.651Z

    Hi. I'm working with this script to set Vari Speed on selected tracks:

    function getCurrentTrackHeight(h) {
    
        let originalTrackHeight;
        let isTrackTooSmall = (h < 61) ? true : false;
    
        switch (true) {
            case (h <= 16):
                originalTrackHeight = 'micro';
                break;
            case (h === 23):
                originalTrackHeight = 'mini';
                break;
            case (h === 43 || h === 61):
                originalTrackHeight = 'small';
                break;
            case (h === 79 || h === 97 || h === 116):
                originalTrackHeight = 'medium';
                break;
            case (h === 135 || h === 173 || h === 192 || h === 213 || h === 235):
                originalTrackHeight = 'large';
                break;
            case (h === 257 || h === 279 || h === 300):
                originalTrackHeight = 'jumbo';
                break;
            case (h > 300):
                originalTrackHeight = 'extreme';
                break;
        }
        return { originalTrackHeight, isTrackTooSmall }
    }
    
    function setTrackSize(size) {
    
        var f = sf.ui.proTools.selectedTrack.frame;
        var popupMenu = sf.ui.proTools.selectedTrack.popupMenuOpenFromElement({
            relativePosition: { x: f.w - 10, y: 5 },
            isOption: true,
            isShift: true,
        }).popupMenu;
        popupMenu.menuClickPopupMenu({
            menuPath: [size]
        });
    }
    
    function setElasticAudioPluginFromPopup(elasticAudioPlugin) {
        const elasticAudioCurrent = sf.ui.proTools.focusedWindow.popupButtons.allItems[2].invalidate().value.value;
        if (elasticAudioCurrent != elasticAudioPlugin) {
            sf.ui.proTools.focusedWindow.popupButtons.allItems[2].popupMenuSelect({
                menuPath: [elasticAudioPlugin],
            });
        }
    }
    
    function main(timebase, elasticAudioPlugin) {
    
        const selectedTrackHeight = sf.ui.proTools.selectedTrack.frame.h;
    
        let { originalTrackHeight, isTrackTooSmall } = getCurrentTrackHeight(selectedTrackHeight)
    
        if (isTrackTooSmall) { setTrackSize("medium") }
    
    
        //  get current timebase
        let timebaseCurrent = sf.ui.proTools.selectedTrack.popupButtons.whoseValue.is("").allItems[1].invalidate().title.value.split(" (").slice(1)[0].slice(0, -1)
        timebaseCurrent = timebaseCurrent.charAt(0).toUpperCase() + timebaseCurrent.slice(1)
    
        //  get current elastic audio plugin
        const elasticAudioCurrent = sf.ui.proTools.selectedTrack.popupButtons.allItems[4].invalidate().value.value;
    
        //   set timebase
        if (timebaseCurrent != timebase) {
            sf.ui.proTools.selectedTrack.popupButtons.allItems[3].popupMenuSelect({ menuPath: [timebase] });
        }
    
        //  set elastic audio plugin
        if (elasticAudioCurrent != elasticAudioPlugin) {
            try {
                sf.ui.proTools.selectedTrack.popupButtons.allItems[4].popupMenuSelect({ menuPath: [elasticAudioPlugin], timeout: 100 });
            } catch (e) { setElasticAudioPluginFromPopup(elasticAudioPlugin) }
        }
    
    
        // get current track hight as it might have changed, if its between PT sizes, aproximate will be set 
        const currentTrackHight = sf.ui.proTools.selectedTrack.frame.h;
    
        if (currentTrackHight != selectedTrackHeight)
            setTrackSize(originalTrackHeight)
    
    }
    
    //Get selected tracks
    const originalTracks = sf.ui.proTools.selectedTrackNames;
    
    //Do for each track.
    sf.ui.proTools.selectedTracks.trackHeaders.slice().map(track => {
    
        //Select track
        track.trackSelect();
    
        //Scroll track into View
        track.trackScrollToView();
    
        ///  set desired settings 
        main("Ticks", "Varispeed")
    });
    
    //Restore previously selected tracks
    sf.ui.proTools.trackSelectByName({ names: originalTracks });
    

    The Script do the setting one by one and when there is a lot of tracks selected (when I load a lot of sounds and loops from splice to try) it takes some time to end the task. Any idea about how to include Option + Shift so the order is done at the same time in all selected tracks?
    Thanks

    • 11 replies

    There are 11 replies. Estimated reading time: 11 minutes

    1. Kitch Membery @Kitch2021-04-23 22:21:22.965Z

      Hi Juan,

      I'll take a look at this when I get a moment unless someone beats me to it. :-)

      But be sure to check this tutorial for how to quote code in the SoundFlow forum, so that it displays in a readable format:

      Rock on!

      1. JJuan B Caballero @Juan_B_Caballero
          2021-04-24 03:08:53.641Z

          got it

        • Kitch Membery @Kitch2021-04-23 22:28:34.252Z2021-04-25 22:33:57.081Z

          To select Varispeed on all selected tracks you can use this;

          //Set Drums group to Elastic Audio Varispeed 
          const popupMenu = sf.ui.proTools.selectedTrack.popupButtons.whoseTitle.is("Current Elastic Audio Plug-in").first.popupMenuOpenFromElement({
              relativePosition: { "x": -3, "y": 3 },
              isOption: true,
              isShift: true,
          }).popupMenu;
          
          popupMenu.popupMenuSelect({
              menuPath: ["Varispeed"],
          });
          

          Let me know if that works for you :-)

          1. JJuan B Caballero @Juan_B_Caballero
              2021-04-25 22:26:31.881Z

              Hi Kitch. My old command not only set Elastic Audio to Varispeed but set the track in thicks also. I assume that your script only sets Varispeed. My question is: does your script replace all my command or do I need to copy it at some point of my old script?
              Thanks

              1. Kitch Membery @Kitch2021-04-25 22:29:03.477Z

                Hi Juan,

                My script only takes care of Selecting Varispeed for all tracks at the same time.

                I'll take a look at your script when I get a moment.

                Rock on

                1. JJuan B Caballero @Juan_B_Caballero
                    2021-04-25 22:35:57.325Z

                    thaks!!

                    1. Kitch Membery @Kitch2021-04-26 11:26:06.098Z

                      Hi @Juan_B_Caballero,

                      I may need to refactor a few things in this script but let me know if it works for you :-)

                      I'm using a different way of increasing the track height (using a keyboard simulation) but thought this is probably the best way to deal with multiple track heights without having to change heights track-by-track.

                      /**@param {string} plugin */
                      function setElasticAudioPluginFromPopup(plugin) {
                          const track = sf.ui.proTools.selectedTrack;
                      
                          //Set Drums group to Elastic Audio Varispeed 
                          const popupMenu = track.popupButtons.whoseTitle.is("Current Elastic Audio Plug-in").first.popupMenuOpenFromElement({
                              relativePosition: { "x": -3, "y": 3 },
                              isOption: true,
                              isShift: true,
                          }).popupMenu;
                      
                          popupMenu.popupMenuSelect({
                              menuPath: ['Varispeed'],
                          });
                      }
                      
                      /**@param {string} timebase */
                      function setTimebase(timebase) {
                          sf.ui.proTools.selectedTrack.popupButtons.allItems[3].popupMenuSelect({
                              menuPath: [timebase],
                              isOption: true,
                              isShift: true,
                          });
                      }
                      
                      /**
                       * @param {number} smallestTrackHeight
                       * @param {'Up'|'Down'} direction
                       */
                      function adjustTrackHeight(smallestTrackHeight, direction) {
                      
                          /** @param {number} trackHeight*/
                          function getTrackSizeIncereaseCount(trackHeight) {
                              const trackheights = {
                                  16: 3,
                                  23: 2,
                                  43: 1,
                              }
                              return trackheights[trackHeight] || 0;
                          }
                      
                          let increaseTrackHeightCount = getTrackSizeIncereaseCount(smallestTrackHeight);
                      
                          for (let i = 0; i < increaseTrackHeightCount; i++) {
                              sf.keyboard.press({
                                  keys: `ctrl+${direction.toLocaleLowerCase()}`,
                              });
                          }
                      }
                      
                      function main() {
                          sf.ui.proTools.mainWindow.invalidate();
                      
                          const originalTracks = sf.ui.proTools.selectedTrackNames;
                      
                          // Scroll track into View
                          sf.ui.proTools.selectedTrack.trackScrollToView();
                      
                          sf.ui.proTools.trackSelectByName({ names: originalTracks });
                      
                          const selectedTrackHeights = sf.ui.proTools.selectedTrackHeaders.map(track => track.frame.h);
                      
                          const smallestTrackHeight = Math.min(...selectedTrackHeights);
                      
                          //Set track heights if any are too small
                          adjustTrackHeight(smallestTrackHeight, 'Up');
                      
                          // Set timebase for all selected tracks to "Ticks"
                          setTimebase("Ticks");
                      
                          // Set track Plugin for all selected tracks to "Varispeed".
                          setElasticAudioPluginFromPopup('Varispeed');
                      
                          sf.wait();
                      
                          //Restore track heights
                          adjustTrackHeight(smallestTrackHeight, 'Down');
                      }
                      
                      main();
                      

                      Rock on!

                      1. Kitch Membery @Kitch2021-04-28 01:44:45.719Z

                        @Juan_B_Caballero

                        Just checking back to see if this worked for you?

                        Rock on!

                        1. JJuan B Caballero @Juan_B_Caballero
                            2021-04-29 04:47:24.375Z

                            I had accidentally skipped this message, and I've just tried the script. Its perfect!! Thanks

                            1. Kitch Membery @Kitch2021-04-29 04:48:16.115Z

                              Awesome. Good to hear :-)

                2. J
                  Juan B Caballero @Juan_B_Caballero
                    2021-04-23 22:42:10.044Z

                    OK: Thanks for the advice

                    Here I go again with my script correctly and two more questions.
                    Is the script you just sent me something I need to add to my script? (At the end?) Or does it replace my whole script?
                    My script also sets the selected track in ticks. I think your new code doesn't. Does it?
                    Thanks!

                    function getCurrentTrackHeight(h) {
                    
                    let originalTrackHeight;
                    let isTrackTooSmall = (h < 61) ? true : false;
                    
                    switch (true) {
                        case (h <= 16):
                            originalTrackHeight = 'micro';
                            break;
                        case (h === 23):
                            originalTrackHeight = 'mini';
                            break;
                        case (h === 43 || h === 61):
                            originalTrackHeight = 'small';
                            break;
                        case (h === 79 || h === 97 || h === 116):
                            originalTrackHeight = 'medium';
                            break;
                        case (h === 135 || h === 173 || h === 192 || h === 213 || h === 235):
                            originalTrackHeight = 'large';
                            break;
                        case (h === 257 || h === 279 || h === 300):
                            originalTrackHeight = 'jumbo';
                            break;
                        case (h > 300):
                            originalTrackHeight = 'extreme';
                            break;
                    }
                    return { originalTrackHeight, isTrackTooSmall }
                    }
                    
                    function setTrackSize(size) {
                    
                    var f = sf.ui.proTools.selectedTrack.frame;
                    var popupMenu = sf.ui.proTools.selectedTrack.popupMenuOpenFromElement({
                        relativePosition: { x: f.w - 10, y: 5 },
                        isOption: true,
                        isShift: true,
                    }).popupMenu;
                    popupMenu.menuClickPopupMenu({
                        menuPath: [size]
                    });
                    }
                    
                    function setElasticAudioPluginFromPopup(elasticAudioPlugin) {
                    const elasticAudioCurrent = sf.ui.proTools.focusedWindow.popupButtons.allItems[2].invalidate().value.value;
                    if (elasticAudioCurrent != elasticAudioPlugin) {
                    sf.ui.proTools.focusedWindow.popupButtons.allItems[2].popupMenuSelect({
                    menuPath: [elasticAudioPlugin],
                    });
                    }
                    }
                    
                    function main(timebase, elasticAudioPlugin) {
                    
                    const selectedTrackHeight = sf.ui.proTools.selectedTrack.frame.h;
                    
                    let { originalTrackHeight, isTrackTooSmall } = getCurrentTrackHeight(selectedTrackHeight)
                    
                    if (isTrackTooSmall) { setTrackSize("medium") }
                    
                    
                    //  get current timebase
                    let timebaseCurrent = sf.ui.proTools.selectedTrack.popupButtons.whoseValue.is("").allItems[1].invalidate().title.value.split(" (").slice(1)[0].slice(0, -1)
                    timebaseCurrent = timebaseCurrent.charAt(0).toUpperCase() + timebaseCurrent.slice(1)
                    
                    //  get current elastic audio plugin
                    const elasticAudioCurrent = sf.ui.proTools.selectedTrack.popupButtons.allItems[4].invalidate().value.value;
                    
                    //   set timebase
                    if (timebaseCurrent != timebase) {
                        sf.ui.proTools.selectedTrack.popupButtons.allItems[3].popupMenuSelect({ menuPath: [timebase] });
                    }
                    
                    //  set elastic audio plugin
                    if (elasticAudioCurrent != elasticAudioPlugin) {
                        try {
                            sf.ui.proTools.selectedTrack.popupButtons.allItems[4].popupMenuSelect({ menuPath: [elasticAudioPlugin], timeout: 100 });
                        } catch (e) { setElasticAudioPluginFromPopup(elasticAudioPlugin) }
                    }
                    
                    
                    // get current track hight as it might have changed, if its between PT sizes, aproximate will be set 
                    const currentTrackHight = sf.ui.proTools.selectedTrack.frame.h;
                    
                    if (currentTrackHight != selectedTrackHeight)
                        setTrackSize(originalTrackHeight)
                    }
                    
                    //Get selected tracks
                    const originalTracks = sf.ui.proTools.selectedTrackNames;
                    
                    //Do for each track.
                    sf.ui.proTools.selectedTracks.trackHeaders.slice().map(track => {
                    
                    //Select track
                    track.trackSelect();
                    
                    //Scroll track into View
                    track.trackScrollToView();
                    
                    ///  set desired settings 
                    main("Ticks", "Varispeed")
                    });
                    
                    //Restore previously selected tracks
                    sf.ui.proTools.trackSelectByName({ names: originalTracks });