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::{ffi, StreamVolumeFormat};
7use glib::{
8    prelude::*,
9    signal::{connect_raw, SignalHandlerId},
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
76mod sealed {
77    pub trait Sealed {}
78    impl<T: super::IsA<super::StreamVolume>> Sealed for T {}
79}
80
81/// Trait containing all [`struct@StreamVolume`] methods.
82///
83/// # Implementors
84///
85/// [`StreamVolume`][struct@crate::StreamVolume]
86pub trait StreamVolumeExt: IsA<StreamVolume> + sealed::Sealed + 'static {
87    ///
88    /// # Returns
89    ///
90    /// Returns [`true`] if the stream is muted
91    #[doc(alias = "gst_stream_volume_get_mute")]
92    #[doc(alias = "get_mute")]
93    #[doc(alias = "mute")]
94    fn is_muted(&self) -> bool {
95        unsafe {
96            from_glib(ffi::gst_stream_volume_get_mute(
97                self.as_ref().to_glib_none().0,
98            ))
99        }
100    }
101
102    /// ## `format`
103    /// [`StreamVolumeFormat`][crate::StreamVolumeFormat] which should be returned
104    ///
105    /// # Returns
106    ///
107    /// The current stream volume as linear factor
108    #[doc(alias = "gst_stream_volume_get_volume")]
109    #[doc(alias = "get_volume")]
110    fn volume(&self, format: StreamVolumeFormat) -> f64 {
111        unsafe {
112            ffi::gst_stream_volume_get_volume(self.as_ref().to_glib_none().0, format.into_glib())
113        }
114    }
115
116    /// ## `mute`
117    /// Mute state that should be set
118    #[doc(alias = "gst_stream_volume_set_mute")]
119    #[doc(alias = "mute")]
120    fn set_mute(&self, mute: bool) {
121        unsafe {
122            ffi::gst_stream_volume_set_mute(self.as_ref().to_glib_none().0, mute.into_glib());
123        }
124    }
125
126    /// ## `format`
127    /// [`StreamVolumeFormat`][crate::StreamVolumeFormat] of `val`
128    /// ## `val`
129    /// Linear volume factor that should be set
130    #[doc(alias = "gst_stream_volume_set_volume")]
131    #[doc(alias = "volume")]
132    fn set_volume(&self, format: StreamVolumeFormat, val: f64) {
133        unsafe {
134            ffi::gst_stream_volume_set_volume(
135                self.as_ref().to_glib_none().0,
136                format.into_glib(),
137                val,
138            );
139        }
140    }
141
142    #[doc(alias = "mute")]
143    fn connect_mute_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
144        unsafe extern "C" fn notify_mute_trampoline<
145            P: IsA<StreamVolume>,
146            F: Fn(&P) + Send + Sync + 'static,
147        >(
148            this: *mut ffi::GstStreamVolume,
149            _param_spec: glib::ffi::gpointer,
150            f: glib::ffi::gpointer,
151        ) {
152            let f: &F = &*(f as *const F);
153            f(StreamVolume::from_glib_borrow(this).unsafe_cast_ref())
154        }
155        unsafe {
156            let f: Box_<F> = Box_::new(f);
157            connect_raw(
158                self.as_ptr() as *mut _,
159                b"notify::mute\0".as_ptr() as *const _,
160                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
161                    notify_mute_trampoline::<Self, F> as *const (),
162                )),
163                Box_::into_raw(f),
164            )
165        }
166    }
167
168    #[doc(alias = "volume")]
169    fn connect_volume_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
170        unsafe extern "C" fn notify_volume_trampoline<
171            P: IsA<StreamVolume>,
172            F: Fn(&P) + Send + Sync + 'static,
173        >(
174            this: *mut ffi::GstStreamVolume,
175            _param_spec: glib::ffi::gpointer,
176            f: glib::ffi::gpointer,
177        ) {
178            let f: &F = &*(f as *const F);
179            f(StreamVolume::from_glib_borrow(this).unsafe_cast_ref())
180        }
181        unsafe {
182            let f: Box_<F> = Box_::new(f);
183            connect_raw(
184                self.as_ptr() as *mut _,
185                b"notify::volume\0".as_ptr() as *const _,
186                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
187                    notify_volume_trampoline::<Self, F> as *const (),
188                )),
189                Box_::into_raw(f),
190            )
191        }
192    }
193}
194
195impl<O: IsA<StreamVolume>> StreamVolumeExt for O {}