Skip to main content
Inspiring
September 10, 2018
Question

Immediately apply changes to AE from a plugin

  • September 10, 2018
  • 1 reply
  • 630 views

Hello,

This is probably going to be difficult to explain, but here it goes.

I'm working on a plugin that has it's own UI. I want this UI to be open by a button, stay open and not block any functionality of After Effects. Then, I want to make changes to AE using my plugin's UI. Seems simple enough but...

There are a lot of ways to create a non blocking UI, and I decided to do it from the GeneralCallback. This was due to the fact that I need the AeData *aeData in order to make changes to the layer my plugin is working on. I make sure the GenericCallback is called from the IdleHook by using the following code:

A_Time currentTime;

suites.LayerSuite6()->AEGP_GetLayerCurrentTime(activeLayer, AEGP_LTimeMode_LayerTime, &currentTime);

suites.EffectSuite3()->AEGP_EffectCallGeneric(gpid, effectRef, &currentTime, PF_Cmd_COMPLETELY_GENERAL, nullptr);

The problem is that by using this method, changes made by my plugin are only applied when the IdleHook function is called (and consequently GeneralCallback), and this creates a bit of a lag between the the time I change something in the UI and the time it actually get changed in After Effects.

My plugin supports events, and I can immediately call a function upon change, but this way I can't actually make any changes to AE because I have no access to a AeData *aeData. Any other methods to change AE simply got discarded probably due to the fact that AE now has different threads for render and UI and those are synchronized periodically and not on demand.

So basically, using IdleHook I cannot make changes on demand, where should I create my UI, so I could apply these changes immediately after I change them, much like if an AE parameter it was?

This topic has been closed for replies.

1 reply

Community Expert
September 10, 2018

the way i see it, you have 2 options:

1. AEGP_CauseIdleRoutinesToBeCalled(). it can be called from the non-main

thread (as long as you acquire it from the main thread), and causes idle

hook to be called ASAP. this can shorten your interactive time lag.

2. create your window as an AE panel (see the "panelator" sample project).

i think panels can interact with AE's API during mouse

down/click/draw/ect...

octaviosaAuthor
Inspiring
September 12, 2018

Thanks for the quick response Shachar.

The AE panel is not an option for me, my UI is very complex and cannot be implemented this way.

I tried the AEGP_CauseIdleRoutinesToBeCalled(), and it looks like it didn't make any difference. I timed the execution between the call to this function and the actual apply of the changes, and sometimes it took more than a second. I was expecting times less than 10ms so the user didn't notice the lag.

I think I'm not understanding how the threads are working in AE. I know there is a main thread and the render thread. A quick check in Visual Studio revealed that my UI is running on the main thread, same goes for the IdleHook function and the GenericCallback function, so why can't I change stream values from my UI and have to do it in the IdleHook?

Community Expert
September 12, 2018

you DO understand the threads correctly. however, over 1 second for idle

hook to be called is very long and highly suspicious. on my implementations

idle hook is called bout 8-15 times per second.

the idle hook functions has a "A_long *max_sleepPL" param. the comments on

the header say:

A_long max_sleepPL); / <> in 1/60 of a second*/

try setting it to *max_sleepP=1 or *max_sleepP=2. perhap[s this will hasten

the idle hook calls.