Stream Deck Control of Logic Pro Fades

Ah yes, that would be useful. That way when I set the Fade Length on the Stream Desk, I could send it to GainControl at the same time. In fact it wouldn't even need the KM variable as it could be set directly in GainControl.

For my purposes I wouldn't need separate fade lengths for all the different fade types, but I guess I would just sent all of them when you pressed the fade length button.

Is that screenshot the actual beta or something you mocked up to send the developer? Just curious why it lets you set fade lengths for EqP but not X?

It's a mockup and I didn't include X fades for two reasons:

  1. who uses them? EqP is the standard and accounts for phase issues.
  2. laziness on my part.

Ha ha, I agree that I use EqP in 99% of cases, but X is useful in a very specific scenario: when the two things you are cross-fading are highly in-phase.

For example, to stretch a bass guitar note (where it REALLY works well because the of the low frequencies), I chop the note part way through and move the end section later, making sure it lands perfectly in phase at the overlap. With an X fade, I can get a completely smooth lengthened note, better-sounding than any time stretching algorithm. If I used an EqP fade, the increase in volume at the fade would create a slight 'bump'.

1 Like

Welp. I just learned something!

1 Like

hi, thank you so much it works pretty nice
!

Hey @noisneil while we're here, I've got a problem with the AppleScript for my fades, and you might be the only person who knows enough about both AppleScript and Logic to help! Would you mind taking a look?

Since Logic 11 (maybe a bit before?) my fade macros sometimes fail with the message:

execution error: System Events got an error: Can’t set window "[Logic file name] - Tracks" of process "Logic Pro X" to 0. (-10006).

Do you have any idea what could be causing this? Here's the AppleScript for setting an equal power fade:

# get length of fade from Keyboard Maestro
tell application "Keyboard Maestro Engine"
	set _FadeLength to getvariable "FadeLength"
	set _FadeLength to _FadeLength as integer
end tell


set _GainRow to 9
set _FadeInRow to 12
set _FadeOutRow to 14
set _FadeTypeRow to 15
set _MoreRow to 10

tell application "Logic Pro X"
	activate
end tell

tell application "System Events"
	tell process "Logic Pro X"
		
		-- Check if control bar is present
		set _TracksWindow to title of first window whose title contains "- Tracks"
		if (description of group 1 of window _TracksWindow = "Control Bar") then
			set _GroupNumber to 2
		else
			set _GroupNumber to 1
		end if
		
		-- Check if Movie mini-window is present
		if (value of static text 1 of group 1 of list 1 of group _GroupNumber of window _TracksWindow is "Movie") then
			set _SubGroupNumber to 2
		else
			set _SubGroupNumber to 1
		end if
		
		-- Open the "Region" disclosure triangle, if it isn't already
		if value of UI element 2 of group _SubGroupNumber of list 1 of group _GroupNumber of window _TracksWindow is not equal to 1 then
			click UI element 1 of group _SubGroupNumber of list 1 of group _GroupNumber of window _TracksWindow
			delay 0.15
		end if
		
		-- Open the "More" disclosure triangle, if it isn't already
		if value of UI element 1 of group 1 of row _MoreRow of outline 1 of scroll area 1 of group _SubGroupNumber of list 1 of group _GroupNumber of window _TracksWindow is not equal to 1 then
			click UI element 1 of group 1 of row _MoreRow of outline 1 of scroll area 1 of group _SubGroupNumber of list 1 of group _GroupNumber of window _TracksWindow
		end if
		
		-- Set crossfade type to EqP, if it isn't already
		if value of pop up button 1 of row _FadeTypeRow of outline 1 of scroll area 1 of group _SubGroupNumber of list 1 of group _GroupNumber of window _TracksWindow is not "EqP" then
			click pop up button 1 of row _FadeTypeRow of outline 1 of scroll area 1 of group _SubGroupNumber of list 1 of group _GroupNumber of window _TracksWindow
			click menu item "EqP (Equal Power Crossfade)" of menu 1 of outline 1 of scroll area 1 of group _SubGroupNumber of list 1 of group _GroupNumber of window _TracksWindow
		end if
		
		-- Set fade length
		tell row _FadeOutRow of outline 1 of scroll area 1 of group _SubGroupNumber of list 1 of group _GroupNumber of window _TracksWindow
			set value of slider 1 to _FadeLength
		end tell
		
	end tell
end tell

Hmm... I can't see anything obviously wrong with your AppleScript. Essentially it does things the same way mine does. I wonder if it might be the occasional time you try to set a second fade value slightly before the first one has finished being set, as I described before. That's the only error I seem to run up against...

FWIW, this seems to be working fairly reliably, albeit very slowly when dealing with large numbers of regions:

AppleScript
set inst to system attribute "KMINSTANCE"
tell application "Keyboard Maestro Engine"
	set FadeLengthAS to (getvariable "Local__FadeLength" instance inst) as number
end tell
tell application "System Events"
	tell process "Logic Pro"
		set tracks_window to title of first window whose title contains "- Tracks"
		
		click pop up button 1 of row 15 of outline 1 of scroll area 1 of group 1 of list 1 of group 2 of window tracks_window
		--delay 0.05
		click menu item "Out" of menu 1 of pop up button 1 of row 15 of outline 1 of scroll area 1 of group 1 of list 1 of group 2 of window tracks_window
		--delay 0.05
		set value of slider 1 of row 14 of outline 1 of scroll area 1 of group 1 of list 1 of group 2 of window tracks_window to FadeLengthAS
		
		-- PAUSE UNTIL File > Close is enabled
		repeat with i from 1 to 20
			try
				if (enabled of menu item "Close" of menu "File" of menu bar item "File" of menu bar 1) then
					exit repeat
				end if
			on error
				-- If there's an error, keep waiting
			end try
			delay 0.5
		end repeat
		
		-- Set the value of the second slider
		repeat with i from 1 to 5
			try
				set value of slider 1 of row 12 of outline 1 of scroll area 1 of group 1 of list 1 of group 2 of window tracks_window to FadeLengthAS
				exit repeat
			on error
				delay 0.5
			end try
		end repeat
		
	end tell
end tell

Thanks @noisneil - I tried going through and comparing our AppleScripts and the only significant difference I could find (bearing in mind how rubbish I am at this!) was that you called the process "Logic Pro" and I called it "Logic Pro X", but this didn't seem to make much difference.

Are you sure the slow fades issue is related to your AppleScript? It seems to beachball and go slow for me with large numbers of fades even when I do it manually from the Inspector. I'm wondering if it's just a general Logic bug.

Anyway, I decided to try moving away from AppleScript and to use more of KM's own features to do this, and I think I've come up with a way that works well.

The macro attached to this post uses mouse clicks and keyboard presses to set an EqP fade, using a Found Image to set the mouse position. AppleScript is only used to open disclosure triangles on the Inspector when needed.

It might be marginally slower than pure AppleScript but it still does it in about half a second on my fairly old Intel i3. Note: it needs to see a KM integer variable called "FadeLength".

Fade EqP.kmmacros (99.8 KB)

I nearly replied this morning to say much the same thing. It still fails occasionally.

You're right. It's a Logic thing, which is what I was saying a few comments back. Apple really need to sort that out. GainControl has the same issues.

I've removed the In part of my EqP version, and so far it's not failing. That's fine for now.

Not sure why it took me so long to think of this, but if I set the fade length before the fade type, it seems to be way more reliable. YMMV

Doesn't seem to work for me unfortunately. I've got a feeling AppleScript solutions are only going to keep degrading over time as clearly it's not a technology Apple are interested in maintaining. Using Keyboard Maestro's Found Image technique seems to be working well for me.

At all, or are you simply finding it to be equally unreliable?

@peternlewis, is UI interaction via Swift something that might be possible with KM? It seems to be a great deal faster and more reliable in Logic Pro, if PlugSearch and GainControl are anything to go by.

Equally unreliable - the same lottery as to whether it works or I get an error message about not being able to set the Logic window.

I don't know what that means?

What “UI interaction via Swift”?

I'll be honest, I don't really either. I know that the developer of these apps switched from using AppleScript to Swift. Perhaps Swift is leveraging some other UI interaction method I'm not aware of.

There's a file called InvisibleWindowController.nib in the app's resources folder, so that must have something to do with it. :man_shrugging:t2:

I appreciate I've not given you much to go on, as I barely know what I'm talking about myself!