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
use crate::*;
use crate::aegp::*;

define_suite!(
    /// Output Module Suite provides information about and control over output modules
    /// attached to render queue items.
    ///
    /// NOTE: All `OutputModuleRefHandle`s are invalidated by ANY re-ordering, addition or removal
    /// of output modules from a render item. DO NOT CACHE THEM.
    OutputModuleSuite,
    AEGP_OutputModuleSuite4,
    kAEGPOutputModuleSuite,
    kAEGPOutputModuleSuiteVersion4
);

impl OutputModuleSuite {
    /// Acquire this suite from the host. Returns error if the suite is not available.
    /// Suite is released on drop.
    pub fn new() -> Result<Self, Error> {
        crate::Suite::new()
    }

    /// Retrieves an output module by index from a render queue item.
    pub fn output_module_by_index(
        &self,
        rq_item: impl AsPtr<ae_sys::AEGP_RQItemRefH>,
        index: i32,
    ) -> Result<OutputModuleRefHandle, Error> {
        Ok(OutputModuleRefHandle::from_raw(
            call_suite_fn_single!(
                self,
                AEGP_GetOutputModuleByIndex -> ae_sys::AEGP_OutputModuleRefH,
                rq_item.as_ptr(),
                index as ae_sys::A_long
            )?
        ))
    }

    /// Retrieves the embedding options for an output module.
    pub fn embed_options(
        &self,
        rq_item: impl AsPtr<ae_sys::AEGP_RQItemRefH>,
        output_module: impl AsPtr<ae_sys::AEGP_OutputModuleRefH>,
    ) -> Result<EmbeddingType, Error> {
        Ok(
            call_suite_fn_single!(
                self,
                AEGP_GetEmbedOptions -> ae_sys::AEGP_EmbeddingType,
                rq_item.as_ptr(),
                output_module.as_ptr()
            )?
            .into()
        )
    }

    /// Sets the embedding options for an output module.
    pub fn set_embed_options(
        &self,
        rq_item: impl AsPtr<ae_sys::AEGP_RQItemRefH>,
        output_module: impl AsPtr<ae_sys::AEGP_OutputModuleRefH>,
        embed_options: EmbeddingType,
    ) -> Result<(), Error> {
        call_suite_fn!(
            self,
            AEGP_SetEmbedOptions,
            rq_item.as_ptr(),
            output_module.as_ptr(),
            embed_options.into()
        )
    }

    /// Retrieves the post-render action for an output module.
    pub fn post_render_action(
        &self,
        rq_item: impl AsPtr<ae_sys::AEGP_RQItemRefH>,
        output_module: impl AsPtr<ae_sys::AEGP_OutputModuleRefH>,
    ) -> Result<PostRenderAction, Error> {
        Ok(
            call_suite_fn_single!(
                self,
                AEGP_GetPostRenderAction -> ae_sys::AEGP_PostRenderAction,
                rq_item.as_ptr(),
                output_module.as_ptr()
            )?
            .into()
        )
    }

    /// Sets the post-render action for an output module.
    pub fn set_post_render_action(
        &self,
        rq_item: impl AsPtr<ae_sys::AEGP_RQItemRefH>,
        output_module: impl AsPtr<ae_sys::AEGP_OutputModuleRefH>,
        action: PostRenderAction,
    ) -> Result<(), Error> {
        call_suite_fn!(
            self,
            AEGP_SetPostRenderAction,
            rq_item.as_ptr(),
            output_module.as_ptr(),
            action.into()
        )
    }

    /// Retrieves which output types (video, audio) are enabled for an output module.
    pub fn enabled_outputs(
        &self,
        rq_item: impl AsPtr<ae_sys::AEGP_RQItemRefH>,
        output_module: impl AsPtr<ae_sys::AEGP_OutputModuleRefH>,
    ) -> Result<OutputTypes, Error> {
        Ok(OutputTypes::from_bits_truncate(
            call_suite_fn_single!(
                self,
                AEGP_GetEnabledOutputs -> ae_sys::AEGP_OutputTypes,
                rq_item.as_ptr(),
                output_module.as_ptr()
            )?
        ))
    }

    /// Sets which output types (video, audio) are enabled for an output module.
    pub fn set_enabled_outputs(
        &self,
        rq_item: impl AsPtr<ae_sys::AEGP_RQItemRefH>,
        output_module: impl AsPtr<ae_sys::AEGP_OutputModuleRefH>,
        enabled_types: OutputTypes,
    ) -> Result<(), Error> {
        call_suite_fn!(
            self,
            AEGP_SetEnabledOutputs,
            rq_item.as_ptr(),
            output_module.as_ptr(),
            enabled_types.bits()
        )
    }

    /// Retrieves the output channels setting for an output module.
    pub fn output_channels(
        &self,
        rq_item: impl AsPtr<ae_sys::AEGP_RQItemRefH>,
        output_module: impl AsPtr<ae_sys::AEGP_OutputModuleRefH>,
    ) -> Result<VideoChannels, Error> {
        Ok(
            call_suite_fn_single!(
                self,
                AEGP_GetOutputChannels -> ae_sys::AEGP_VideoChannels,
                rq_item.as_ptr(),
                output_module.as_ptr()
            )?
            .into()
        )
    }

    /// Sets the output channels for an output module.
    pub fn set_output_channels(
        &self,
        rq_item: impl AsPtr<ae_sys::AEGP_RQItemRefH>,
        output_module: impl AsPtr<ae_sys::AEGP_OutputModuleRefH>,
        channels: VideoChannels,
    ) -> Result<(), Error> {
        call_suite_fn!(
            self,
            AEGP_SetOutputChannels,
            rq_item.as_ptr(),
            output_module.as_ptr(),
            channels.into()
        )
    }

    /// Retrieves the stretch info for an output module.
    ///
    /// Returns a tuple of (is_enabled, stretch_quality, is_locked).
    pub fn stretch_info(
        &self,
        rq_item: impl AsPtr<ae_sys::AEGP_RQItemRefH>,
        output_module: impl AsPtr<ae_sys::AEGP_OutputModuleRefH>,
    ) -> Result<(bool, StretchQuality, bool), Error> {
        let mut is_enabled: ae_sys::A_Boolean = 0;
        let mut stretch_quality: ae_sys::AEGP_StretchQuality = 0;
        let mut locked: ae_sys::A_Boolean = 0;

        call_suite_fn!(
            self,
            AEGP_GetStretchInfo,
            rq_item.as_ptr(),
            output_module.as_ptr(),
            &mut is_enabled,
            &mut stretch_quality,
            &mut locked
        )?;

        Ok((is_enabled != 0, stretch_quality.into(), locked != 0))
    }

    /// Sets the stretch info for an output module.
    pub fn set_stretch_info(
        &self,
        rq_item: impl AsPtr<ae_sys::AEGP_RQItemRefH>,
        output_module: impl AsPtr<ae_sys::AEGP_OutputModuleRefH>,
        is_enabled: bool,
        stretch_quality: StretchQuality,
    ) -> Result<(), Error> {
        call_suite_fn!(
            self,
            AEGP_SetStretchInfo,
            rq_item.as_ptr(),
            output_module.as_ptr(),
            is_enabled as ae_sys::A_Boolean,
            stretch_quality.into()
        )
    }

    /// Retrieves the crop info for an output module.
    ///
    /// Returns a tuple of (is_enabled, crop_rect).
    pub fn crop_info(
        &self,
        rq_item: impl AsPtr<ae_sys::AEGP_RQItemRefH>,
        output_module: impl AsPtr<ae_sys::AEGP_OutputModuleRefH>,
    ) -> Result<(bool, ae_sys::A_Rect), Error> {
        let mut is_enabled: ae_sys::A_Boolean = 0;
        let mut crop_rect: ae_sys::A_Rect = unsafe { std::mem::zeroed() };

        call_suite_fn!(
            self,
            AEGP_GetCropInfo,
            rq_item.as_ptr(),
            output_module.as_ptr(),
            &mut is_enabled,
            &mut crop_rect
        )?;

        Ok((is_enabled != 0, crop_rect))
    }

    /// Sets the crop info for an output module.
    pub fn set_crop_info(
        &self,
        rq_item: impl AsPtr<ae_sys::AEGP_RQItemRefH>,
        output_module: impl AsPtr<ae_sys::AEGP_OutputModuleRefH>,
        enable: bool,
        crop_rect: ae_sys::A_Rect,
    ) -> Result<(), Error> {
        call_suite_fn!(
            self,
            AEGP_SetCropInfo,
            rq_item.as_ptr(),
            output_module.as_ptr(),
            enable as ae_sys::A_Boolean,
            crop_rect
        )
    }

    /// Retrieves the sound format info for an output module.
    ///
    /// Returns a tuple of (sound_format, audio_enabled).
    pub fn sound_format_info(
        &self,
        rq_item: impl AsPtr<ae_sys::AEGP_RQItemRefH>,
        output_module: impl AsPtr<ae_sys::AEGP_OutputModuleRefH>,
    ) -> Result<(ae_sys::AEGP_SoundDataFormat, bool), Error> {
        let mut sound_format: ae_sys::AEGP_SoundDataFormat = unsafe { std::mem::zeroed() };
        let mut audio_enabled: ae_sys::A_Boolean = 0;

        call_suite_fn!(
            self,
            AEGP_GetSoundFormatInfo,
            rq_item.as_ptr(),
            output_module.as_ptr(),
            &mut sound_format,
            &mut audio_enabled
        )?;

        Ok((sound_format, audio_enabled != 0))
    }

    /// Sets the sound format info for an output module.
    pub fn set_sound_format_info(
        &self,
        rq_item: impl AsPtr<ae_sys::AEGP_RQItemRefH>,
        output_module: impl AsPtr<ae_sys::AEGP_OutputModuleRefH>,
        sound_format: ae_sys::AEGP_SoundDataFormat,
        audio_enabled: bool,
    ) -> Result<(), Error> {
        call_suite_fn!(
            self,
            AEGP_SetSoundFormatInfo,
            rq_item.as_ptr(),
            output_module.as_ptr(),
            sound_format,
            audio_enabled as ae_sys::A_Boolean
        )
    }

    /// Retrieves the output file path for an output module.
    /// Returns an empty string if not specified.
    pub fn output_file_path(
        &self,
        rq_item: impl AsPtr<ae_sys::AEGP_RQItemRefH>,
        output_module: impl AsPtr<ae_sys::AEGP_OutputModuleRefH>,
    ) -> Result<String, Error> {
        let mem_handle = call_suite_fn_single!(
            self,
            AEGP_GetOutputFilePath -> ae_sys::AEGP_MemHandle,
            rq_item.as_ptr(),
            output_module.as_ptr()
        )?;
        unsafe {
            Ok(
                U16CString::from_ptr_str(MemHandle::<u16>::from_raw(mem_handle)?.lock()?.as_ptr())
                    .to_string_lossy()
            )
        }
    }

    /// Sets the output file path for an output module.
    /// The path should use platform-native separators.
    pub fn set_output_file_path(
        &self,
        rq_item: impl AsPtr<ae_sys::AEGP_RQItemRefH>,
        output_module: impl AsPtr<ae_sys::AEGP_OutputModuleRefH>,
        path: &str,
    ) -> Result<(), Error> {
        let path_utf16 = U16CString::from_str(path).map_err(|_| Error::InvalidParms)?;
        call_suite_fn!(
            self,
            AEGP_SetOutputFilePath,
            rq_item.as_ptr(),
            output_module.as_ptr(),
            path_utf16.as_ptr()
        )
    }

    /// Adds a default output module to a render queue item.
    /// Returns a handle to the newly created output module.
    pub fn add_default_output_module(
        &self,
        rq_item: impl AsPtr<ae_sys::AEGP_RQItemRefH>,
    ) -> Result<OutputModuleRefHandle, Error> {
        Ok(OutputModuleRefHandle::from_raw(
            call_suite_fn_single!(
                self,
                AEGP_AddDefaultOutputModule -> ae_sys::AEGP_OutputModuleRefH,
                rq_item.as_ptr()
            )?
        ))
    }

    /// Retrieves extra information about an output module.
    ///
    /// Returns a tuple of (format_name, info, is_sequence, is_multi_frame).
    pub fn extra_output_module_info(
        &self,
        rq_item: impl AsPtr<ae_sys::AEGP_RQItemRefH>,
        output_module: impl AsPtr<ae_sys::AEGP_OutputModuleRefH>,
    ) -> Result<(String, String, bool, bool), Error> {
        let mut format_handle: ae_sys::AEGP_MemHandle = std::ptr::null_mut();
        let mut info_handle: ae_sys::AEGP_MemHandle = std::ptr::null_mut();
        let mut is_sequence: ae_sys::A_Boolean = 0;
        let mut multi_frame: ae_sys::A_Boolean = 0;

        call_suite_fn!(
            self,
            AEGP_GetExtraOutputModuleInfo,
            rq_item.as_ptr(),
            output_module.as_ptr(),
            &mut format_handle,
            &mut info_handle,
            &mut is_sequence,
            &mut multi_frame
        )?;

        unsafe {
            let format = U16CString::from_ptr_str(
                MemHandle::<u16>::from_raw(format_handle)?.lock()?.as_ptr()
            ).to_string_lossy();

            let info = U16CString::from_ptr_str(
                MemHandle::<u16>::from_raw(info_handle)?.lock()?.as_ptr()
            ).to_string_lossy();

            Ok((format, info, is_sequence != 0, multi_frame != 0))
        }
    }
}

// ――――――――――――――――――――――――――――――――――――――― Types ―――――――――――――――――――――――――――――――――――――――

define_enum! {
    ae_sys::AEGP_EmbeddingType,
    EmbeddingType {
        None        = ae_sys::AEGP_Embedding_NONE,
        Nothing     = ae_sys::AEGP_Embedding_NOTHING,
        Link        = ae_sys::AEGP_Embedding_LINK,
        LinkAndCopy = ae_sys::AEGP_Embedding_LINK_AND_COPY,
    }
}

define_enum! {
    ae_sys::AEGP_PostRenderAction,
    PostRenderAction {
        None              = ae_sys::AEGP_PostRenderOptions_NONE,
        Import            = ae_sys::AEGP_PostRenderOptions_IMPORT,
        ImportAndReplace  = ae_sys::AEGP_PostRenderOptions_IMPORT_AND_REPLACE_USAGE,
        SetProxy          = ae_sys::AEGP_PostRenderOptions_SET_PROXY,
    }
}

bitflags::bitflags! {
    /// Output type flags for specifying which types of output to render.
    #[derive(Debug, Clone, Copy, PartialEq, Eq)]
    pub struct OutputTypes: ae_sys::AEGP_OutputTypes {
        const NONE  = ae_sys::AEGP_OutputType_NONE  as ae_sys::AEGP_OutputTypes;
        const VIDEO = ae_sys::AEGP_OutputType_VIDEO as ae_sys::AEGP_OutputTypes;
        const AUDIO = ae_sys::AEGP_OutputType_AUDIO as ae_sys::AEGP_OutputTypes;
    }
}

define_enum! {
    ae_sys::AEGP_VideoChannels,
    VideoChannels {
        None  = ae_sys::AEGP_VideoChannels_NONE,
        Rgb   = ae_sys::AEGP_VideoChannels_RGB,
        Rgba  = ae_sys::AEGP_VideoChannels_RGBA,
        Alpha = ae_sys::AEGP_VideoChannels_ALPHA,
    }
}

define_enum! {
    ae_sys::AEGP_StretchQuality,
    StretchQuality {
        None = ae_sys::AEGP_StretchQual_NONE,
        Low  = ae_sys::AEGP_StretchQual_LOW,
        High = ae_sys::AEGP_StretchQual_HIGH,
    }
}