after-effects 0.4.0

High level bindings for the Adobe After Effects® SDK
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
use after_effects_sys::{
    AEGP_AboutRefcon, AEGP_AboutStringRefcon, AEGP_CommandRefcon, AEGP_DeathRefcon,
    AEGP_GlobalRefcon, AEGP_UpdateMenuRefcon, AEGP_VersionRefcon,
};

use crate::*;
use std::ffi::CString;

define_suite!(
    RegisterSuite,
    AEGP_RegisterSuite5,
    kAEGPRegisterSuite,
    kAEGPRegisterSuiteVersion5
);

define_enum! {
    ae_sys::AEGP_HookPriority,
    HookPriority {
        BeforeAE = ae_sys::AEGP_HP_BeforeAE,
        AfterAE = ae_sys::AEGP_HP_AfterAE,
    }
}

define_enum! {
    ae_sys::AEGP_WindowType,
    WindowType {
        None = ae_sys::AEGP_WindType_NONE,
        Project = ae_sys::AEGP_WindType_PROJECT,
        Comp = ae_sys::AEGP_WindType_COMP,
        TimeLayout = ae_sys::AEGP_WindType_TIME_LAYOUT,
        Layer = ae_sys::AEGP_WindType_LAYER,
        Footage = ae_sys::AEGP_WindType_FOOTAGE,
        RenderQueue = ae_sys::AEGP_WindType_RENDER_QUEUE,
        QuickTime = ae_sys::AEGP_WindType_QT,
        Dialog = ae_sys::AEGP_WindType_DIALOG,
        Flowchart = ae_sys::AEGP_WindType_FLOWCHART,
        Effect = ae_sys::AEGP_WindType_EFFECT,
        Other = ae_sys::AEGP_WindType_OTHER,
    }
}

#[derive(Debug, Clone)]
pub enum CommandHookStatus {
    Handled,
    Unhandled,
}

pub type UpdateMenuHook<G, R> =
    Box<dyn Fn(Option<&mut G>, &mut R, WindowType) -> Result<(), Error>>;

pub type CommandHook<G, R> = Box<
    dyn FnMut(
        Option<&mut G>,
        &mut R,
        ae_sys::AEGP_Command,
        HookPriority,
        bool,
    ) -> Result<CommandHookStatus, Error>,
>;

pub type DeathHook<G, R> = Box<dyn FnMut(Option<&mut G>, &mut R) -> Result<(), Error>>;

pub type VersionHook<G, R> = Box<dyn FnMut(Option<&mut G>, &mut R, &mut u32) -> Result<(), Error>>;

pub type AboutStringHook<G, R> =
    Box<dyn FnMut(Option<&mut G>, &mut R, &mut [u8]) -> Result<(), Error>>;

pub type AboutHook<G, R> = Box<dyn FnMut(Option<&mut G>, &mut R) -> Result<(), Error>>;

pub type IdleHook<G, R> = Box<dyn FnMut(Option<&mut G>, &mut R, &mut i32) -> Result<(), Error>>;

/// Note: functions in this suite take a `Global` Paramater, for AEGPs this must be the same as your global `AegpPlugin` type, for all
/// other plugins this should likely be the type you registered with the [UtilitySuite::register_aegp_plugin] function.
impl RegisterSuite {
    pub fn new() -> Result<Self, Error> { crate::Suite::new() }

    /// Register a hook (command handler) function with After Effects.
    /// If you are replacing a function which After Effects also handles, `AEGP_HookPriority` determines whether your plug-in gets run first.
    pub fn register_command_hook<Global: AegpSeal, RefCon>(
        &self,
        plugin_id: ae_sys::AEGP_PluginID,
        hook_priority: HookPriority,
        command: ae_sys::AEGP_Command,
        command_hook_func: CommandHook<Global, RefCon>,
        command_refcon: RefCon,
    ) -> Result<(), Error> {
        unsafe extern "C" fn command_hook_wrapper<P, T>(
            plugin_refcon: AEGP_GlobalRefcon,
            refcon: AEGP_CommandRefcon,
            command: ae_sys::AEGP_Command,
            hook_priority: ae_sys::AEGP_HookPriority,
            already_handled: ae_sys::A_Boolean,
            handled_p: *mut ae_sys::A_Boolean,
        ) -> ae_sys::A_Err {
            let global = if plugin_refcon.is_null() {
                None
            } else {
                Some(unsafe { &mut *(plugin_refcon as *mut P) })
            };

            let Some((callback, refcon)) = (unsafe { (refcon as *mut (CommandHook<P, T>, T)).as_mut() }) else {
                return Error::Generic.into();
            };

            let already_handled_bool = already_handled != 0;

            let hook_priority_enum = HookPriority::from(hook_priority);

            let res = callback(
                global,
                refcon,
                command,
                hook_priority_enum,
                already_handled_bool,
            );

            match res {
                Ok(CommandHookStatus::Handled) => {
                    unsafe { *handled_p = 1; }
                    Error::None
                }
                Ok(CommandHookStatus::Unhandled) => {
                    unsafe { *handled_p = 0; }
                    Error::None
                }
                Err(e) => {
                    unsafe { *handled_p = 0; }
                    e
                }
            }
            .into()
        }

        let refcon_cb_tuple = Box::new((command_hook_func, command_refcon));
        call_suite_fn!(
            self,
            AEGP_RegisterCommandHook,
            plugin_id,
            hook_priority.into(),
            command,
            Some(command_hook_wrapper::<Global, RefCon>),
            Box::into_raw(refcon_cb_tuple) as *mut _,
        )
    }

    /// Register your menu update function (which determines whether or not items are active),
    /// called every time any menu is to be drawn.
    pub fn register_update_menu_hook<Global: AegpSeal, UpdateMenuRefCon>(
        &self,
        plugin_id: ae_sys::AEGP_PluginID,
        update_menu_hook_func: UpdateMenuHook<Global, UpdateMenuRefCon>,
        update_menu_refcon: UpdateMenuRefCon,
    ) -> Result<(), Error> {
        unsafe extern "C" fn update_menu_hook_wrapper<P, T>(
            plugin_refcon: AEGP_GlobalRefcon,
            refcon: AEGP_UpdateMenuRefcon,
            window_type: ae_sys::AEGP_WindowType,
        ) -> sys::PF_Err {
            let global = if plugin_refcon.is_null() {
                None
            } else {
                Some(unsafe { &mut *(plugin_refcon as *mut P) })
            };

            let Some((callback, refcon)) = (unsafe { (refcon as *mut (UpdateMenuHook<P, T>, T)).as_mut() })
            else {
                return Error::Generic.into();
            };

            match callback(global, refcon, window_type.into()) {
                Ok(_) => Error::None,
                Err(e) => e.into(),
            }
            .into()
        }

        let refcon_cb_tuple = Box::new((update_menu_hook_func, update_menu_refcon));

        call_suite_fn!(
            self,
            AEGP_RegisterUpdateMenuHook,
            plugin_id,
            Some(update_menu_hook_wrapper::<Global, UpdateMenuRefCon>),
            Box::into_raw(refcon_cb_tuple) as *mut _,
        )
    }

    /// Register your termination function. Called when the application quits.
    pub fn register_death_hook<Global: AegpSeal, DeathRefcon>(
        &self,
        plugin_id: ae_sys::AEGP_PluginID,
        death_hook_func: DeathHook<Global, DeathRefcon>,
        death_refcon: DeathRefcon,
    ) -> Result<(), Error> {
        unsafe extern "C" fn death_hook_wrapper<P, T>(
            plugin_refcon: AEGP_GlobalRefcon,
            refcon: AEGP_DeathRefcon,
        ) -> sys::PF_Err {
            let global = if plugin_refcon.is_null() {
                None
            } else {
                Some(unsafe { &mut *(plugin_refcon as *mut P) })
            };

            let (cb, refcon) = unsafe { &mut *(refcon as *mut (DeathHook<P, T>, T)) };
            match cb(global, refcon) {
                Ok(_) => Error::None,
                Err(e) => e,
            }
            .into()
        }

        let refcon_cb_tuple = Box::new((death_hook_func, death_refcon));
        call_suite_fn!(
            self,
            AEGP_RegisterDeathHook,
            plugin_id,
            Some(death_hook_wrapper::<Global, DeathRefcon>),
            Box::into_raw(refcon_cb_tuple) as *mut _,
        )
    }

    /// Currently not called.
    pub fn register_version_hook<Global: AegpSeal, VersionRefCon>(
        &self,
        plugin_id: ae_sys::AEGP_PluginID,
        version_hook_func: VersionHook<Global, VersionRefCon>,
        version_refcon: VersionRefCon,
    ) -> Result<(), Error> {
        unsafe extern "C" fn version_hook_wrapper<P, T>(
            plugin_refcon: AEGP_GlobalRefcon,
            refcon: AEGP_VersionRefcon,
            pf_version_p: *mut ae_sys::A_u_long,
        ) -> ae_sys::A_Err {
            log::error!(
                "The after effects documentation said version hook should never be called!"
            );
            let global = if plugin_refcon.is_null() {
                None
            } else {
                Some(unsafe { &mut *(plugin_refcon as *mut P) })
            };

            let (cb, refcon) = unsafe { &mut *(refcon as *mut (VersionHook<P, T>, T)) };
            let pf_version = unsafe { &mut (*pf_version_p as u32) };

            match cb(global, refcon, pf_version) {
                Ok(_) => Error::None,
                Err(e) => e,
            }
            .into()
        }

        log::warn!("Called `register_version_hook`, this does nothing!");

        let refcon_cb_tuple = Box::new((version_hook_func, version_refcon));
        call_suite_fn!(
            self,
            AEGP_RegisterVersionHook,
            plugin_id,
            Some(version_hook_wrapper::<Global, VersionRefCon>),
            Box::into_raw(refcon_cb_tuple) as *mut _,
        )
    }

    /// Currently not called.
    pub fn register_about_string_hook<Global: AegpSeal, AboutString>(
        &self,
        plugin_id: ae_sys::AEGP_PluginID,
        about_string_hook_func: AboutStringHook<Global, AboutString>,
        about_string_refcon: AboutString,
    ) -> Result<(), Error> {
        unsafe extern "C" fn about_string_hook_wrapper<P, T>(
            plugin_refcon: AEGP_GlobalRefcon,
            refcon: AEGP_AboutStringRefcon,
            // We have 0 documentation about this pointer
            // besides that it is never constructed, so it's treated as null
            _about_z: *mut ae_sys::A_char,
        ) -> ae_sys::A_Err {
            log::error!(
                "The after effects documentation said about string hook should never be called!"
            );
            let global = if plugin_refcon.is_null() {
                None
            } else {
                Some(unsafe { &mut *(plugin_refcon as *mut P) })
            };

            let (cb, refcon) = unsafe { &mut *(refcon as *mut (AboutStringHook<P, T>, T)) };

            match cb(global, refcon, &mut []) {
                Ok(_) => Error::None,
                Err(e) => e,
            }
            .into()
        }

        log::warn!("Called `register_about_string_hook`, this does nothing!");

        let refcon_cb_tuple = Box::new((about_string_hook_func, about_string_refcon));
        call_suite_fn!(
            self,
            AEGP_RegisterAboutStringHook,
            plugin_id,
            Some(about_string_hook_wrapper::<Global, AboutString>),
            Box::into_raw(refcon_cb_tuple) as *mut _,
        )
    }

    /// Currently not called.
    pub fn register_about_hook<Global: AegpSeal, About>(
        &self,
        plugin_id: ae_sys::AEGP_PluginID,
        about_hook_func: AboutHook<Global, About>,
        about_refcon: About,
    ) -> Result<(), Error> {
        unsafe extern "C" fn about_hook_wrapper<P, T>(
            plugin_refcon: AEGP_GlobalRefcon,
            refcon: AEGP_AboutRefcon,
        ) -> ae_sys::A_Err {
            log::error!("The after effects documentation said about hook should never be called!");
            let global = if plugin_refcon.is_null() {
                None
            } else {
                Some(unsafe { &mut *(plugin_refcon as *mut P) })
            };

            let (cb, refcon) = unsafe { &mut *(refcon as *mut (AboutHook<P, T>, T)) };

            match cb(global, refcon) {
                Ok(_) => Error::None,
                Err(e) => e,
            }
            .into()
        }

        log::warn!("Called `register_about_hook`, this does nothing!");

        let refcon_cb_tuple = Box::new((about_hook_func, about_refcon));
        call_suite_fn!(
            self,
            AEGP_RegisterAboutHook,
            plugin_id,
            Some(about_hook_wrapper::<Global, About>),
            Box::into_raw(refcon_cb_tuple) as *mut _,
        )
    }

    /// Register your IdleHook function. After Effects will call the function sporadically,
    /// while the user makes difficult artistic decisions (or while they're getting more coffee).
    pub fn register_idle_hook<Global: AegpSeal, IdleRefCon>(
        &self,
        plugin_id: ae_sys::AEGP_PluginID,
        idle_hook_func: IdleHook<Global, IdleRefCon>,
        idle_refcon: IdleRefCon,
    ) -> Result<(), Error> {
        unsafe extern "C" fn idle_hook_wrapper<P, T>(
            plugin_refcon: AEGP_GlobalRefcon,
            refcon: ae_sys::AEGP_IdleRefcon,
            max_sleep_p: *mut ae_sys::A_long,
        ) -> ae_sys::A_Err {
            let global = if plugin_refcon.is_null() {
                None
            } else {
                Some(unsafe { &mut *(plugin_refcon as *mut P) })
            };

            let (cb, refcon) = unsafe { &mut *(refcon as *mut (IdleHook<P, T>, T)) };
            let max_sleep = unsafe { &mut (*max_sleep_p) };

            match cb(global, refcon, max_sleep) {
                Ok(_) => Error::None,
                Err(e) => e,
            }
            .into()
        }

        let refcon_cb_tuple = Box::new((idle_hook_func, idle_refcon));
        call_suite_fn!(
            self,
            AEGP_RegisterIdleHook,
            plugin_id,
            Some(idle_hook_wrapper::<Global, IdleRefCon>),
            Box::into_raw(refcon_cb_tuple) as *mut _,
        )
    }

    /// Call this to register as many strings as you like for name-replacement when presets are loaded.
    /// Any time a Property name is found, or referred to in an expression, and it starts with an ASCII tab character ('t'),
    /// followed by one of the English names, it will be replaced with the localized name.
    /// (In English the tab character will simply be removed).
    pub fn register_preset_localization_string(
        &self,
        english_name: &str,
        localized_name: &str,
    ) -> Result<(), Error> {
        let english_name_c = CString::new(english_name).map_err(|_| Error::InvalidParms)?;
        let localized_name_c = CString::new(localized_name).map_err(|_| Error::InvalidParms)?;
        call_suite_fn!(
            self,
            AEGP_RegisterPresetLocalizationString,
            english_name_c.as_ptr(),
            localized_name_c.as_ptr()
        )
    }
}

pub type NonAegpUpdateMenuHook<R> = Box<dyn Fn(&mut R, WindowType) -> Result<(), Error>>;

pub type NonAegpCommandHook<R> = Box<
    dyn FnMut(&mut R, ae_sys::AEGP_Command, HookPriority, bool) -> Result<CommandHookStatus, Error>,
>;

pub type NonAegpDeathHook<R> = Box<dyn FnMut(&mut R) -> Result<(), Error>>;

pub type NonAegpVersionHook<R> = Box<dyn FnMut(&mut R, &mut u32) -> Result<(), Error>>;

pub type NonAegpAboutStringHook<R> = Box<dyn FnMut(&mut R, &mut [u8]) -> Result<(), Error>>;

pub type NonAegpAboutHook<R> = Box<dyn FnMut(&mut R) -> Result<(), Error>>;

pub type NonAegpIdleHook<R> = Box<dyn FnMut(&mut R, &mut i32) -> Result<(), Error>>;

define_suite!(
    RegisterNonAegpSuite,
    AEGP_RegisterSuite5,
    kAEGPRegisterSuite,
    kAEGPRegisterSuiteVersion5
);

/// Note: functions in this suite assume the plugin_refcon is always null.
/// This is appropriate for non-AEGP plugins.
impl RegisterNonAegpSuite {
    pub fn new() -> Result<Self, Error> { crate::Suite::new() }

    /// Register a hook (command handler) function with After Effects.
    /// If you are replacing a function which After Effects also handles, `AEGP_HookPriority` determines whether your plug-in gets run first.
    pub fn register_command_hook<RefCon>(
        &self,
        plugin_id: ae_sys::AEGP_PluginID,
        hook_priority: HookPriority,
        command: ae_sys::AEGP_Command,
        command_hook_func: NonAegpCommandHook<RefCon>,
        command_refcon: RefCon,
    ) -> Result<(), Error> {
        unsafe extern "C" fn command_hook_wrapper<T>(
            _: AEGP_GlobalRefcon,
            refcon: AEGP_CommandRefcon,
            command: ae_sys::AEGP_Command,
            hook_priority: ae_sys::AEGP_HookPriority,
            already_handled: ae_sys::A_Boolean,
            handled_p: *mut ae_sys::A_Boolean,
        ) -> ae_sys::A_Err {
            let (cb, refcon) = unsafe { &mut *(refcon as *mut (NonAegpCommandHook<T>, T)) };
            let already_handled_bool = already_handled != 0;

            let hook_priority_enum = HookPriority::from(hook_priority);

            let res = cb(refcon, command, hook_priority_enum, already_handled_bool);

            match res {
                Ok(CommandHookStatus::Handled) => {
                    unsafe { *handled_p = 1; }
                    Error::None
                }
                Ok(CommandHookStatus::Unhandled) => {
                    unsafe { *handled_p = 0; }
                    Error::None
                }
                Err(e) => {
                    unsafe { *handled_p = 0; }
                    e
                }
            }
            .into()
        }

        let refcon_cb_tuple = Box::new((command_hook_func, command_refcon));
        call_suite_fn!(
            self,
            AEGP_RegisterCommandHook,
            plugin_id,
            hook_priority.into(),
            command,
            Some(command_hook_wrapper::<RefCon>),
            Box::into_raw(refcon_cb_tuple) as *mut _,
        )
    }

    /// Register your menu update function (which determines whether or not items are active),
    /// called every time any menu is to be drawn.
    pub fn register_update_menu_hook<UpdateMenuRefCon>(
        &self,
        plugin_id: ae_sys::AEGP_PluginID,
        update_menu_hook_func: NonAegpUpdateMenuHook<UpdateMenuRefCon>,
        update_menu_refcon: UpdateMenuRefCon,
    ) -> Result<(), Error> {
        unsafe extern "C" fn update_menu_hook_wrapper<T>(
            _: AEGP_GlobalRefcon,
            refcon: AEGP_UpdateMenuRefcon,
            window_type: ae_sys::AEGP_WindowType,
        ) -> sys::PF_Err {
            let (callback, refcon) = unsafe { &mut *(refcon as *mut (NonAegpUpdateMenuHook<T>, T)) };

            match callback(refcon, window_type.into()) {
                Ok(_) => Error::None,
                Err(e) => e.into(),
            }
            .into()
        }

        let refcon_cb_tuple = Box::new((update_menu_hook_func, update_menu_refcon));

        call_suite_fn!(
            self,
            AEGP_RegisterUpdateMenuHook,
            plugin_id,
            Some(update_menu_hook_wrapper::<UpdateMenuRefCon>),
            Box::into_raw(refcon_cb_tuple) as *mut _,
        )
    }

    /// Register your termination function. Called when the application quits.
    pub fn register_death_hook<DeathRefcon>(
        &self,
        plugin_id: ae_sys::AEGP_PluginID,
        death_hook_func: NonAegpDeathHook<DeathRefcon>,
        death_refcon: DeathRefcon,
    ) -> Result<(), Error> {
        unsafe extern "C" fn death_hook_wrapper<T>(
            _: AEGP_GlobalRefcon,
            refcon: AEGP_DeathRefcon,
        ) -> sys::PF_Err {
            let (cb, refcon) = unsafe { &mut *(refcon as *mut (NonAegpDeathHook<T>, T)) };
            match cb(refcon) {
                Ok(_) => Error::None,
                Err(e) => e,
            }
            .into()
        }

        let refcon_cb_tuple = Box::new((death_hook_func, death_refcon));
        call_suite_fn!(
            self,
            AEGP_RegisterDeathHook,
            plugin_id,
            Some(death_hook_wrapper::<DeathRefcon>),
            Box::into_raw(refcon_cb_tuple) as *mut _,
        )
    }

    /// Currently not called.
    pub fn register_version_hook<VersionRefCon>(
        &self,
        plugin_id: ae_sys::AEGP_PluginID,
        version_hook_func: NonAegpVersionHook<VersionRefCon>,
        version_refcon: VersionRefCon,
    ) -> Result<(), Error> {
        unsafe extern "C" fn version_hook_wrapper<T>(
            _: AEGP_GlobalRefcon,
            refcon: AEGP_VersionRefcon,
            pf_version_p: *mut ae_sys::A_u_long,
        ) -> ae_sys::A_Err {
            log::error!(
                "The after effects documentation said version hook should never be called!"
            );

            let (cb, refcon) = unsafe { &mut *(refcon as *mut (NonAegpVersionHook<T>, T)) };
            let pf_version = unsafe { &mut (*pf_version_p as u32) };

            match cb(refcon, pf_version) {
                Ok(_) => Error::None,
                Err(e) => e,
            }
            .into()
        }

        log::warn!("Called `register_version_hook`, this does nothing!");

        let refcon_cb_tuple = Box::new((version_hook_func, version_refcon));
        call_suite_fn!(
            self,
            AEGP_RegisterVersionHook,
            plugin_id,
            Some(version_hook_wrapper::<VersionRefCon>),
            Box::into_raw(refcon_cb_tuple) as *mut _,
        )
    }

    /// Currently not called.
    pub fn register_about_string_hook<AboutString>(
        &self,
        plugin_id: ae_sys::AEGP_PluginID,
        about_string_hook_func: NonAegpAboutStringHook<AboutString>,
        about_string_refcon: AboutString,
    ) -> Result<(), Error> {
        unsafe extern "C" fn about_string_hook_wrapper<T>(
            _: AEGP_GlobalRefcon,
            refcon: AEGP_AboutStringRefcon,
            // We have 0 documentation about this pointer
            // besides that it is never constructed, so it's treated as null
            _about_z: *mut ae_sys::A_char,
        ) -> ae_sys::A_Err {
            log::error!(
                "The after effects documentation said about string hook should never be called!"
            );

            let (cb, refcon) = unsafe { &mut *(refcon as *mut (NonAegpAboutStringHook<T>, T)) };

            match cb(refcon, &mut []) {
                Ok(_) => Error::None,
                Err(e) => e,
            }
            .into()
        }

        log::warn!("Called `register_about_string_hook`, this does nothing!");

        let refcon_cb_tuple = Box::new((about_string_hook_func, about_string_refcon));
        call_suite_fn!(
            self,
            AEGP_RegisterAboutStringHook,
            plugin_id,
            Some(about_string_hook_wrapper::<AboutString>),
            Box::into_raw(refcon_cb_tuple) as *mut _,
        )
    }

    /// Currently not called.
    pub fn register_about_hook<About>(
        &self,
        plugin_id: ae_sys::AEGP_PluginID,
        about_hook_func: NonAegpAboutHook<About>,
        about_refcon: About,
    ) -> Result<(), Error> {
        unsafe extern "C" fn about_hook_wrapper<T>(
            _: AEGP_GlobalRefcon,
            refcon: AEGP_AboutRefcon,
        ) -> ae_sys::A_Err {
            log::error!("The after effects documentation said about hook should never be called!");

            let (cb, refcon) = unsafe { &mut *(refcon as *mut (NonAegpAboutHook<T>, T)) };

            match cb(refcon) {
                Ok(_) => Error::None,
                Err(e) => e,
            }
            .into()
        }

        log::warn!("Called `register_about_hook`, this does nothing!");

        let refcon_cb_tuple = Box::new((about_hook_func, about_refcon));
        call_suite_fn!(
            self,
            AEGP_RegisterAboutHook,
            plugin_id,
            Some(about_hook_wrapper::<About>),
            Box::into_raw(refcon_cb_tuple) as *mut _,
        )
    }

    /// Register your IdleHook function. After Effects will call the function sporadically,
    /// while the user makes difficult artistic decisions (or while they're getting more coffee).
    pub fn register_idle_hook<IdleRefCon>(
        &self,
        plugin_id: ae_sys::AEGP_PluginID,
        idle_hook_func: NonAegpIdleHook<IdleRefCon>,
        idle_refcon: IdleRefCon,
    ) -> Result<(), Error> {
        unsafe extern "C" fn idle_hook_wrapper<T>(
            _: AEGP_GlobalRefcon,
            refcon: ae_sys::AEGP_IdleRefcon,
            max_sleep_p: *mut ae_sys::A_long,
        ) -> ae_sys::A_Err {
            let (cb, refcon) = unsafe { &mut *(refcon as *mut (NonAegpIdleHook<T>, T)) };
            let max_sleep = unsafe { &mut (*max_sleep_p) };

            match cb(refcon, max_sleep) {
                Ok(_) => Error::None,
                Err(e) => e,
            }
            .into()
        }

        let refcon_cb_tuple = Box::new((idle_hook_func, idle_refcon));
        call_suite_fn!(
            self,
            AEGP_RegisterIdleHook,
            plugin_id,
            Some(idle_hook_wrapper::<IdleRefCon>),
            Box::into_raw(refcon_cb_tuple) as *mut _,
        )
    }

    /// Call this to register as many strings as you like for name-replacement when presets are loaded.
    /// Any time a Property name is found, or referred to in an expression, and it starts with an ASCII tab character ('t'),
    /// followed by one of the English names, it will be replaced with the localized name.
    /// (In English the tab character will simply be removed).
    pub fn register_preset_localization_string(
        &self,
        english_name: &str,
        localized_name: &str,
    ) -> Result<(), Error> {
        let english_name_c = CString::new(english_name).map_err(|_| Error::InvalidParms)?;
        let localized_name_c = CString::new(localized_name).map_err(|_| Error::InvalidParms)?;
        call_suite_fn!(
            self,
            AEGP_RegisterPresetLocalizationString,
            english_name_c.as_ptr(),
            localized_name_c.as_ptr()
        )
    }
}