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
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use ges_sys;
use glib;
use glib::object::Cast;
use glib::object::IsA;
use glib::signal::connect_raw;
use glib::signal::SignalHandlerId;
use glib::translate::*;
use glib::StaticType;
use glib::Value;
use glib_sys;
use gobject_sys;
use gst;
use std::boxed::Box as Box_;
use std::mem::transmute;
use Edge;
use EditMode;
use Extractable;
use Layer;
use TimelineElement;
use Track;
use TrackType;

glib_wrapper! {
    /// `TrackElement` is the Base Class for any object that can be contained in a
    /// `Track`.
    ///
    /// It contains the basic information as to the location of the object within
    /// its container, like the start position, the inpoint, the duration and the
    /// priority.
    ///
    /// # Implements
    ///
    /// [`TrackElementExt`](trait.TrackElementExt.html), [`TimelineElementExt`](trait.TimelineElementExt.html), [`glib::object::ObjectExt`](../glib/object/trait.ObjectExt.html), [`ExtractableExt`](trait.ExtractableExt.html)
    pub struct TrackElement(Object<ges_sys::GESTrackElement, ges_sys::GESTrackElementClass, TrackElementClass>) @extends TimelineElement, @implements Extractable;

    match fn {
        get_type => || ges_sys::ges_track_element_get_type(),
    }
}

pub const NONE_TRACK_ELEMENT: Option<&TrackElement> = None;

/// Trait containing all `TrackElement` methods.
///
/// # Implementors
///
/// [`TrackElement`](struct.TrackElement.html)
pub trait TrackElementExt: 'static {
    /// Looks for the properties defines with the various parametters and add
    /// them to the hashtable of children properties.
    ///
    /// To be used by subclasses only
    /// ## `element`
    /// The GstElement to retrieve properties from
    /// ## `wanted_categories`
    ///
    /// An array of categories of GstElement to
    /// take into account (as defined in the factory meta "klass" field)
    /// ## `blacklist`
    /// A
    /// blacklist of elements factory names to not take into account
    /// ## `whitelist`
    /// A list
    /// of propery names to add as children properties
    fn add_children_props<P: IsA<gst::Element>>(
        &self,
        element: &P,
        wanted_categories: &[&str],
        blacklist: &[&str],
        whitelist: &[&str],
    );

    /// Edit `self` in the different exisiting `EditMode` modes. In the case of
    /// slide, and roll, you need to specify a `Edge`
    /// ## `layers`
    /// The layers you want the edit to
    ///  happen in, `None` means that the edition is done in all the
    ///  `GESLayers` contained in the current timeline.
    ///  FIXME: This is not implemented yet.
    /// ## `mode`
    /// The `EditMode` in which the edition will happen.
    /// ## `edge`
    /// The `Edge` the edit should happen on.
    /// ## `position`
    /// The position at which to edit `self` (in nanosecond)
    ///
    /// # Returns
    ///
    /// `true` if the object as been edited properly, `false` if an error
    /// occured
    fn edit(
        &self,
        layers: &[Layer],
        mode: EditMode,
        edge: Edge,
        position: u64,
    ) -> Result<(), glib::error::BoolError>;

    //fn get_all_control_bindings(&self) -> /*Unknown conversion*//*Unimplemented*/HashTable TypeId { ns_id: 0, id: 28 }/TypeId { ns_id: 6, id: 83 };

    //fn get_control_binding(&self, property_name: &str) -> /*Ignored*/Option<gst::ControlBinding>;

    /// Get the `gst::Element` this track element is controlling within GNonLin.
    ///
    /// # Returns
    ///
    /// the `gst::Element` this track element is controlling
    /// within GNonLin.
    fn get_element(&self) -> Option<gst::Element>;

    /// Get the NleObject object this object is controlling.
    ///
    /// # Deprecated
    ///
    /// use `TrackElementExt::get_nleobject` instead.
    ///
    /// # Returns
    ///
    /// the NleObject object this object is controlling.
    fn get_gnlobject(&self) -> Option<gst::Element>;

    /// Get the GNonLin object this object is controlling.
    ///
    /// # Returns
    ///
    /// the GNonLin object this object is controlling.
    fn get_nleobject(&self) -> Option<gst::Element>;

    /// Get the `Track` to which this object belongs.
    ///
    /// # Returns
    ///
    /// The `Track` to which this object
    /// belongs. Can be `None` if it is not in any track
    fn get_track(&self) -> Option<Track>;

    fn get_track_type(&self) -> TrackType;

    /// Lets you know if `self` will be used for playback and rendering,
    /// or not.
    ///
    /// # Returns
    ///
    /// `true` if `self` is active, `false` otherwize
    fn is_active(&self) -> bool;

    //fn lookup_child(&self, prop_name: &str, pspec: /*Ignored*/glib::ParamSpec) -> Option<gst::Element>;

    /// Removes a `gst::ControlBinding` from `self`.
    /// ## `property_name`
    /// The name of the property to control.
    ///
    /// # Returns
    ///
    /// `true` if the binding could be removed, `false` if an error
    /// occured
    fn remove_control_binding(&self, property_name: &str) -> Result<(), glib::error::BoolError>;

    /// Sets the usage of the `self`. If `active` is `true`, the object will be used for
    /// playback and rendering, else it will be ignored.
    /// ## `active`
    /// visibility
    ///
    /// # Returns
    ///
    /// `true` if the property was toggled, else `false`
    fn set_active(&self, active: bool) -> bool;

    //fn set_control_source(&self, source: /*Ignored*/&gst::ControlSource, property_name: &str, binding_type: &str) -> bool;

    fn set_track_type(&self, type_: TrackType);

    /// Whether the object should be taken into account in the `Track` output.
    /// If `false`, then its contents will not be used in the resulting track.
    fn get_property_active(&self) -> bool;

    //fn connect_control_binding_added<Unsupported or ignored types>(&self, f: F) -> SignalHandlerId;

    //fn connect_control_binding_removed<Unsupported or ignored types>(&self, f: F) -> SignalHandlerId;

    fn connect_property_active_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;

    fn connect_property_track_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;

    fn connect_property_track_type_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
}

impl<O: IsA<TrackElement>> TrackElementExt for O {
    fn add_children_props<P: IsA<gst::Element>>(
        &self,
        element: &P,
        wanted_categories: &[&str],
        blacklist: &[&str],
        whitelist: &[&str],
    ) {
        unsafe {
            ges_sys::ges_track_element_add_children_props(
                self.as_ref().to_glib_none().0,
                element.as_ref().to_glib_none().0,
                wanted_categories.to_glib_none().0,
                blacklist.to_glib_none().0,
                whitelist.to_glib_none().0,
            );
        }
    }

    fn edit(
        &self,
        layers: &[Layer],
        mode: EditMode,
        edge: Edge,
        position: u64,
    ) -> Result<(), glib::error::BoolError> {
        unsafe {
            glib_result_from_gboolean!(
                ges_sys::ges_track_element_edit(
                    self.as_ref().to_glib_none().0,
                    layers.to_glib_none().0,
                    mode.to_glib(),
                    edge.to_glib(),
                    position
                ),
                "Failed to edit"
            )
        }
    }

    //fn get_all_control_bindings(&self) -> /*Unknown conversion*//*Unimplemented*/HashTable TypeId { ns_id: 0, id: 28 }/TypeId { ns_id: 6, id: 83 } {
    //    unsafe { TODO: call ges_sys:ges_track_element_get_all_control_bindings() }
    //}

    //fn get_control_binding(&self, property_name: &str) -> /*Ignored*/Option<gst::ControlBinding> {
    //    unsafe { TODO: call ges_sys:ges_track_element_get_control_binding() }
    //}

    fn get_element(&self) -> Option<gst::Element> {
        unsafe {
            from_glib_none(ges_sys::ges_track_element_get_element(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn get_gnlobject(&self) -> Option<gst::Element> {
        unsafe {
            from_glib_none(ges_sys::ges_track_element_get_gnlobject(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn get_nleobject(&self) -> Option<gst::Element> {
        unsafe {
            from_glib_none(ges_sys::ges_track_element_get_nleobject(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn get_track(&self) -> Option<Track> {
        unsafe {
            from_glib_none(ges_sys::ges_track_element_get_track(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn get_track_type(&self) -> TrackType {
        unsafe {
            from_glib(ges_sys::ges_track_element_get_track_type(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn is_active(&self) -> bool {
        unsafe {
            from_glib(ges_sys::ges_track_element_is_active(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    //fn lookup_child(&self, prop_name: &str, pspec: /*Ignored*/glib::ParamSpec) -> Option<gst::Element> {
    //    unsafe { TODO: call ges_sys:ges_track_element_lookup_child() }
    //}

    fn remove_control_binding(&self, property_name: &str) -> Result<(), glib::error::BoolError> {
        unsafe {
            glib_result_from_gboolean!(
                ges_sys::ges_track_element_remove_control_binding(
                    self.as_ref().to_glib_none().0,
                    property_name.to_glib_none().0
                ),
                "Failed to remove control binding"
            )
        }
    }

    fn set_active(&self, active: bool) -> bool {
        unsafe {
            from_glib(ges_sys::ges_track_element_set_active(
                self.as_ref().to_glib_none().0,
                active.to_glib(),
            ))
        }
    }

    //fn set_control_source(&self, source: /*Ignored*/&gst::ControlSource, property_name: &str, binding_type: &str) -> bool {
    //    unsafe { TODO: call ges_sys:ges_track_element_set_control_source() }
    //}

    fn set_track_type(&self, type_: TrackType) {
        unsafe {
            ges_sys::ges_track_element_set_track_type(
                self.as_ref().to_glib_none().0,
                type_.to_glib(),
            );
        }
    }

    fn get_property_active(&self) -> bool {
        unsafe {
            let mut value = Value::from_type(<bool as StaticType>::static_type());
            gobject_sys::g_object_get_property(
                self.to_glib_none().0 as *mut gobject_sys::GObject,
                b"active\0".as_ptr() as *const _,
                value.to_glib_none_mut().0,
            );
            value
                .get()
                .expect("Return Value for property `active` getter")
                .unwrap()
        }
    }

    //fn connect_control_binding_added<Unsupported or ignored types>(&self, f: F) -> SignalHandlerId {
    //    Ignored control_binding: Gst.ControlBinding
    //}

    //fn connect_control_binding_removed<Unsupported or ignored types>(&self, f: F) -> SignalHandlerId {
    //    Ignored control_binding: Gst.ControlBinding
    //}

    fn connect_property_active_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_active_trampoline<P, F: Fn(&P) + 'static>(
            this: *mut ges_sys::GESTrackElement,
            _param_spec: glib_sys::gpointer,
            f: glib_sys::gpointer,
        ) where
            P: IsA<TrackElement>,
        {
            let f: &F = &*(f as *const F);
            f(&TrackElement::from_glib_borrow(this).unsafe_cast())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::active\0".as_ptr() as *const _,
                Some(transmute(notify_active_trampoline::<Self, F> as usize)),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_property_track_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_track_trampoline<P, F: Fn(&P) + 'static>(
            this: *mut ges_sys::GESTrackElement,
            _param_spec: glib_sys::gpointer,
            f: glib_sys::gpointer,
        ) where
            P: IsA<TrackElement>,
        {
            let f: &F = &*(f as *const F);
            f(&TrackElement::from_glib_borrow(this).unsafe_cast())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::track\0".as_ptr() as *const _,
                Some(transmute(notify_track_trampoline::<Self, F> as usize)),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_property_track_type_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_track_type_trampoline<P, F: Fn(&P) + 'static>(
            this: *mut ges_sys::GESTrackElement,
            _param_spec: glib_sys::gpointer,
            f: glib_sys::gpointer,
        ) where
            P: IsA<TrackElement>,
        {
            let f: &F = &*(f as *const F);
            f(&TrackElement::from_glib_borrow(this).unsafe_cast())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::track-type\0".as_ptr() as *const _,
                Some(transmute(notify_track_type_trampoline::<Self, F> as usize)),
                Box_::into_raw(f),
            )
        }
    }
}