No internet connection
  1. Home
  2. How to

Wait for user input?

By Reid Caulfield @Reid_Caulfield
    2021-07-09 05:04:06.265Z

    Hello all. I'm new to Soundflow for Pro Tools and I'm still getting my head around it but it looks like it will be a monster for my workflow. My head is kind of exploding with potential workflow enhancements.

    In this workflow, it looks like I can automate everything I need to, but I have not been able to find how to do the following:

    (In Pro Tools) Press Keys Number Pad "*" (which allows for variable Timecode entry into the PT Transport TC window) - I can do this one, obviously. But then...

    I need Soundflow to wait for my specific 8 key TC location, after which I hit Num Pad Key "Enter"

    ...and then I would like Soundflow to continue onward with its routine after this point.

    In other words, I need to enter a specific number that will be different for each TV episode I'm working on, and I need to do this in the middle of a Soundflow Macro.

    Thoughts very much appreciated!

    Thanks so much!

    • 6 replies
    1. samuel henriques @samuel_henriques
        2021-07-09 18:47:29.988Z

        Hello Reid Caulfield, welcome to SoundFlow,

        try this,

        function waitForNewTc() {
        
            let currentStartTime = sf.ui.proTools.selectionGet().selectionStart
        
            while (true) {
        
                let newStartTime = sf.ui.proTools.selectionGet().selectionStart
        
                if (currentStartTime != newStartTime) {
                    break;
                } else {
                    sf.wait({ intervalMs: 200 })
                }
            }
        }
        
        
        
        waitForNewTc()
        

        If you are doing your workflow with macros, save this script on a new script, and call the script as an action on your macro.

        Let me know how it goes.

        1. In reply toReid_Caulfield:

          Hi Reid,

          Samuel provided a way to directly do what you're asking.

          I would consider instead doing:

          • Ask for user input first, ie. open a prompt to ask for the input (use the prompt('...') call to ask the user for the TC info and then save it to a variable)
          • Then, when you need to change the selection in your script, use the selectionSet action to make the selection change, using the variable from before to tell it where to go.

          This will be more stable, and furthermore has the benefit that once the user has entered their input, the rest of the macro can continue unsupervised. Generally, this is the best design approach.

          1. Here's an example:

            //First, ask the user for their input
            const timecode = prompt(`Please enter the timecode`);
            
            //Here, do something else...
            
            //Then, set the selection to what the user specified in the beginning
            sf.ui.proTools.selectionSetTimecode({
                selectionStart: timecode,
                selectionEnd: timecode,
            });
            
            
            1. RReid Caulfield @Reid_Caulfield
                2021-07-12 00:35:14.895Z

                Thank you Christian and Samuel! I implemented Samuel's script and have the macro working but when I try to incorporate the brilliant "Prompt" suggestion, it breaks the macro. I have no doubt that this is pilot error' and my own inexperience with Javascript but I really love the Prompt idea. Using Samuel's script, while there is no prompt, the user input does go straight into the Transport timecode window as desired. I then hit 'Enter" and the macro continues as planned. However I implement the Prompt, I get the Prompt window but the number I type in does not transfer to the Transport TC field.

                Thank you and thoughts welcome!

                1. I designed this to change the selection in the main counter, not the transport display - not sure if that's the confusion.

                  In which format do you enter the timecode? It would need to be formatted exactly like it is in your main counter display, for example 01:00:00:00

                  1. In reply toReid_Caulfield:
                    samuel henriques @samuel_henriques
                      2021-07-12 14:06:43.033Z

                      Hello @Reid_Caulfield,

                      I think Christian's proposal is better, for the reasons he stated. Thank you Christian.

                      Could you be trying to use both mine and Christian proposal? You can only choose one.

                      Just to check that, you converted your macro to javaScript and placed the code
                      to Christian's code after the line //Here, do something else... ?

                      If you want, I made a version that checks if time code is valid, and you can type 01020304 or 01:02:03:04 they will both work.Also it checks if the numbers you type are compatible with timecode format.
                      So it's the same way you would type on the main counter but, for example you copy from somewhere with the correct format 01:00:00:00 it works as well. But 11223344 or 112233 won't work. You then have a chance to re-type.

                      Still you need to place the converted macro to javaScript after the line //Here, do something else...

                      Let me now if you get stuck.

                      
                      
                      function userTimeCode() {
                          function checkTimeCodeValid(value) {
                              /////https://gist.github.com/allensarkisyan/5441601
                              // Assumes the frame rate is 23.98, 24, 25, 29.97 NDF, or 30
                              var isValidSMPTETimeCode = /(^(?:(?:[0-1][0-9]|[0-2][0-3]):)(?:[0-5][0-9]:){2}(?:[0-2][0-9])$)/;
                              if (!isValidSMPTETimeCode.test(value)) {
                                  alert("This Time Code is Not Valid!")
                                  return
                              } else {
                                  return value
                              };
                          };
                      
                          function stringToTc(string) {
                              let convert
                              if (string.indexOf(":") != -1) {
                                  convert = string
                              } else {
                                  convert = string.match(/.{1,2}/g).join(":");
                              };
                              return convert
                          };
                      
                      
                          let validTimeCode
                          while (true) {
                      
                              let promptString = prompt(`Please enter the timecode,\nwith or without colon (:)`);
                      
                              if (promptString === undefined) {
                      
                                  throw 'Prompt for timecode canceled.'
                      
                              } else if (promptString) {
                      
                                  validTimeCode = checkTimeCodeValid(stringToTc(promptString))
                      
                                  if (validTimeCode) {
                                      return validTimeCode
                                  };
                      
                              };
                          };
                      };
                      
                      //First, ask the user for their input and check if is valid
                      const timecode = userTimeCode()
                      
                      
                      
                      //Here, do something else...
                      
                      
                      
                      //Then, set the selection to what the user specified in the beginning
                      sf.ui.proTools.selectionSetTimecode({
                          selectionStart: timecode,
                          selectionEnd: timecode,
                      });