Macro Request: Logic Pro: Set negative delay of selected track?

For new created tracks in Logic, very often I find myself having to set negative-delay values for the track. There are several common ones I keep on having to input based on certain sample libraries I use: -60ms, -100ms, -222ms, -333ms.

Any thoughts on a macro that can assign such a negative delay to a selected track when the macro is executed? Either one of the above as an example, or a quick way to prompt it in.

If it helps, I typically have the inspector CLOSED in the main tracks window on my main display, but I have it open on a second tracks window on a second display. However, the ‘Track’ option dropdown where the negative delay is typically set, I ‘usually’ have closed.

How about something like this?

Track Delay.kmmacros (132 KB)

Macro screenshot

Super great start! Not fully working for me yet, but we can likely get it there.

When I run the macro, I get the excellent pop-up with the delay options. But for some reason after selecting one, I get the Logic error “Command not available because there is no plugin in that slot”.

Another important note is that I’m actually intending to set TRACK delay, not region delay.

Again, if it adds anything, my inspector pane is open on a second display, though the windows should all be visible for found image actions. Alternatively, wondering if they can be selected via apple script instead of found image / mouse moving if that would be cleaner?

Okay, let's try AppleScript. For testing, please simplify your screenset by closing any windows on your second display. Let's see if we can get it working in a single - Tracks window, first of all.

Track Delay.kmmacros (49 KB)

Macro screenshot

One thing to bear in mind is that it will fail if you have a movie imported, as it will change the inspector layout. Let me know if that's the case and I can add a contingency for that. Oh, and I haven't added in the mouse recall yet. If you want that now you can copy the first and last actions across from the first macro.

Thanks! Testing this one now in a single tracks window on my main display. I’ve popped open the inspector panel. When I run the macro, I successfully get the pop-up asking for delay options. However, when I select an option, the GROUPS window in the inspector is what opens up (“Track” is the drop-down right below). After the Groups window opens, nothing happens.

In my case, I was able tix this by changing the “Open Track Pane” script to the following:

click UI element 1 of group 3 of list 1 of group 2 of window tracks_window

… though the macro still ends after the window opens, perhaps now because the subsequent scripts need to be updated for the UI?

Ah… I suspect this will likely be the case as I often work with video files. Good catch.

Try this version. It works for me whether a movie exists or not.

Track Delay (account for movie).kmmacros (55 KB)

Macro screenshot

If it doesn't work for you, first disable the Combined Script group and enable the Separate Scripts and test that. If it still doesn't work, send me the AppleScript output from the UI Browser Lite macro while hovering over the Delay field. That should hopefully show me any discrepancies between our screensets.

Thanks! In both the combined and separate scripts groups, I’m still getting the issue where it opens the “Groups” pane instead of the “Track” one.

click slider 1 of row 13 of table 1 of scroll area 1 of group 3 of list 1 of group 2 of window "Untitled 29 - Tracks"

I'm hoping I've cracked it. Track: is always the penultimate group, so we can count the total number of groups in the inspector and use the second-to-last one. That way, regardless of whether the Movie or Group Inspector panes exist, we should still be able to target the Track group...

Track Delay.kmmacros (50 KB)

Macro screenshot

Assuming we're in business, here's a bonus tip:

Change the text in the prompt action to something like:

0__Reset
-60__Piano
-100__Bass
-222__Drums
-333__Strings

Whatever you add after a __ will appear visually in the prompt, so that you don't have to remember which delay time corresponds to which library.

Nailed it! It’s working on my end!

Next step is… any thoughts on how to get this to apply to my “Track” pane that’s open on my second display, instead of my primary (which usually has the inspector closed)? Is it as simple as just changing the UI elements in the script a bit?

If so, here’s what I get:

activate application "Logic Pro"
tell application "System Events"
tell process "Logic Pro"
click slider 1 of row 13 of table 1 of scroll area 1 of group 3 of list 1 of group 1 of window "Untitled 29 - Tracks"
end tell
end tell

Looks like the last Group 2 changes to Group 1.

… Reading your Apple Script, though, I suspect it might be a bit more complicated! Or maybe just a matter of targeting the SECOND window whose title contains “ - Tracks”?

Yeah but the trouble is, what if you are working in that window? Then it's not the second window any more.

Presumably, you'll be working in the correct window at the time you want to run the script...? If not, can you explain your workflow?

My primary window is really just the tracks area and what I am mostly in for sequencing purposes. Second main window is for all my parameters – I’ve got the library open, inspector pane open, and mix window open there.

All that said, I did test the macro with my setup and, so long as indeed the second window is at least selected, it works perfectly. I usually am creating new tracks via the second window (hence the open library) so I figure it’ll get selected that way already, so we might be good to go. If not (and this is pending me doing some real testing with it) I guess it may just need an action to quickly select that second window (which i imagine is fairly easy, either a quick click-action or something similar)

1 Like

Run this while the window you want to run the macro on is front-most and tell me what number is returned.

Screen Test.kmmacros (20 KB)

Macro screenshot

Result: 4

Ok I might need a bit of help here...

@Nige_S, my brain isn't braining...

We need to determine the index of the front app's window which:

  • contains the string '- Tracks' and
  • is on the screen whose index is 4.

I know we could loop through windows until the conditions are both satisfied, but we don't want to switch to it; that would be too easy! We want to determine it for use in an AppleScript.

I'm not great with screen functions...

:melting_face:

Off the top of my head...

  1. Get the rectangle of screen index 4
  2. Get the list of window names with %WindowName%All% -- one name per line, in index order
  3. Get the list of window positions with `%WindowPosition%All% -- one top-left corner per line, in (same) index order
  4. For Each: Local_i in range from 1 to count of lines in Local_windowNames
    1. If line Local_i of Local_windowNames contains "- Tracks" AND line Local_i of Local_windowPositions is within the bounds of screen 4's rectangle
      1. Set Local_foundIndex to Local_i
      2. Exit For Each

So Local_i will be the index of the frontmost window that matches your criteria.

You can do the "within bounds of screen" bit with

if windowX >= screen4Left AND windowX <=screen4Right AND windowY >= screen4Top AND windowY <= screen4Bottom

Or you could use the window mid-point, if that's how you want to decide which screen a window is on.

Does that give your brain a nudge? If not I'll do a proper demo tomorrow (later today!).

Oof!

Okay we've hit on something I haven't done before in KM: iterating through two synced lists via a line count... My brain has been nudged, but it's now rolled over and gone back to sleep!

This, from the outline above, would be my preferred method because while it is more complicated it only makes three API calls -- one to get the screen bounds, one to get all the window names, one to get all the window positions.

Index of Window with Properties.kmmacros (13.5 KB)

Image

The simpler method is to target each window in turn:

For Each: Local_i from 1 to WINDOWCOUNT()
   If %WindowName%Local_i% contains "- Title" AND WINDOW(Local_i, Left) >= SCREEN(4, Left) AND WINDOW(Local_i, Right) <= SCREEN(4, Right) AND...

...which involves many more API calls (obvs the SCREEN(4, ... ones could be done before the "For Each" and stored in variables, but that's still 4 API calls rather than 1).

Anyone playing along at home might like to give the "simpler" method a go, using the same logic for name and screen matching as the posted demo does.

1 Like

Nige, you're a clever fella!

Ok I can't test this as I'm at home with no second screen, but I think this should work:

Track Delay (Second Tracks Window on External Monitor).kmmacros (60 KB)

Macro screenshot

Given that all I know about KM has come from this Forum, it's the past and present clever people here that deserve any credit going.

I don't say it often enough -- but thank you everyone, both questioners and answerers, for your Forum participation over the years!

3 Likes