No internet connection
  1. Home
  2. How to

Checking whether a setting is already ticked - or resetting it -Triplets in Quantize

By Simon Franglen @Simon_Franglen
    2020-01-26 19:46:17.954Z2020-01-26 20:17:32.355Z

    I'm creating scripts to quantise to different amount. I have one for triplet values, however if triplets have been previously selected, applying this script toggles the triplet setting to off.
    Is there a way for SF to check whether a variable is already checked on before switching it, or to reset it first?

    sf.ui.proTools.appActivateMainWindow();
    
    sf.keyboard.press({
        keys: "alt+numpad 0",
    });
    
    sf.ui.proTools.windows.whoseTitle.is('Event Operations').first.elementWaitFor();
    
    sf.ui.proTools.windows.whoseTitle.is('Event Operations').first.popupButtons.whoseDescription.is('').allItems[2].popupMenuSelect({
        menuPath: ["1/2 note"],
    });
    sf.wait();
    
    sf.ui.proTools.windows.whoseTitle.is('Event Operations').first.popupButtons.whoseDescription.is('').allItems[2].popupMenuSelect({
        menuPath: ["triplet"],
    });
    sf.wait();
    
    sf.ui.proTools.windows.whoseTitle.is('Event Operations').first.buttons.whoseTitle.is('Apply').first.elementClick();
    
    sf.ui.proTools.windows.whoseTitle.is('Event Operations').first.windowClose();
    
    sf.ui.proTools.windows.whoseTitle.is('Event Operations').first.elementWaitFor({
        waitType: "Disappear",
    });
    
    Solved in post #5, click to view
    • 9 replies
    1. Hi Simon.

      I'm sorry, your entry here got lost in mail hell.
      I can't test this right now since I'm not on a PT computer, but try this:

      if (sf.ui.proTools.windows.whoseTitle.is('Event Operations').first.popupButtons.whoseDescription.is('').allItems[2].value.invalidate().value !== "1/2 note") {
          sf.ui.proTools.windows.whoseTitle.is('Event Operations').first.popupButtons.whoseDescription.is('').allItems[2].popupMenuSelect({
              menuPath: ["1/2 note"],
          });
      }
      
      1. Hi Simon

        Could you get this working?

      2. S
        In reply toSimon_Franglen:
        Simon Franglen @Simon_Franglen
          2020-03-18 23:17:55.508Z

          This almost works. It resets the command to a 1/2 note before selecting the new quantise value, however it does not reset the Triplet Tick below the value.
          What I want is for the macro to either check whether the triplet has been ticked, or perhaps reset the Triplet if it is ticked, that way I can use the same macro for any value and just add in a 'tick the triplet' line in there when I need it.

          I suppose basically I need a command to reset all the value to a default value before selecting

          1. This script should do it in the fewest possible steps:

            
            function selectGrid({ value, dotted, triplet }) {
                var eventOpsWin = sf.ui.proTools.windows.whoseTitle.is('Event Operations').first;
            
                var gridButton = eventOpsWin.popupButtons.whoseTitle.is('Combined Quantize').first;
                var gridValue = gridButton.value.invalidate().value;
                var gridNoteValueMatch = gridValue.match(/(dotted )?(1\/\d+) note( triplet)?/);
                var gridNoteValue = gridNoteValueMatch && gridNoteValueMatch[2];
            
                if (gridNoteValue !== value) {
                    gridButton.popupMenuSelect({ menuPath: [value + ' note'] });
                }
            
                if (!dotted && !triplet) {
                    if (gridValue.indexOf("triplet") >= 0) {
                        gridButton.popupMenuSelect({ menuPath: ['triplet'] });
                    } else if (gridValue.indexOf("dotted") >= 0) {
                        gridButton.popupMenuSelect({ menuPath: ['dotted'] });
                    }
                } else {
                    if (triplet && (gridValue.indexOf("triplet") < 0)) {
                        gridButton.popupMenuSelect({ menuPath: ['triplet'] });
                    } else if (dotted && (gridValue.indexOf("dotted") < 0)) {
                        gridButton.popupMenuSelect({ menuPath: ['dotted'] });
                    }
                }
            
            }
            
            selectGrid({
                value: '1/2', dotted: true, triplet: false
            });
            
            ReplySolution
            1. SSimon Franglen @Simon_Franglen
                2020-03-20 14:31:35.158Z

                Perfect

                1. In reply tochrscheuer:
                  JJuan B Caballero @Juan_B_Caballero
                    2020-12-10 18:13:45.358Z

                    Hi! I'm running this script with the Quantize window open and the only parameter that is set is 1/2 grid. All other parameters remain in the same state there were before running the script.
                    Is there any programmed command that allowed me to set quantize in a specific grid value, specific triplet or not triplet mode, specific swing value, etc... ? I found something like this for Set Grid and Nudge parameters.
                    With quantize, all the scripts I found worked as a toggle parameter so the final setting depended on the initial state of the parameter.
                    Thaks!!

                    1. Hi Juan B,

                      I think it's better that you open a new question for the specific use cases you have – it's easier for us to manage which questions need attention that way, so your questions don't get lost in old threads that are already marked as solved.
                      Commenting on multiple old questions adds more noise than necessary :)

                      1. JJuan B Caballero @Juan_B_Caballero
                          2020-12-11 22:36:05.263Z

                          OK, you are right. It happened that I tried the solution that is in this thread and it doesn't work to me, so maybe I'm doing something wrong. Anyway, I made a new question asking for quantize commands or templates.

                          1. Thank you :)