No internet connection
  1. Home
  2. Packages
  3. Kitch's Command Template Collection

Hey Kitch, how about Input Quantize...

By marcello azevedo @marcello_azevedo
    2023-12-28 23:25:35.323Z2023-12-29 18:23:42.666Z

    On earlier 2023 versions of PT I had the below script working perfectly but since 2023.12 it doesn't work anymore.
    It would be great if you added that to your package.
    Can you take a look at my script for me please?

    sf.ui.proTools.appActivate();
    
    const win = sf.ui.proTools.windows.whoseTitle.is('Event Operations').first;
    
    sf.ui.proTools.menuClick({
        menuPath: ['Event', 'Event Operations', 'Input Quantize...'],
    });
    
    win.checkBoxes.whoseTitle.is('Note On').first.checkboxSet({
        targetValue: "Enable",
    });
    
    win.checkBoxes.whoseTitle.is('Note Off').first.checkboxSet({
        targetValue: "Enable",
    });
    
    win.checkBoxes.whoseTitle.is('Tuplet:').first.checkboxSet({
        targetValue: "Disable",
    });
    
    win.popupButtons.whoseTitle.is('Combined Quantize').first.popupMenuSelect({
        menuPath: ["1/8 note"],
    });
    
    win.getElement('AXCloseButton').elementClick();
    
    win.elementWaitFor({waitType:'Disappear'});
    
    • 6 replies
    1. S
      SoundFlow Bot @soundflowbot
        2023-12-28 23:25:37.770Z

        Thanks for posting a question or an issue related to the 'Kitch's Command Template Collection' package.
        This package is made by @Kitch. We're auto-tagging them here so that they will hopefully be able to help you.

        Please note, that the best way to get help with a script, macro or other content installed from the Store is to select the script you installed, then click the red Need help button, and then click "Get help with this script or macro".
        By using this workflow, the developer of the package will get access to more information so they'll be able to help you quicker.
        You can read more about how to best get help in this article: bit.ly/sfscripthelp

        1. Kitch Membery @Kitch2023-12-29 18:27:57.026Z

          Hi @marcello_azevedo,

          Ahh yes they made some drastic changes to the Event Operations window in recent versions of Pro Tools.

          I have a bunch on my plate right now but as soon as I find a moment I'll see if I can add it to the package. :-)

          Rock on!

          1. Nathan Salefski @nathansalefski
              2023-12-29 20:00:17.788Z

              @marcello_azevedo it appears that this window no longer has a title. This should fix your issue in the mean time while we wait for the wizard. You should also be able to change the note value by replacing the string in line 45

              function quantizeMIDI(value) {
              
                  const win = sf.ui.proTools.windows.first
                  // No longer has title
              
                  sf.ui.proTools.menuClick({
                      menuPath: ['Event', 'Event Operations', 'Input Quantize...'],
                  });
              
                  win.elementWaitFor();
              
                  let inputQuantizeCollapserButtonCollapsed = win.buttons.whoseTitle.is('Collapser button: Collapsed - Input Quantize').first
              
                  if (inputQuantizeCollapserButtonCollapsed.exists) {
                      inputQuantizeCollapserButtonCollapsed.elementClick();
                  }
              
                  sf.ui.proTools.windows.first.checkBoxes.whoseTitle.is('Enable').allItems[1].checkboxSet({
                      targetValue: 'Enable',
                  })
              
                  win.checkBoxes.whoseTitle.is('Note On').first.checkboxSet({
                      targetValue: 'Enable',
                  });
              
                  win.checkBoxes.whoseTitle.is('Note Off').first.checkboxSet({
                      targetValue: 'Enable',
                  });
              
                  win.checkBoxes.whoseTitle.is('Tuplet:').first.checkboxSet({
                      targetValue: 'Disable',
                  });
              
                  win.popupButtons.whoseTitle.is('Combined Quantize').first.popupMenuSelect({
                      menuPath: [value],
                  });
              
                  win.getElement('AXCloseButton').elementClick();
              }
              
              function main() {
                  sf.ui.proTools.appActivateMainWindow();
                  sf.ui.proTools.mainWindow.invalidate();
              
                  quantizeMIDI('1/8 note');
              }
              
              main();
              
            • Kitch Membery @Kitch2023-12-29 20:39:29.265Z

              Hi @marcello_azevedo,

              Converting this into a solid Command Template could take a while, but this script should do the trick for now. :-)

              function ensurePanelState(name, shouldBeOpen) {
                  const eventOperationsWindow = sf.ui.proTools.windows.first;
                  let panelExpanderButton;
              
                  if (shouldBeOpen) {
                      panelExpanderButton = eventOperationsWindow.buttons.whoseTitle.is(`Collapser button: Collapsed - ${name}`).first;
                  } else {
                      panelExpanderButton = eventOperationsWindow.buttons.whoseTitle.is(`Collapser button: Expanded - ${name}`).first;
                  }
              
                  if (panelExpanderButton.exists) {
                      panelExpanderButton.elementClick();
                  }
              }
              
              function setNoteTypeAndValue({ targetNoteValue, targetNoteType }) {
                  sf.ui.proTools.appActivateMainWindow();
              
                  // Set Target Note and Type values
                  if (targetNoteValue || targetNoteType) {
                      let combinedQuantizePopup = sf.ui.proTools.windows.first.popupButtons.getByTitle("Combined Quantize");
              
                      let currentNoteValue = combinedQuantizePopup.value.invalidate().value.replace(/dotted|triplet/g, "").trim()
                      let currentNoteType = combinedQuantizePopup.value.invalidate().value.includes("dotted") ? "dotted"
                          : combinedQuantizePopup.value.invalidate().value.includes("triplet") ? "triplet" : "standard";
              
                      // Set Note Value
                      if (currentNoteValue !== targetNoteValue)
                          combinedQuantizePopup.popupMenuSelect({ menuPath: [targetNoteValue], });
              
                      // set Note Type
                      if (targetNoteType === "dotted" && currentNoteType !== "dotted") {
              
                          combinedQuantizePopup.popupMenuSelect({ menuPath: ["dotted"], });
              
                      } else if (targetNoteType === "triplet" && currentNoteType !== "triplet") {
              
                          combinedQuantizePopup.popupMenuSelect({ menuPath: ["triplet"], });
              
                      } else if (targetNoteType === "standard") {
                          if (currentNoteType === "dotted")
                              combinedQuantizePopup.popupMenuSelect({ menuPath: ["dotted"], });
                          else if (currentNoteType === "triplet")
                              combinedQuantizePopup.popupMenuSelect({ menuPath: ["triplet"], });
                      }
                  }
              }
              
              function main() {
                  sf.ui.proTools.appActivate();
                  sf.ui.proTools.invalidate();
              
                  let isEventWindowOpen = false;
              
                  // Ensure the Event Operations Window is open.
                  if (!sf.ui.proTools.windows.first.children.whoseRole.is("AXStaticText").whoseValue.is("Input Quantize").first.exists) {
                      sf.ui.proTools.menuClick({ menuPath: ['Event', 'Event Operations', 'Input Quantize...'], });
                      sf.ui.proTools.windows.first.children.whoseRole.is("AXStaticText").whoseValue.is("Input Quantize").first.elementWaitFor();
                  } else {
                      isEventWindowOpen = true;
                  }
              
                  const win = sf.ui.proTools.windows.first;
              
                  // Ensure the "Input Quantize" Panel is open
                  ensurePanelState("Input Quantize", true);
              
                  // The "Quantize" Panel Needs to be closed as it contains similar params as the "Input Quantize" panel
                  ensurePanelState("Quantize", false);
              
                  try {
                      // Enable the "Input Quantize" Enable Checkbox.
                      const inputQuantizeEnableCheckbox = win.checkBoxes.whoseTitle.is("Enable").allItems[1];
              
                      // Change the targetValue to "Toggle" if you want to Toggle the "Input Quantize" Enable Checkbox.
                      inputQuantizeEnableCheckbox.checkboxSet({ targetValue: "Enable", });
              
                      // Enable "Note On" Checkbox
                      win.checkBoxes.whoseTitle.is('Note On').first.checkboxSet({ targetValue: "Enable", });
              
                      // Enable "Note Off" Checkbox
                      win.checkBoxes.whoseTitle.is('Note Off').first.checkboxSet({ targetValue: "Enable", });
                      
                      // Disable "Tuplet" Checkbox
                      win.checkBoxes.whoseTitle.is('Tuplet:').first.checkboxSet({ targetValue: "Disable", });
              
                      // Set Quantize Grid's "Combined Quantize" popup.
                      if (win.popupButtons.whoseTitle.is('Combined Quantize').first.value.value !== "1/8 note") {
                          setNoteTypeAndValue({
                              targetNoteValue: "1/8 note",
                              targetNoteType: "standard"
                          });
                      }
              
                  } catch (err) {
                      // Add error handling here if needed.
                  } finally {
                      if (!isEventWindowOpen) {
                          win.windowClose();
                      }
                  }
              }
              
              main();
              
              1. marcello azevedo @marcello_azevedo
                  2023-12-29 23:35:02.065Z

                  Working perfectly Kitch
                  You're amazing!
                  Thank you!!!!!

                  1. Kitch Membery @Kitch2023-12-29 23:36:16.888Z

                    Rock on @marcello_azevedo,
                    Enjoy what's left of the year, legend!