Skip to main content

gstreamer_audio/auto/
stream_volume.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// from gst-gir-files (https://gitlab.freedesktop.org/gstreamer/gir-files-rs.git)
4// DO NOT EDIT
5
6use crate::{StreamVolumeFormat, ffi};
7use glib::{
8    prelude::*,
9    signal::{SignalHandlerId, connect_raw},
10    translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15    /// This interface is implemented by elements that provide a stream volume. Examples for
16    /// such elements are `volume` and `playbin`.
17    ///
18    /// Applications can use this interface to get or set the current stream volume. For this
19    /// the "volume" [`glib::Object`][crate::glib::Object] property can be used or the helper functions [`StreamVolumeExt::set_volume()`][crate::prelude::StreamVolumeExt::set_volume()]
20    /// and [`StreamVolumeExt::volume()`][crate::prelude::StreamVolumeExt::volume()]. This volume is always a linear factor, i.e. 0.0 is muted
21    /// 1.0 is 100%. For showing the volume in a GUI it might make sense to convert it to
22    /// a different format by using [`convert_volume()`][Self::convert_volume()]. Volume sliders should usually
23    /// use a cubic volume.
24    ///
25    /// Separate from the volume the stream can also be muted by the "mute" [`glib::Object`][crate::glib::Object] property or
26    /// [`StreamVolumeExt::set_mute()`][crate::prelude::StreamVolumeExt::set_mute()] and [`StreamVolumeExt::is_muted()`][crate::prelude::StreamVolumeExt::is_muted()].
27    ///
28    /// Elements that provide some kind of stream volume should implement the "volume" and
29    /// "mute" [`glib::Object`][crate::glib::Object] properties and handle setting and getting of them properly.
30    /// The volume property is defined to be a linear volume factor.
31    ///
32    /// ## Properties
33    ///
34    ///
35    /// #### `mute`
36    ///  Readable | Writeable
37    ///
38    ///
39    /// #### `volume`
40    ///  Readable | Writeable
41    ///
42    /// # Implements
43    ///
44    /// [`StreamVolumeExt`][trait@crate::prelude::StreamVolumeExt]
45    #[doc(alias = "GstStreamVolume")]
46    pub struct StreamVolume(Interface<ffi::GstStreamVolume, ffi::GstStreamVolumeInterface>);
47
48    match fn {
49        type_ => || ffi::gst_stream_volume_get_type(),
50    }
51}
52
53impl StreamVolume {
54    pub const NONE: Option<&'static StreamVolume> = None;
55
56    /// ## `from`
57    /// [`StreamVolumeFormat`][crate::StreamVolumeFormat] to convert from
58    /// ## `to`
59    /// [`StreamVolumeFormat`][crate::StreamVolumeFormat] to convert to
60    /// ## `val`
61    /// Volume in `from` format that should be converted
62    ///
63    /// # Returns
64    ///
65    /// the converted volume
66    #[doc(alias = "gst_stream_volume_convert_volume")]
67    pub fn convert_volume(from: StreamVolumeFormat, to: StreamVolumeFormat, val: f64) -> f64 {
68        assert_initialized_main_thread!();
69        unsafe { ffi::gst_stream_volume_convert_volume(from.into_glib(), to.into_glib(), val) }
70    }
71}
72
73unsafe impl Send for StreamVolume {}
74unsafe impl Sync for StreamVolume {}
75
76/// Trait containing all [`struct@StreamVolume`] methods.
77///
78/// # Implementors
79///
80/// [`StreamVolume`][struct@crate::StreamVolume]
81pub trait StreamVolumeExt: IsA<StreamVolume> + 'static {
82    ///
83    /// # Returns
84    ///
85    /// Returns [`true`] if the stream is muted
86    #[doc(alias = "gst_stream_volume_get_mute")]
87    #[doc(alias = "get_mute")]
88    #[doc(alias = "mute")]
89    fn is_muted(&self) -> bool {
90        unsafe {
91            from_glib(ffi::gst_stream_volume_get_mute(
92                self.as_ref().to_glib_none().0,
93            ))
94        }
95    }
96
97    /// ## `format`
98    /// [`StreamVolumeFormat`][crate::StreamVolumeFormat] which should be returned
99    ///
100    /// # Returns
101    ///
102    /// The current stream volume as linear factor
103    #[doc(alias = "gst_stream_volume_get_volume")]
104    #[doc(alias = "get_volume")]
105    fn volume(&self, format: StreamVolumeFormat) -> f64 {
106        unsafe {
107            ffi::gst_stream_volume_get_volume(self.as_ref().to_glib_none().0, format.into_glib())
108        }
109    }
110
111    /// ## `mute`
112    /// Mute state that should be set
113    #[doc(alias = "gst_stream_volume_set_mute")]
114    #[doc(alias = "mute")]
115    fn set_mute(&self, mute: bool) {
116        unsafe {
117            ffi::gst_stream_volume_set_mute(self.as_ref().to_glib_none().0, mute.into_glib());
118        }
119    }
120
121    /// ## `format`
122    /// [`StreamVolumeFormat`][crate::StreamVolumeFormat] of `val`
123    /// ## `val`
124    /// Linear volume factor that should be set
125    #[doc(alias = "gst_stream_volume_set_volume")]
126    #[doc(alias = "volume")]
127    fn set_volume(&self, format: StreamVolumeFormat, val: f64) {
128        unsafe {
129            ffi::gst_stream_volume_set_volume(
130                self.as_ref().to_glib_none().0,
131                format.into_glib(),
132                val,
133            );
134        }
135    }
136
137    #[doc(alias = "mute")]
138    fn connect_mute_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
139        unsafe extern "C" fn notify_mute_trampoline<
140            P: IsA<StreamVolume>,
141            F: Fn(&P) + Send + Sync + 'static,
142        >(
143            this: *mut ffi::GstStreamVolume,
144            _param_spec: glib::ffi::gpointer,
145            f: glib::ffi::gpointer,
146        ) {
147            unsafe {
148                let f: &F = &*(f as *const F);
149                f(StreamVolume::from_glib_borrow(this).unsafe_cast_ref())
150            }
151        }
152        unsafe {
153            let f: Box_<F> = Box_::new(f);
154            connect_raw(
155                self.as_ptr() as *mut _,
156                c"notify::mute".as_ptr(),
157                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
158                    notify_mute_trampoline::<Self, F> as *const (),
159                )),
160                Box_::into_raw(f),
161            )
162        }
163    }
164
165    #[doc(alias = "volume")]
166    fn connect_volume_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
167        unsafe extern "C" fn notify_volume_trampoline<
168            P: IsA<StreamVolume>,
169            F: Fn(&P) + Send + Sync + 'static,
170        >(
171            this: *mut ffi::GstStreamVolume,
172            _param_spec: glib::ffi::gpointer,
173            f: glib::ffi::gpointer,
174        ) {
175            unsafe {
176                let f: &F = &*(f as *const F);
177                f(StreamVolume::from_glib_borrow(this).unsafe_cast_ref())
178            }
179        }
180        unsafe {
181            let f: Box_<F> = Box_::new(f);
182            connect_raw(
183                self.as_ptr() as *mut _,
184                c"notify::volume".as_ptr(),
185                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
186                    notify_volume_trampoline::<Self, F> as *const (),
187                )),
188                Box_::into_raw(f),
189            )
190        }
191    }
192}
193
194impl<O: IsA<StreamVolume>> StreamVolumeExt for O {}