objc2-cinematic 0.3.2

Bindings to the Cinematic framework
Documentation
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
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ffi::*;
use core::ptr::NonNull;
use objc2::__framework_prelude::*;
#[cfg(feature = "objc2-av-foundation")]
use objc2_av_foundation::*;
#[cfg(feature = "objc2-core-media")]
use objc2_core_media::*;
use objc2_foundation::*;

use crate::*;

extern_class!(
    /// Database of focus decisions with methods to change them.
    /// Knows what has been detected in each frame and which detection is being focused on.
    /// All operations are executed in a thread-safe manner, but that also means that a long-running update can stall a lookup.
    /// Best practice is to lookup what you need up front (outside your critical code) and pass the immutable results to where it's needed.
    /// That way, you're not blocked when you access the information, say inside the rendering portion of your code.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/cinematic/cnscript?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct CNScript;
);

unsafe impl Send for CNScript {}

unsafe impl Sync for CNScript {}

extern_conformance!(
    unsafe impl NSObjectProtocol for CNScript {}
);

impl CNScript {
    extern_methods!(
        #[cfg(all(feature = "block2", feature = "objc2-av-foundation"))]
        /// Load cinematic script asynchronously from a cinematic asset.
        /// - Parameters:
        /// - asset: the cinematic asset to be loaded.
        /// - changes: optional changes since asset was recorded. Can be obtained from a previous editing session. If `nil`, the asset is loaded as originally recorded.
        /// - progress: optional progress object to track progress or cancel loading. Represents just the loading of this asset. Create with desired total unit count or use zero to have the unit count filled in automatically.  If `nil`, no progress is reported.
        /// - completionHandler: called with the loaded cinematic script when done, or with with an error if it fails. If progress is canceled before it completes, the completion handler is called with an error.
        #[unsafe(method(loadFromAsset:changes:progress:completionHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn loadFromAsset_changes_progress_completionHandler(
            asset: &AVAsset,
            changes: Option<&CNScriptChanges>,
            progress: Option<&NSProgress>,
            completion_handler: &block2::DynBlock<dyn Fn(*mut CNScript, *mut NSError)>,
        );

        /// Reload the cinematic script with optional changes applied, removing any previous changes made.
        /// This can be more efficient than loading the asset from scratch.
        /// - Parameters:
        /// - changes: optional changes since asset was recorded. Can be obtained from a previous editing session. If `nil`, the asset is reloaded as originally recorded.
        #[unsafe(method(reloadWithChanges:))]
        #[unsafe(method_family = none)]
        pub unsafe fn reloadWithChanges(&self, changes: Option<&CNScriptChanges>);

        /// Changes made since cinematic asset was recorded. Can be used to checkpoint and later restore changes made so far.
        #[unsafe(method(changes))]
        #[unsafe(method_family = none)]
        pub unsafe fn changes(&self) -> Retained<CNScriptChanges>;

        #[cfg(feature = "objc2-core-media")]
        /// Changes trimmed and time range shifted to start at zero — for use with a similarly trimmed cinematic asset.
        #[unsafe(method(changesTrimmedByTimeRange:))]
        #[unsafe(method_family = none)]
        pub unsafe fn changesTrimmedByTimeRange(
            &self,
            time_range: CMTimeRange,
        ) -> Retained<CNScriptChanges>;

        #[cfg(feature = "objc2-core-media")]
        /// The time range of the cinematic asset. All frames, decisions, and detections are within this time range.
        #[unsafe(method(timeRange))]
        #[unsafe(method_family = none)]
        pub unsafe fn timeRange(&self) -> CMTimeRange;

        #[cfg(feature = "objc2-core-media")]
        /// The closest frame to the given time within the given tolerance. Returns `nil` if there are none.
        #[unsafe(method(frameAtTime:tolerance:))]
        #[unsafe(method_family = none)]
        pub unsafe fn frameAtTime_tolerance(
            &self,
            time: CMTime,
            tolerance: CMTime,
        ) -> Option<Retained<CNScriptFrame>>;

        #[cfg(feature = "objc2-core-media")]
        /// All frames within the given time range.
        #[unsafe(method(framesInTimeRange:))]
        #[unsafe(method_family = none)]
        pub unsafe fn framesInTimeRange(
            &self,
            time_range: CMTimeRange,
        ) -> Retained<NSArray<CNScriptFrame>>;

        #[cfg(all(feature = "CNDecision", feature = "objc2-core-media"))]
        /// The closest decision to the given time within the given tolerance. Returns `nil` if there are none.
        #[unsafe(method(decisionAtTime:tolerance:))]
        #[unsafe(method_family = none)]
        pub unsafe fn decisionAtTime_tolerance(
            &self,
            time: CMTime,
            tolerance: CMTime,
        ) -> Option<Retained<CNDecision>>;

        #[cfg(all(feature = "CNDecision", feature = "objc2-core-media"))]
        /// All decisions within the given time range.
        #[unsafe(method(decisionsInTimeRange:))]
        #[unsafe(method_family = none)]
        pub unsafe fn decisionsInTimeRange(
            &self,
            time_range: CMTimeRange,
        ) -> Retained<NSArray<CNDecision>>;

        #[cfg(all(feature = "CNDecision", feature = "objc2-core-media"))]
        /// The decision that occurs after the given time. Pass the time of an existing decision to find the next one.
        #[unsafe(method(decisionAfterTime:))]
        #[unsafe(method_family = none)]
        pub unsafe fn decisionAfterTime(&self, time: CMTime) -> Option<Retained<CNDecision>>;

        #[cfg(all(feature = "CNDecision", feature = "objc2-core-media"))]
        /// The decision that occurs before the given time. Pass the time of an existing decisions to find the previous one.
        #[unsafe(method(decisionBeforeTime:))]
        #[unsafe(method_family = none)]
        pub unsafe fn decisionBeforeTime(&self, time: CMTime) -> Option<Retained<CNDecision>>;

        #[cfg(all(feature = "CNDecision", feature = "objc2-core-media"))]
        /// The primary decision that is in effect at the specified time, unless if it's outside the time range of the cinematic script.
        /// Also represents the decision that is being transitioned away from if the given time is during a focus transition.
        #[unsafe(method(primaryDecisionAtTime:))]
        #[unsafe(method_family = none)]
        pub unsafe fn primaryDecisionAtTime(&self, time: CMTime) -> Option<Retained<CNDecision>>;

        #[cfg(all(feature = "CNDecision", feature = "objc2-core-media"))]
        /// The secondary decision that is being transitioned towards if the given time is during a focus transition.
        #[unsafe(method(secondaryDecisionAtTime:))]
        #[unsafe(method_family = none)]
        pub unsafe fn secondaryDecisionAtTime(&self, time: CMTime) -> Option<Retained<CNDecision>>;

        #[cfg(all(feature = "CNDecision", feature = "objc2-core-media"))]
        /// The time range during which the focus transition away from the given decision occurs.
        #[unsafe(method(timeRangeOfTransitionAfterDecision:))]
        #[unsafe(method_family = none)]
        pub unsafe fn timeRangeOfTransitionAfterDecision(
            &self,
            decision: &CNDecision,
        ) -> CMTimeRange;

        #[cfg(all(feature = "CNDecision", feature = "objc2-core-media"))]
        /// The time range during which the focus transition towards the given decision occurs.
        #[unsafe(method(timeRangeOfTransitionBeforeDecision:))]
        #[unsafe(method_family = none)]
        pub unsafe fn timeRangeOfTransitionBeforeDecision(
            &self,
            decision: &CNDecision,
        ) -> CMTimeRange;

        #[cfg(all(feature = "CNDecision", feature = "objc2-core-media"))]
        /// All user decisions in the given time range. Includes user decisions made during recording or added to the script.
        #[unsafe(method(userDecisionsInTimeRange:))]
        #[unsafe(method_family = none)]
        pub unsafe fn userDecisionsInTimeRange(
            &self,
            time_range: CMTimeRange,
        ) -> Retained<NSArray<CNDecision>>;

        #[cfg(all(feature = "CNDecision", feature = "objc2-core-media"))]
        /// All base decisions made automatically during recording in the given time range. These apply if no user decision overrides them.
        #[unsafe(method(baseDecisionsInTimeRange:))]
        #[unsafe(method_family = none)]
        pub unsafe fn baseDecisionsInTimeRange(
            &self,
            time_range: CMTimeRange,
        ) -> Retained<NSArray<CNDecision>>;

        #[cfg(all(feature = "CNDetection", feature = "CNDetectionTrack"))]
        /// A detection track representing all detections with the given detectionID over the entire cinematic script.
        #[unsafe(method(detectionTrackForID:))]
        #[unsafe(method_family = none)]
        pub unsafe fn detectionTrackForID(
            &self,
            detection_id: CNDetectionID,
        ) -> Option<Retained<CNDetectionTrack>>;

        #[cfg(all(feature = "CNDecision", feature = "CNDetectionTrack"))]
        /// A detection track representing all detections that would be chosen by a given decision.
        #[unsafe(method(detectionTrackForDecision:))]
        #[unsafe(method_family = none)]
        pub unsafe fn detectionTrackForDecision(
            &self,
            decision: &CNDecision,
        ) -> Option<Retained<CNDetectionTrack>>;

        /// The f/number to apply to the entire movie, initially set to that of the recorded movie.
        ///
        /// Pass this to the rendering session in the rendering frame attributes to match the selected aperture.
        /// Change this property when the user selects a different aperture for the edited movie.
        /// Changes to this property are reflected in the script changes for later restoration.
        #[unsafe(method(fNumber))]
        #[unsafe(method_family = none)]
        pub unsafe fn fNumber(&self) -> c_float;

        /// Setter for [`fNumber`][Self::fNumber].
        #[unsafe(method(setFNumber:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setFNumber(&self, f_number: c_float);

        #[cfg(feature = "CNDecision")]
        /// Add a new user decision. Replaces an existing user decision if the times are identical.
        ///
        /// Adding a decision can fail if the decision focuses on an detection or group that does not exist or if its time is not within the time range of the cinematic script.
        ///
        /// - Returns: whether adding was successful
        #[unsafe(method(addUserDecision:))]
        #[unsafe(method_family = none)]
        pub unsafe fn addUserDecision(&self, decision: &CNDecision) -> bool;

        #[cfg(feature = "CNDecision")]
        /// Remove an existing user decision.
        ///
        /// User decisions added to the script or those made at recording time (by tapping during recording) can be removed.
        /// Decisions that are not user decisions cannot be removed.
        ///
        /// - Returns: whether removal was successful
        #[unsafe(method(removeUserDecision:))]
        #[unsafe(method_family = none)]
        pub unsafe fn removeUserDecision(&self, decision: &CNDecision) -> bool;

        /// Remove all user decisions and revert to base decisions only.
        #[unsafe(method(removeAllUserDecisions))]
        #[unsafe(method_family = none)]
        pub unsafe fn removeAllUserDecisions(&self);

        #[cfg(all(feature = "CNDetection", feature = "CNDetectionTrack"))]
        /// Add user created detection track.
        ///
        /// - Returns: the detectionID assigned to the added track, which can be used for later lookup or decision creation.
        #[unsafe(method(addDetectionTrack:))]
        #[unsafe(method_family = none)]
        pub unsafe fn addDetectionTrack(&self, detection_track: &CNDetectionTrack)
            -> CNDetectionID;

        #[cfg(feature = "CNDetectionTrack")]
        /// Remove user created detection track.
        ///
        /// Tracks created at recording time cannot be removed.
        ///
        /// - Returns: whether removal was successful
        #[unsafe(method(removeDetectionTrack:))]
        #[unsafe(method_family = none)]
        pub unsafe fn removeDetectionTrack(&self, detection_track: &CNDetectionTrack) -> bool;

        #[cfg(feature = "CNDetectionTrack")]
        /// All detection tracks that have been added since recording.
        #[unsafe(method(addedDetectionTracks))]
        #[unsafe(method_family = none)]
        pub unsafe fn addedDetectionTracks(&self) -> Retained<NSArray<CNDetectionTrack>>;

        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;
    );
}

extern_class!(
    /// Represents a snapshot of changes made to the cinematic script since recording.
    /// Can be used as a snapshot to quickly revert to previously saved edits via `-[CNScript reloadWithChanges:]`
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/cinematic/cnscriptchanges?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct CNScriptChanges;
);

extern_conformance!(
    unsafe impl NSObjectProtocol for CNScriptChanges {}
);

impl CNScriptChanges {
    extern_methods!(
        /// Create from previously saved data representation
        #[unsafe(method(initWithDataRepresentation:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithDataRepresentation(
            this: Allocated<Self>,
            data_representation: &NSData,
        ) -> Option<Retained<Self>>;

        /// Get persistent data representation of these changes for later restoration.
        ///
        /// The changes can only be used with the original cinematic asset from which the CNScript was created.
        #[unsafe(method(dataRepresentation))]
        #[unsafe(method_family = none)]
        pub unsafe fn dataRepresentation(&self) -> Retained<NSData>;

        /// The f/number to apply to the entire movie.
        #[unsafe(method(fNumber))]
        #[unsafe(method_family = none)]
        pub unsafe fn fNumber(&self) -> c_float;

        #[cfg(feature = "CNDecision")]
        /// All active user decisions, including those made at recording time, unless they have been removed.
        #[unsafe(method(userDecisions))]
        #[unsafe(method_family = none)]
        pub unsafe fn userDecisions(&self) -> Retained<NSArray<CNDecision>>;

        #[cfg(feature = "CNDetectionTrack")]
        /// All detection tracks that have been added. Does not include those created at recording time.
        #[unsafe(method(addedDetectionTracks))]
        #[unsafe(method_family = none)]
        pub unsafe fn addedDetectionTracks(&self) -> Retained<NSArray<CNDetectionTrack>>;

        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;
    );
}

extern_class!(
    /// Represents focus
    /// &
    /// detection information at a particular time.
    ///
    /// Indicates where to focus (disparity) and what to focus on (detection) at a particular time in the movie.
    /// It also provides access to all known detections that can be focused on at that time.
    /// Utility methods support looking up a detection by detectionID or detectionGroupID.
    ///
    /// Frames are obtained from the cinematic script using `frame(at:tolerance:)` or `frames(in:)`.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/cinematic/cnscriptframe?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct CNScriptFrame;
);

unsafe impl Send for CNScriptFrame {}

unsafe impl Sync for CNScriptFrame {}

extern_conformance!(
    unsafe impl NSCopying for CNScriptFrame {}
);

unsafe impl CopyingHelper for CNScriptFrame {
    type Result = Self;
}

extern_conformance!(
    unsafe impl NSObjectProtocol for CNScriptFrame {}
);

impl CNScriptFrame {
    extern_methods!(
        #[cfg(feature = "objc2-core-media")]
        /// The presentation time associated with the remaining properties.
        #[unsafe(method(time))]
        #[unsafe(method_family = none)]
        pub unsafe fn time(&self) -> CMTime;

        /// The disparity value representing the focus plane at which the script is focused in this frame.
        ///
        /// A larger disparity results in the focus plane being closer to the camera. The scale and offset of disparity is not defined.
        ///
        /// Pass this to the rendering session when rendering the corresponding frame of the movie to focus at the recommended depth.
        #[unsafe(method(focusDisparity))]
        #[unsafe(method_family = none)]
        pub unsafe fn focusDisparity(&self) -> c_float;

        #[cfg(feature = "CNDetection")]
        /// The detection on which the script is focused in this frame.
        ///
        /// The focusDisparity of the focusDetection can be different from that of the frame such as when a rack focus is in progress.
        #[unsafe(method(focusDetection))]
        #[unsafe(method_family = none)]
        pub unsafe fn focusDetection(&self) -> Retained<CNDetection>;

        #[cfg(feature = "CNDetection")]
        /// All detected objects in this frame.
        #[unsafe(method(allDetections))]
        #[unsafe(method_family = none)]
        pub unsafe fn allDetections(&self) -> Retained<NSArray<CNDetection>>;

        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;
    );
}

/// CNExtensions.
impl CNScriptFrame {
    extern_methods!(
        #[cfg(feature = "CNDetection")]
        /// The detection in this frame with the given detection ID, if any.
        #[unsafe(method(detectionForID:))]
        #[unsafe(method_family = none)]
        pub unsafe fn detectionForID(
            &self,
            detection_id: CNDetectionID,
        ) -> Option<Retained<CNDetection>>;

        #[cfg(feature = "CNDetection")]
        /// The best detection to focus on in this frame among those with the given detectionGroupID.
        /// For example, a face is preferred to the corresponding torso, even though both have the same detectionGroupID.
        #[unsafe(method(bestDetectionForGroupID:))]
        #[unsafe(method_family = none)]
        pub unsafe fn bestDetectionForGroupID(
            &self,
            detection_group_id: CNDetectionGroupID,
        ) -> Option<Retained<CNDetection>>;
    );
}