I want to fire a macro every time any track is selected... is there a way to do this?
I want to fire "open track output" which will focus my channel on the icon... thus getting a "focus fader follows track selection" functionality that is lacking on my D-Control.
Linked from:
- How do you prevent multiple instances of the same run forever scripts from running?
- Unexpected behaviour of globalState
- rx 10 editor supress all warnings on send to rx
- Background function stops working when other scripts are called. (Display different deck on Stream deck by changing the preview mode).
- Track Active Time in Pro Tools (Time Tracker)
- Christian Scheuer @chrscheuer2019-09-13 20:29:48.549Z
Hi @Steve_Giammaria.
You could use a script like this do perform something like it (it may give you some errors here and there but it should work)...
var lastFocusedTrackName; function main() { var newName = sf.ui.proTools.selectedTrackNames[0]; if (newName === lastFocusedTrackName) return; lastFocusedTrackName = newName; sf.ui.proTools.selectedTrack.trackOutputToggleShow(); } function runForever(name, action, interval, timeout) { var now = (new Date).valueOf(); if (now - globalState[name] < timeout) throw 0; //Exit if we were invoked again inside the timeout globalState[name] = now; sf.engine.runInBackground(function () { try { while (true) { sf.engine.checkForCancellation(); globalState[name] = (new Date).valueOf(); action(); sf.wait({ intervalMs: interval, executionMode: 'Background' }); } } finally { globalState[name] = null; } }); } runForever("isFollowFocusedTrackRunning", main, 500, 5000);
Assign an Application Trigger on Pro Tools being activated, and it should make sure to always be running when Pro Tools is.
Christian Scheuer @chrscheuer2019-09-13 20:30:57.576Z
You can stop the script (it continues to run in the background) by pressing Ctrl+Shift+Escape if you have default SF triggers enabled in your profile.
- SIn reply toSteve_Giammaria⬆:Steve Giammaria @Steve_Giammaria
Ah thanks!
this is so close to perfect.
it errors and stops when no track is selected.
I'm very green when it comes to coding, but
what does sf.ui.proTools.selectedTrackNames[0] return when no track is selected?we need somthing like:
if newName != NOTHING lastFocusedTrackName = newName;
- SSteve Giammaria @Steve_Giammaria
or something like:
if (newName === "") return;- SSteve Giammaria @Steve_Giammaria
figured it out.... I'm learning haha...
needs:
if (newName === undefined) return;
to avoid it dumping out if no track is selected!
Christian Scheuer @chrscheuer2019-09-17 14:45:18.378Z
Great find, @Steve_Giammaria!
A complete script that works could look like this then:
var lastFocusedTrackName; function main() { var newName = sf.ui.proTools.selectedTrackNames[0]; if (newName === lastFocusedTrackName || newName === undefined) return; lastFocusedTrackName = newName; sf.ui.proTools.selectedTrack.trackOutputToggleShow(); } function runForever(name, action, interval, timeout) { var now = (new Date).valueOf(); if (now - globalState[name] < timeout) throw 0; //Exit if we were invoked again inside the timeout globalState[name] = now; sf.engine.runInBackground(function () { try { while (true) { sf.engine.checkForCancellation(); globalState[name] = (new Date).valueOf(); action(); sf.wait({ intervalMs: interval, executionMode: 'Background' }); } } finally { globalState[name] = null; } }); } runForever("isFollowFocusedTrackRunning", main, 500, 5000);
- SSteve Giammaria @Steve_Giammaria
Oooh that's cleaner than I was doing. thanks!
- In reply tochrscheuer⬆:Aalex alcanjim @alex_alcanjim
Hi @chrscheuer!
I'm trying to use this script and something is going wrong when i don't have any track selected. SF pops an error that say "Object reference not set to an instance of an object"
That occurs when I click maybe between two tracks and then no track appear as selected. The thing is that, when this error pops up, I have to re-launch the script for use it, because it doesn't recover by itself.
Is there any way to make this script to ignore any "non selected track" situation?
Thanks so much in advance!
- In reply toSteve_Giammaria⬆:Fokke van Saane @Fokke
Ah, that is interesting, that you can use Selecting a track as trigger. Or, is it running all the time?
Christian Scheuer @chrscheuer2019-09-29 19:37:38.114Z
In essence it's accomplishing #1 by doing #2. The specific action modes we're using here ensure that it's running in Background mode though, which means it's not taking up space from other SF commands running. And you can configure the interval for how often you want it to query PT to see if anything has changed.
Note you can use this method (scripts running in the background repeatedly checking things) to do all sorts of interesting things :)
Fokke van Saane @Fokke
Isn't that taking up system resources by constantly checking things?
Christian Scheuer @chrscheuer2019-09-29 19:43:39.327Z
Depends on what you do in your loop :) The above script doesn't incur any noticeable performance penalty in my setup. If you asked it to compute a million decimals of PI every 200 ms you could make SoundFlow go to 100% on one core. So of course it should be designed intelligently whatever you set up that way.
Christian Scheuer @chrscheuer2019-09-29 19:44:57.776Z
Remember many things are constantly running on a computer, or run in the same way as here. The audio thread in a DAW being one example. If code is designed well you can have it running a crazy amount of things and the CPU usage would be barely noticeable.