Wait For Key Press?
Hello, I am putting together a Macro for EQ matching. I was wondering if there is a way to make the script wait for key presses (ie: space bar for play, space bar again for stop) to have the plugin i'm using listen for the match, then have SF finish the script.
Thank you!
- Kitch Membery @Kitch2021-09-16 01:10:12.588Z
Hi @Blake_Bunzel,
Welcome to the forum :-)
Can you describe the manual steps you would take to achieve what you are after?
Generally, writing scripts that wait for user input, quickly becomes very advanced and/or unstable.
But by rethinking the workflow so that the script does the work for you, may be a better approach.:-)
- BBlake Bunzel @Blake_Bunzel
Hey Kitch!
I have a script that utilizes Fab Filter's Pro Q 3 which a bunch of Mouse Click Relative to UI. It's currently split up into 2 macros:
Macro 1. Sets the plugin to it's default state. Clicks through Pro Q3's menu items at the bottom to tell the plugin to listen to the sidechain. I then run program (hit space bar) to have the plugin listen to the side chain and adjust it's EQ curce. Once that is in the plugin, I will hit stop (space) bar.
Macro 2. I then hit "Match", then "Finish", then click the gain scale a the bottom right, enter 30 to draw back from 100% to 30%.Essentially the only break between Macro 1 and Macro 2 is having to hit space bar to run program and again to stop program. I figure, if the script waits for these 2 space bar hits, it would then allow me to combine the Macros to one.
Kitch Membery @Kitch2021-09-16 03:07:30.559Z
Ahh I see...
You could use the following code to wait for Pro Tools to stop playing;
Found in @samuel_henriques post Wait for Pro Tools to stop playing or recording (is it the same?) #post-2 ;
while (true) { if (sf.ui.proTools.isPlaying) { sf.wait() log("is playing") } else { log("stoped") break; } }
Or you could use a more in-depth way that checks if Pro Tools is playing every 100 milliseconds while letting you know how to cancel the script while Pro Tools is playing.
let currentTime = Date.now(); let getTime = () => Date.now(); let count = 0 log("Is playing: To cancel script press Ctrl+Shift+Esc"); while (sf.ui.proTools.isPlaying) { if (count < 0 || getTime() > currentTime + 5300) { log("Is playing: To cancel script press Ctrl+Shift+Esc"); currentTime = Date.now(); } sf.wait({ intervalMs: 100 }); count++ } log("Stoped");
Simply add code to press play at the end of your first script and them place one of the above scripts between your first and second script. :-)
Let me know if that makes sense, or if you need further explanation.
Rock on!
- BBlake Bunzel @Blake_Bunzel
Following back up here to report that the 2nd script worked perfectly!! Thank you Kitch! LOVING SF
Kitch Membery @Kitch2021-09-16 19:17:33.743Z
Fantastic:. Rock on!
- In reply toKitch⬆:
Chris Shaw @Chris_Shaw2021-09-16 22:05:05.964Z
@Kitch Out of curiosity, what is
count
doing? In the while loop the script is checking if count is less than zero OR if 5300ms has passed (to keep the notification persistent).count
is never less than zero, so what is it for?Chris Shaw @Chris_Shaw2021-09-16 22:06:44.739Z
It seems to run fine without the
count
variable.- In reply toChris_Shaw⬆:
Kitch Membery @Kitch2021-09-16 22:08:20.949Z
Hi @Chris.
With out the
count
, the first time the script runs the log will only appear after5300
milliseconds. the count is to make sure the log displays instantly the first time :-)Rock on!
- In reply toChris_Shaw⬆:
Kitch Membery @Kitch2021-09-16 22:35:56.343Z
I take that back... You are right, thanks for picking it up. I put the count there before I moved the 100ms wait to the end of the while loop. Great catch. :-)
New version;
let currentTime = Date.now(); let getTime = () => Date.now(); log("Is playing: To cancel script press Ctrl+Shift+Esc"); while (sf.ui.proTools.isPlaying) { if (getTime() > currentTime + 5300) { log("Is playing: To cancel script press Ctrl+Shift+Esc"); currentTime = Date.now(); } sf.wait({ intervalMs: 100 }); } log("Stoped");
@Blake_Bunzel here is an updated version. :-)
Rock on!
Chris Shaw @Chris_Shaw2021-09-16 23:09:38.427Z
Aah, I get it.
In the old version the if statement should have checked ifcount == 0
instead ofcount < 0
. The new version is more concise. 👍Kitch Membery @Kitch2021-09-16 23:11:47.517Z
Refactor, repeat, Story of my life! :-)
Chris Shaw @Chris_Shaw2021-09-17 00:36:28.868Z
Mine as well…🤦♂️
Kitch Membery @Kitch2021-09-17 00:47:06.170Z
Hahahaha :-)
- BIn reply toBlake_Bunzel⬆:Blake Bunzel @Blake_Bunzel
Thank you Kitch!! I'll give this a try and will circle back if I have any questions
- AIn reply toBlake_Bunzel⬆:Alexander Gruzdev @Alexander_Gruzdev
Hello Blake,
Would you be so kind to share your script for Fabfilter Q3 eq match process.
Appreciate any response. thank you.
AG