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
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// from gst-gir-files (https://gitlab.freedesktop.org/gstreamer/gir-files-rs.git)
// DO NOT EDIT

use crate::Asset;
use crate::BaseEffect;
use crate::Container;
use crate::Extractable;
#[cfg(any(feature = "v1_18", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
use crate::FrameNumber;
use crate::Layer;
use crate::TimelineElement;
use crate::Track;
use crate::TrackElement;
use crate::TrackType;
use glib::object::Cast;
use glib::object::IsA;
use glib::signal::connect_raw;
use glib::signal::SignalHandlerId;
use glib::translate::*;
use std::boxed::Box as Box_;
use std::mem::transmute;
#[cfg(any(feature = "v1_18", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
use std::ptr;

glib::wrapper! {
    /// [`Clip`][crate::Clip]-s are the core objects of a [`Layer`][crate::Layer]. Each clip may exist in
    /// a single layer but may control several [`TrackElement`][crate::TrackElement]-s that span
    /// several [`Track`][crate::Track]-s. A clip will ensure that all its children share the
    /// same `property::TimelineElement::start` and `property::TimelineElement::duration` in
    /// their tracks, which will match the `property::TimelineElement::start` and
    /// `property::TimelineElement::duration` of the clip itself. Therefore, changing
    /// the timing of the clip will change the timing of the children, and a
    /// change in the timing of a child will change the timing of the clip and
    /// subsequently all its siblings. As such, a clip can be treated as a
    /// singular object in its layer.
    ///
    /// For most uses of a [`Timeline`][crate::Timeline], it is often sufficient to only
    /// interact with [`Clip`][crate::Clip]-s directly, which will take care of creating and
    /// organising the elements of the timeline's tracks.
    ///
    /// ## Core Children
    ///
    /// In more detail, clips will usually have some *core* [`TrackElement`][crate::TrackElement]
    /// children, which are created by the clip when it is added to a layer in
    /// a timeline. The type and form of these core children will depend on the
    /// clip's subclass. You can use [`TrackElementExt::is_core()`][crate::prelude::TrackElementExt::is_core()] to determine
    /// whether a track element is considered such a core track element. Note,
    /// if a core track element is part of a clip, it will always be treated as
    /// a core *child* of the clip. You can connect to the
    /// `signal::Container::child-added` signal to be notified of their creation.
    ///
    /// When a child is added to a clip, the timeline will select its tracks
    /// using `signal::Timeline::select-tracks-for-object`. Note that it may be the
    /// case that the child will still have no set `property::TrackElement::track`
    /// after this process. For example, if the timeline does not have a track
    /// of the corresponding `property::Track::track-type`. A clip can safely contain
    /// such children, which may have their track set later, although they will
    /// play no functioning role in the timeline in the meantime.
    ///
    /// If a clip may create track elements with various
    /// `property::TrackElement::track-type`(s), such as a [`UriClip`][crate::UriClip], but you only
    /// want it to create a subset of these types, you should set the
    /// `property::Clip::supported-formats` of the clip to the subset of types. This
    /// should be done *before* adding the clip to a layer.
    ///
    /// If a clip will produce several core elements of the same
    /// `property::TrackElement::track-type`, you should connect to the timeline's
    /// `signal::Timeline::select-tracks-for-object` signal to coordinate which
    /// tracks each element should land in. Note, no two core children within a
    /// clip can share the same [`Track`][crate::Track], so you should not select the same
    /// track for two separate core children. Provided you stick to this rule,
    /// it is still safe to select several tracks for the same core child, the
    /// core child will be copied into the additional tracks. You can manually
    /// add the child to more tracks later using [`ClipExt::add_child_to_track()`][crate::prelude::ClipExt::add_child_to_track()].
    /// If you do not wish to use a core child, you can always select no track.
    ///
    /// The `property::TimelineElement::in-point` of the clip will control the
    /// `property::TimelineElement::in-point` of its core children to be the same
    /// value if their `property::TrackElement::has-internal-source` is set to [`true`].
    ///
    /// The `property::TimelineElement::max-duration` of the clip is the minimum
    /// `property::TimelineElement::max-duration` of its core children. If you set its
    /// value to anything other than its current value, this will also set the
    /// `property::TimelineElement::max-duration` of all its core children to the same
    /// value if their `property::TrackElement::has-internal-source` is set to [`true`].
    /// As a special case, whilst a clip does not yet have any core children,
    /// its `property::TimelineElement::max-duration` may be set to indicate what its
    /// value will be once they are created.
    ///
    /// ## Effects
    ///
    /// Some subclasses (`GESSourceClip` and `GESBaseEffectClip`) may also allow
    /// their objects to have additional non-core [`BaseEffect`][crate::BaseEffect]-s elements as
    /// children. These are additional effects that are applied to the output
    /// data of the core elements. They can be added to the clip using
    /// [`ClipExt::add_top_effect()`][crate::prelude::ClipExt::add_top_effect()], which will take care of adding the effect to
    /// the timeline's tracks. The new effect will be placed between the clip's
    /// core track elements and its other effects. As such, the newly added
    /// effect will be applied to any source data **before** the other existing
    /// effects. You can change the ordering of effects using
    /// [`ClipExt::set_top_effect_index()`][crate::prelude::ClipExt::set_top_effect_index()].
    ///
    /// Tracks are selected for top effects in the same way as core children.
    /// If you add a top effect to a clip before it is part of a timeline, and
    /// later add the clip to a timeline, the track selection for the top
    /// effects will occur just after the track selection for the core
    /// children. If you add a top effect to a clip that is already part of a
    /// timeline, the track selection will occur immediately. Since a top
    /// effect must be applied on top of a core child, if you use
    /// `signal::Timeline::select-tracks-for-object`, you should ensure that the
    /// added effects are destined for a [`Track`][crate::Track] that already contains a core
    /// child.
    ///
    /// In addition, if the core child in the track is not
    /// `property::TrackElement::active`, then neither can any of its effects be
    /// `property::TrackElement::active`. Therefore, if a core child is made in-active,
    /// all of the additional effects in the same track will also become
    /// in-active. Similarly, if an effect is set to be active, then the core
    /// child will also become active, but other effects will be left alone.
    /// Finally, if an active effect is added to the track of an in-active core
    /// child, it will become in-active as well. Note, in contrast, setting a
    /// core child to be active, or an effect to be in-active will *not* change
    /// the other children in the same track.
    ///
    /// ### Time Effects
    ///
    /// Some effects also change the timing of their data (see [`BaseEffect`][crate::BaseEffect]
    /// for what counts as a time effect). Note that a `GESBaseEffectClip` will
    /// refuse time effects, but a `GESSource` will allow them.
    ///
    /// When added to a clip, time effects may adjust the timing of other
    /// children in the same track. Similarly, when changing the order of
    /// effects, making them (in)-active, setting their time property values
    /// or removing time effects. These can cause the `property::Clip::duration-limit`
    /// to change in value. However, if such an operation would ever cause the
    /// `property::TimelineElement::duration` to shrink such that a clip's `GESSource` is
    /// totally overlapped in the timeline, the operation would be prevented.
    /// Note that the same can happen when adding non-time effects with a
    /// finite `property::TimelineElement::max-duration`.
    ///
    /// Therefore, when working with time effects, you should -- more so than
    /// usual -- not assume that setting the properties of the clip's children
    /// will succeed. In particular, you should use
    /// [`TimelineElementExt::set_child_property_full()`][crate::prelude::TimelineElementExt::set_child_property_full()] when setting the time
    /// properties.
    ///
    /// If you wish to preserve the *internal* duration of a source in a clip
    /// during these time effect operations, you can do something like the
    /// following.
    ///
    /// ```c
    /// void
    /// do_time_effect_change (GESClip * clip)
    /// {
    ///   GList *tmp, *children;
    ///   GESTrackElement *source;
    ///   GstClockTime source_outpoint;
    ///   GstClockTime new_end;
    ///   GError *error = NULL;
    ///
    ///   // choose some active source in a track to preserve the internal
    ///   // duration of
    ///   source = ges_clip_get_track_element (clip, NULL, GES_TYPE_SOURCE);
    ///
    ///   // note its current internal end time
    ///   source_outpoint = ges_clip_get_internal_time_from_timeline_time (
    ///         clip, source, GES_TIMELINE_ELEMENT_END (clip), NULL);
    ///
    ///   // handle invalid out-point
    ///
    ///   // stop the children's control sources from clamping when their
    ///   // out-point changes with a change in the time effects
    ///   children = ges_container_get_children (GES_CONTAINER (clip), FALSE);
    ///
    ///   for (tmp = children; tmp; tmp = tmp->next)
    ///     ges_track_element_set_auto_clamp_control_source (tmp->data, FALSE);
    ///
    ///   // add time effect, or set their children properties, or move them around
    ///   ...
    ///   // user can make sure that if a time effect changes one source, we should
    ///   // also change the time effect for another source. E.g. if
    ///   // "GstVideorate::rate" is set to 2.0, we also set "GstPitch::rate" to
    ///   // 2.0
    ///
    ///   // Note the duration of the clip may have already changed if the
    ///   // duration-limit of the clip dropped below its current value
    ///
    ///   new_end = ges_clip_get_timeline_time_from_internal_time (
    ///         clip, source, source_outpoint, &error);
    ///   // handle error
    ///
    ///   if (!ges_timeline_elemnet_edit_full (GES_TIMELINE_ELEMENT (clip),
    ///         -1, GES_EDIT_MODE_TRIM, GES_EDGE_END, new_end, &error))
    ///     // handle error
    ///
    ///   for (tmp = children; tmp; tmp = tmp->next)
    ///     ges_track_element_set_auto_clamp_control_source (tmp->data, TRUE);
    ///
    ///   g_list_free_full (children, gst_object_unref);
    ///   gst_object_unref (source);
    /// }
    /// ```
    ///
    /// This is an Abstract Base Class, you cannot instantiate it.
    ///
    /// # Implements
    ///
    /// [`ClipExt`][trait@crate::prelude::ClipExt], [`GESContainerExt`][trait@crate::prelude::GESContainerExt], [`TimelineElementExt`][trait@crate::prelude::TimelineElementExt], [`trait@glib::ObjectExt`], [`ExtractableExt`][trait@crate::prelude::ExtractableExt], [`TimelineElementExtManual`][trait@crate::prelude::TimelineElementExtManual]
    #[doc(alias = "GESClip")]
    pub struct Clip(Object<ffi::GESClip, ffi::GESClipClass>) @extends Container, TimelineElement, @implements Extractable;

    match fn {
        type_ => || ffi::ges_clip_get_type(),
    }
}

pub const NONE_CLIP: Option<&Clip> = None;

/// Trait containing all [`struct@Clip`] methods.
///
/// # Implementors
///
/// [`Clip`][struct@crate::Clip], [`OperationClip`][struct@crate::OperationClip]
pub trait ClipExt: 'static {
    /// Extracts a [`TrackElement`][crate::TrackElement] from an asset and adds it to the clip.
    /// This can be used to add effects that derive from the asset to the
    /// clip, but this method is not intended to be used to create the core
    /// elements of the clip.
    /// ## `asset`
    /// An asset with `GES_TYPE_TRACK_ELEMENT` as its
    /// `property::Asset::extractable-type`
    ///
    /// # Returns
    ///
    /// The newly created element, or
    /// [`None`] if an error occurred.
    #[doc(alias = "ges_clip_add_asset")]
    fn add_asset<P: IsA<Asset>>(&self, asset: &P) -> Result<TrackElement, glib::BoolError>;

    /// Adds the track element child of the clip to a specific track.
    ///
    /// If the given child is already in another track, this will create a copy
    /// of the child, add it to the clip, and add this copy to the track.
    ///
    /// You should only call this whilst a clip is part of a [`Timeline`][crate::Timeline], and
    /// for tracks that are in the same timeline.
    ///
    /// This method is an alternative to using the
    /// `signal::Timeline::select-tracks-for-object` signal, but can be used to
    /// complement it when, say, you wish to copy a clip's children from one
    /// track into a new one.
    ///
    /// When the child is a core child, it must be added to a track that does
    /// not already contain another core child of the same clip. If it is not a
    /// core child (an additional effect), then it must be added to a track
    /// that already contains one of the core children of the same clip.
    ///
    /// This method can also fail if the adding the track element to the track
    /// would break a configuration rule of the corresponding [`Timeline`][crate::Timeline],
    /// such as causing three sources to overlap at a single time, or causing
    /// a source to completely overlap another in the same track.
    /// ## `child`
    /// A child of `self`
    /// ## `track`
    /// The track to add `child` to
    ///
    /// # Returns
    ///
    /// The element that was added to `track`, either
    /// `child` or a copy of child, or [`None`] if the element could not be added.
    #[cfg(any(feature = "v1_18", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
    #[doc(alias = "ges_clip_add_child_to_track")]
    fn add_child_to_track<P: IsA<TrackElement>, Q: IsA<Track>>(
        &self,
        child: &P,
        track: &Q,
    ) -> Result<TrackElement, glib::Error>;

    /// Add a top effect to a clip at the given index.
    ///
    /// Unlike using [`GESContainerExt::add()`][crate::prelude::GESContainerExt::add()], this allows you to set the index
    /// in advance. It will also check that no error occurred during the track
    /// selection for the effect.
    ///
    /// Note, only subclasses of `GESClipClass` that have
    /// `GES_CLIP_CLASS_CAN_ADD_EFFECTS` set to [`true`] (such as `GESSourceClip`
    /// and `GESBaseEffectClip`) can have additional top effects added.
    ///
    /// Note, if the effect is a time effect, this may be refused if the clip
    /// would not be able to adapt itself once the effect is added.
    /// ## `effect`
    /// A top effect to add
    /// ## `index`
    /// The index to add `effect` at, or -1 to add at the highest
    ///
    /// # Returns
    ///
    /// [`true`] if `effect` was successfully added to `self` at `index`.
    #[cfg(any(feature = "v1_18", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
    #[doc(alias = "ges_clip_add_top_effect")]
    fn add_top_effect<P: IsA<BaseEffect>>(&self, effect: &P, index: i32)
        -> Result<(), glib::Error>;

    /// Finds an element controlled by the clip. If `track` is given,
    /// then only the track elements in `track` are searched for. If `type_` is
    /// given, then this function searches for a track element of the given
    /// `type_`.
    ///
    /// Note, if multiple track elements in the clip match the given criteria,
    /// this will return the element amongst them with the highest
    /// `property::TimelineElement::priority` (numerically, the smallest). See
    /// [`find_track_elements()`][Self::find_track_elements()] if you wish to find all such elements.
    /// ## `track`
    /// The track to search in, or [`None`] to search in
    /// all tracks
    /// ## `type_`
    /// The type of track element to search for, or `G_TYPE_NONE` to
    /// match any type
    ///
    /// # Returns
    ///
    /// The element controlled by
    /// `self`, in `track`, and of the given `type_`, or [`None`] if no such element
    /// could be found.
    #[doc(alias = "ges_clip_find_track_element")]
    fn find_track_element<P: IsA<Track>>(
        &self,
        track: Option<&P>,
        type_: glib::types::Type,
    ) -> Option<TrackElement>;

    /// Finds the [`TrackElement`][crate::TrackElement]-s controlled by the clip that match the
    /// given criteria. If `track` is given as [`None`] and `track_type` is given as
    /// [`TrackType::UNKNOWN`][crate::TrackType::UNKNOWN], then the search will match all elements in any
    /// track, including those with no track, and of any
    /// `property::TrackElement::track-type`. Otherwise, if `track` is not [`None`], but
    /// `track_type` is [`TrackType::UNKNOWN`][crate::TrackType::UNKNOWN], then only the track elements in
    /// `track` are searched for. Otherwise, if `track_type` is not
    /// [`TrackType::UNKNOWN`][crate::TrackType::UNKNOWN], but `track` is [`None`], then only the track
    /// elements whose `property::TrackElement::track-type` matches `track_type` are
    /// searched for. Otherwise, when both are given, the track elements that
    /// match **either** criteria are searched for. Therefore, if you wish to
    /// only find elements in a specific track, you should give the track as
    /// `track`, but you should not give the track's `property::Track::track-type` as
    /// `track_type` because this would also select elements from other tracks
    /// of the same type.
    ///
    /// You may also give `type_` to _further_ restrict the search to track
    /// elements of the given `type_`.
    /// ## `track`
    /// The track to search in, or [`None`] to search in
    /// all tracks
    /// ## `track_type`
    /// The track-type of the track element to search for, or
    /// [`TrackType::UNKNOWN`][crate::TrackType::UNKNOWN] to match any track type
    /// ## `type_`
    /// The type of track element to search for, or `G_TYPE_NONE` to
    /// match any type
    ///
    /// # Returns
    ///
    /// A list of all
    /// the [`TrackElement`][crate::TrackElement]-s controlled by `self`, in `track` or of the given
    /// `track_type`, and of the given `type_`.
    #[doc(alias = "ges_clip_find_track_elements")]
    fn find_track_elements<P: IsA<Track>>(
        &self,
        track: Option<&P>,
        track_type: TrackType,
        type_: glib::types::Type,
    ) -> Vec<TrackElement>;

    /// Gets the `property::Clip::duration-limit` of the clip.
    ///
    /// # Returns
    ///
    /// The duration-limit of `self`.
    #[cfg(any(feature = "v1_18", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
    #[doc(alias = "ges_clip_get_duration_limit")]
    #[doc(alias = "get_duration_limit")]
    fn duration_limit(&self) -> gst::ClockTime;

    /// Convert the timeline time to an internal source time of the child.
    /// This will take any time effects placed on the clip into account (see
    /// [`BaseEffect`][crate::BaseEffect] for what time effects are supported, and how to
    /// declare them in GES).
    ///
    /// When `timeline_time` is above the `property::TimelineElement::start` of `self`,
    /// this will return the internal time at which the content that appears at
    /// `timeline_time` in the output of the timeline is created in `child`. For
    /// example, if `timeline_time` corresponds to the current seek position,
    /// this would let you know which part of a media file is being read.
    ///
    /// This will be done assuming the clip has an indefinite end, so the
    /// internal time may be beyond the current out-point of the child, or even
    /// its `property::TimelineElement::max-duration`.
    ///
    /// If, instead, `timeline_time` is below the current
    /// `property::TimelineElement::start` of `self`, this will return what you would
    /// need to set the `property::TimelineElement::in-point` of `child` to if you set
    /// the `property::TimelineElement::start` of `self` to `timeline_time` and wanted
    /// to keep the content of `child` currently found at the current
    /// `property::TimelineElement::start` of `self` at the same timeline position. If
    /// this would be negative, the conversion fails. This is useful for
    /// determining what `property::TimelineElement::in-point` would result from a
    /// [`EditMode::Trim`][crate::EditMode::Trim] to `timeline_time`.
    ///
    /// Note that whilst a clip has no time effects, this second return is
    /// equivalent to finding the internal time at which the content that
    /// appears at `timeline_time` in the timeline can be found in `child` if it
    /// had indefinite extent in both directions. However, with non-linear time
    /// effects this second return will be more distinct.
    ///
    /// In either case, the returned time would be appropriate to use for the
    /// `property::TimelineElement::in-point` or `property::TimelineElement::max-duration` of the
    /// child.
    ///
    /// See [`timeline_time_from_internal_time()`][Self::timeline_time_from_internal_time()], which performs the
    /// reverse.
    /// ## `child`
    /// An `property::TrackElement::active` child of `self` with a
    /// `property::TrackElement::track`
    /// ## `timeline_time`
    /// A time in the timeline time coordinates
    ///
    /// # Returns
    ///
    /// The time in the internal coordinates of `child` corresponding
    /// to `timeline_time`, or `GST_CLOCK_TIME_NONE` if the conversion could not
    /// be performed.
    #[cfg(any(feature = "v1_18", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
    #[doc(alias = "ges_clip_get_internal_time_from_timeline_time")]
    #[doc(alias = "get_internal_time_from_timeline_time")]
    fn internal_time_from_timeline_time<P: IsA<TrackElement>>(
        &self,
        child: &P,
        timeline_time: impl Into<Option<gst::ClockTime>>,
    ) -> Result<Option<gst::ClockTime>, glib::Error>;

    #[doc(alias = "ges_clip_get_layer")]
    #[doc(alias = "get_layer")]
    fn layer(&self) -> Option<Layer>;

    #[doc(alias = "ges_clip_get_supported_formats")]
    #[doc(alias = "get_supported_formats")]
    fn supported_formats(&self) -> TrackType;

    #[cfg(any(feature = "v1_18", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
    #[doc(alias = "ges_clip_get_timeline_time_from_internal_time")]
    #[doc(alias = "get_timeline_time_from_internal_time")]
    fn timeline_time_from_internal_time<P: IsA<TrackElement>>(
        &self,
        child: &P,
        internal_time: impl Into<Option<gst::ClockTime>>,
    ) -> Result<Option<gst::ClockTime>, glib::Error>;

    #[cfg(any(feature = "v1_18", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
    #[doc(alias = "ges_clip_get_timeline_time_from_source_frame")]
    #[doc(alias = "get_timeline_time_from_source_frame")]
    fn timeline_time_from_source_frame(
        &self,
        frame_number: FrameNumber,
    ) -> Result<Option<gst::ClockTime>, glib::Error>;

    #[doc(alias = "ges_clip_get_top_effect_index")]
    #[doc(alias = "get_top_effect_index")]
    fn top_effect_index<P: IsA<BaseEffect>>(&self, effect: &P) -> i32;

    #[doc(alias = "ges_clip_get_top_effect_position")]
    #[doc(alias = "get_top_effect_position")]
    fn top_effect_position<P: IsA<BaseEffect>>(&self, effect: &P) -> i32;

    #[doc(alias = "ges_clip_get_top_effects")]
    #[doc(alias = "get_top_effects")]
    fn top_effects(&self) -> Vec<TrackElement>;

    #[doc(alias = "ges_clip_move_to_layer")]
    fn move_to_layer<P: IsA<Layer>>(&self, layer: &P) -> Result<(), glib::error::BoolError>;

    #[cfg(any(feature = "v1_18", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
    #[doc(alias = "ges_clip_move_to_layer_full")]
    fn move_to_layer_full<P: IsA<Layer>>(&self, layer: &P) -> Result<(), glib::Error>;

    #[cfg(any(feature = "v1_18", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
    #[doc(alias = "ges_clip_remove_top_effect")]
    fn remove_top_effect<P: IsA<BaseEffect>>(&self, effect: &P) -> Result<(), glib::Error>;

    #[doc(alias = "ges_clip_set_supported_formats")]
    fn set_supported_formats(&self, supportedformats: TrackType);

    #[doc(alias = "ges_clip_set_top_effect_index")]
    fn set_top_effect_index<P: IsA<BaseEffect>>(
        &self,
        effect: &P,
        newindex: u32,
    ) -> Result<(), glib::error::BoolError>;

    #[cfg(any(feature = "v1_18", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
    #[doc(alias = "ges_clip_set_top_effect_index_full")]
    fn set_top_effect_index_full<P: IsA<BaseEffect>>(
        &self,
        effect: &P,
        newindex: u32,
    ) -> Result<(), glib::Error>;

    #[doc(alias = "ges_clip_set_top_effect_priority")]
    fn set_top_effect_priority<P: IsA<BaseEffect>>(
        &self,
        effect: &P,
        newpriority: u32,
    ) -> Result<(), glib::error::BoolError>;

    #[doc(alias = "ges_clip_split")]
    fn split(&self, position: u64) -> Result<Clip, glib::BoolError>;

    #[cfg(any(feature = "v1_18", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
    #[doc(alias = "ges_clip_split_full")]
    fn split_full(&self, position: u64) -> Result<Option<Clip>, glib::Error>;

    #[cfg(any(feature = "v1_18", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
    #[doc(alias = "duration-limit")]
    fn connect_duration_limit_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;

    #[doc(alias = "layer")]
    fn connect_layer_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;

    #[doc(alias = "supported-formats")]
    fn connect_supported_formats_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
}

impl<O: IsA<Clip>> ClipExt for O {
    fn add_asset<P: IsA<Asset>>(&self, asset: &P) -> Result<TrackElement, glib::BoolError> {
        unsafe {
            Option::<_>::from_glib_none(ffi::ges_clip_add_asset(
                self.as_ref().to_glib_none().0,
                asset.as_ref().to_glib_none().0,
            ))
            .ok_or_else(|| glib::bool_error!("Failed to add asset"))
        }
    }

    #[cfg(any(feature = "v1_18", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
    fn add_child_to_track<P: IsA<TrackElement>, Q: IsA<Track>>(
        &self,
        child: &P,
        track: &Q,
    ) -> Result<TrackElement, glib::Error> {
        unsafe {
            let mut error = ptr::null_mut();
            let ret = ffi::ges_clip_add_child_to_track(
                self.as_ref().to_glib_none().0,
                child.as_ref().to_glib_none().0,
                track.as_ref().to_glib_none().0,
                &mut error,
            );
            if error.is_null() {
                Ok(from_glib_none(ret))
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    #[cfg(any(feature = "v1_18", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
    fn add_top_effect<P: IsA<BaseEffect>>(
        &self,
        effect: &P,
        index: i32,
    ) -> Result<(), glib::Error> {
        unsafe {
            let mut error = ptr::null_mut();
            let _ = ffi::ges_clip_add_top_effect(
                self.as_ref().to_glib_none().0,
                effect.as_ref().to_glib_none().0,
                index,
                &mut error,
            );
            if error.is_null() {
                Ok(())
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    fn find_track_element<P: IsA<Track>>(
        &self,
        track: Option<&P>,
        type_: glib::types::Type,
    ) -> Option<TrackElement> {
        unsafe {
            from_glib_full(ffi::ges_clip_find_track_element(
                self.as_ref().to_glib_none().0,
                track.map(|p| p.as_ref()).to_glib_none().0,
                type_.into_glib(),
            ))
        }
    }

    fn find_track_elements<P: IsA<Track>>(
        &self,
        track: Option<&P>,
        track_type: TrackType,
        type_: glib::types::Type,
    ) -> Vec<TrackElement> {
        unsafe {
            FromGlibPtrContainer::from_glib_full(ffi::ges_clip_find_track_elements(
                self.as_ref().to_glib_none().0,
                track.map(|p| p.as_ref()).to_glib_none().0,
                track_type.into_glib(),
                type_.into_glib(),
            ))
        }
    }

    #[cfg(any(feature = "v1_18", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
    fn duration_limit(&self) -> gst::ClockTime {
        unsafe {
            try_from_glib(ffi::ges_clip_get_duration_limit(
                self.as_ref().to_glib_none().0,
            ))
            .expect("mandatory glib value is None")
        }
    }

    #[cfg(any(feature = "v1_18", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
    fn internal_time_from_timeline_time<P: IsA<TrackElement>>(
        &self,
        child: &P,
        timeline_time: impl Into<Option<gst::ClockTime>>,
    ) -> Result<Option<gst::ClockTime>, glib::Error> {
        unsafe {
            let mut error = ptr::null_mut();
            let ret = ffi::ges_clip_get_internal_time_from_timeline_time(
                self.as_ref().to_glib_none().0,
                child.as_ref().to_glib_none().0,
                timeline_time.into().into_glib(),
                &mut error,
            );
            if error.is_null() {
                Ok(from_glib(ret))
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    fn layer(&self) -> Option<Layer> {
        unsafe { from_glib_full(ffi::ges_clip_get_layer(self.as_ref().to_glib_none().0)) }
    }

    fn supported_formats(&self) -> TrackType {
        unsafe {
            from_glib(ffi::ges_clip_get_supported_formats(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[cfg(any(feature = "v1_18", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
    fn timeline_time_from_internal_time<P: IsA<TrackElement>>(
        &self,
        child: &P,
        internal_time: impl Into<Option<gst::ClockTime>>,
    ) -> Result<Option<gst::ClockTime>, glib::Error> {
        unsafe {
            let mut error = ptr::null_mut();
            let ret = ffi::ges_clip_get_timeline_time_from_internal_time(
                self.as_ref().to_glib_none().0,
                child.as_ref().to_glib_none().0,
                internal_time.into().into_glib(),
                &mut error,
            );
            if error.is_null() {
                Ok(from_glib(ret))
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    #[cfg(any(feature = "v1_18", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
    fn timeline_time_from_source_frame(
        &self,
        frame_number: FrameNumber,
    ) -> Result<Option<gst::ClockTime>, glib::Error> {
        unsafe {
            let mut error = ptr::null_mut();
            let ret = ffi::ges_clip_get_timeline_time_from_source_frame(
                self.as_ref().to_glib_none().0,
                frame_number,
                &mut error,
            );
            if error.is_null() {
                Ok(from_glib(ret))
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    fn top_effect_index<P: IsA<BaseEffect>>(&self, effect: &P) -> i32 {
        unsafe {
            ffi::ges_clip_get_top_effect_index(
                self.as_ref().to_glib_none().0,
                effect.as_ref().to_glib_none().0,
            )
        }
    }

    fn top_effect_position<P: IsA<BaseEffect>>(&self, effect: &P) -> i32 {
        unsafe {
            ffi::ges_clip_get_top_effect_position(
                self.as_ref().to_glib_none().0,
                effect.as_ref().to_glib_none().0,
            )
        }
    }

    fn top_effects(&self) -> Vec<TrackElement> {
        unsafe {
            FromGlibPtrContainer::from_glib_full(ffi::ges_clip_get_top_effects(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn move_to_layer<P: IsA<Layer>>(&self, layer: &P) -> Result<(), glib::error::BoolError> {
        unsafe {
            glib::result_from_gboolean!(
                ffi::ges_clip_move_to_layer(
                    self.as_ref().to_glib_none().0,
                    layer.as_ref().to_glib_none().0
                ),
                "Failed to move clip to specified layer"
            )
        }
    }

    #[cfg(any(feature = "v1_18", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
    fn move_to_layer_full<P: IsA<Layer>>(&self, layer: &P) -> Result<(), glib::Error> {
        unsafe {
            let mut error = ptr::null_mut();
            let _ = ffi::ges_clip_move_to_layer_full(
                self.as_ref().to_glib_none().0,
                layer.as_ref().to_glib_none().0,
                &mut error,
            );
            if error.is_null() {
                Ok(())
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    #[cfg(any(feature = "v1_18", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
    fn remove_top_effect<P: IsA<BaseEffect>>(&self, effect: &P) -> Result<(), glib::Error> {
        unsafe {
            let mut error = ptr::null_mut();
            let _ = ffi::ges_clip_remove_top_effect(
                self.as_ref().to_glib_none().0,
                effect.as_ref().to_glib_none().0,
                &mut error,
            );
            if error.is_null() {
                Ok(())
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    fn set_supported_formats(&self, supportedformats: TrackType) {
        unsafe {
            ffi::ges_clip_set_supported_formats(
                self.as_ref().to_glib_none().0,
                supportedformats.into_glib(),
            );
        }
    }

    fn set_top_effect_index<P: IsA<BaseEffect>>(
        &self,
        effect: &P,
        newindex: u32,
    ) -> Result<(), glib::error::BoolError> {
        unsafe {
            glib::result_from_gboolean!(
                ffi::ges_clip_set_top_effect_index(
                    self.as_ref().to_glib_none().0,
                    effect.as_ref().to_glib_none().0,
                    newindex
                ),
                "Failed to move effect"
            )
        }
    }

    #[cfg(any(feature = "v1_18", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
    fn set_top_effect_index_full<P: IsA<BaseEffect>>(
        &self,
        effect: &P,
        newindex: u32,
    ) -> Result<(), glib::Error> {
        unsafe {
            let mut error = ptr::null_mut();
            let _ = ffi::ges_clip_set_top_effect_index_full(
                self.as_ref().to_glib_none().0,
                effect.as_ref().to_glib_none().0,
                newindex,
                &mut error,
            );
            if error.is_null() {
                Ok(())
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    fn set_top_effect_priority<P: IsA<BaseEffect>>(
        &self,
        effect: &P,
        newpriority: u32,
    ) -> Result<(), glib::error::BoolError> {
        unsafe {
            glib::result_from_gboolean!(
                ffi::ges_clip_set_top_effect_priority(
                    self.as_ref().to_glib_none().0,
                    effect.as_ref().to_glib_none().0,
                    newpriority
                ),
                "Failed to the set top effect priority"
            )
        }
    }

    fn split(&self, position: u64) -> Result<Clip, glib::BoolError> {
        unsafe {
            Option::<_>::from_glib_none(ffi::ges_clip_split(
                self.as_ref().to_glib_none().0,
                position,
            ))
            .ok_or_else(|| glib::bool_error!("Failed to split clip"))
        }
    }

    #[cfg(any(feature = "v1_18", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
    fn split_full(&self, position: u64) -> Result<Option<Clip>, glib::Error> {
        unsafe {
            let mut error = ptr::null_mut();
            let ret =
                ffi::ges_clip_split_full(self.as_ref().to_glib_none().0, position, &mut error);
            if error.is_null() {
                Ok(from_glib_none(ret))
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    #[cfg(any(feature = "v1_18", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
    #[doc(alias = "duration-limit")]
    fn connect_duration_limit_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_duration_limit_trampoline<P: IsA<Clip>, F: Fn(&P) + 'static>(
            this: *mut ffi::GESClip,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&Clip::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::duration-limit\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_duration_limit_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "layer")]
    fn connect_layer_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_layer_trampoline<P: IsA<Clip>, F: Fn(&P) + 'static>(
            this: *mut ffi::GESClip,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&Clip::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::layer\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_layer_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "supported-formats")]
    fn connect_supported_formats_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_supported_formats_trampoline<
            P: IsA<Clip>,
            F: Fn(&P) + 'static,
        >(
            this: *mut ffi::GESClip,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&Clip::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::supported-formats\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_supported_formats_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}