alsarawmidi 0.8.0

API binding for alsarawmidi library
Documentation
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use crate::ffi;
use glib::{
    prelude::*,
    signal::{connect_raw, SignalHandlerId},
    translate::*,
};
use std::boxed::Box as Box_;

glib::wrapper! {
    /// A GObject-derived object to express parameters of substream.
    ///
    /// A [`SubstreamParams`][crate::SubstreamParams] is a GObject-derived object to express parameters of substream
    /// attached to the pair of streams. The call of [`StreamPairExt::set_substream_params()`][crate::prelude::StreamPairExt::set_substream_params()] requires
    /// the instance of object.
    ///
    /// The object wraps `struct snd_rawmidi_params` in UAPI of Linux sound subsystem.
    ///
    /// ## Properties
    ///
    ///
    /// #### `active-sensing`
    ///  Whether to emit 0xfe one time when closing substream.
    ///
    /// Readable | Writeable
    ///
    ///
    /// #### `avail-min`
    ///  The threshold to wake up from any blocking operation such as poll(2), read(2) and write(2).
    ///
    /// Readable | Writeable
    ///
    ///
    /// #### `buffer-size`
    ///  The size of intermediate buffer for substream.
    ///
    /// Readable | Writeable
    ///
    /// # Implements
    ///
    /// [`SubstreamParamsExt`][trait@crate::prelude::SubstreamParamsExt]
    #[doc(alias = "ALSARawmidiSubstreamParams")]
    pub struct SubstreamParams(Object<ffi::ALSARawmidiSubstreamParams, ffi::ALSARawmidiSubstreamParamsClass>);

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

impl SubstreamParams {
    pub const NONE: Option<&'static SubstreamParams> = None;

    /// Allocate and return an instance of [`SubstreamParams`][crate::SubstreamParams].
    ///
    /// # Returns
    ///
    /// An instance of [`SubstreamParams`][crate::SubstreamParams].
    #[doc(alias = "alsarawmidi_substream_params_new")]
    pub fn new() -> SubstreamParams {
        unsafe { from_glib_full(ffi::alsarawmidi_substream_params_new()) }
    }
}

impl Default for SubstreamParams {
    fn default() -> Self {
        Self::new()
    }
}

/// Trait containing all [`struct@SubstreamParams`] methods.
///
/// # Implementors
///
/// [`SubstreamParams`][struct@crate::SubstreamParams]
pub trait SubstreamParamsExt: IsA<SubstreamParams> + 'static {
    /// Whether to emit 0xfe one time when closing substream.
    #[doc(alias = "active-sensing")]
    fn is_active_sensing(&self) -> bool {
        ObjectExt::property(self.as_ref(), "active-sensing")
    }

    /// Whether to emit 0xfe one time when closing substream.
    #[doc(alias = "active-sensing")]
    fn set_active_sensing(&self, active_sensing: bool) {
        ObjectExt::set_property(self.as_ref(), "active-sensing", active_sensing)
    }

    /// The threshold to wake up from any blocking operation such as poll(2), read(2) and write(2).
    #[doc(alias = "avail-min")]
    fn avail_min(&self) -> u32 {
        ObjectExt::property(self.as_ref(), "avail-min")
    }

    /// The threshold to wake up from any blocking operation such as poll(2), read(2) and write(2).
    #[doc(alias = "avail-min")]
    fn set_avail_min(&self, avail_min: u32) {
        ObjectExt::set_property(self.as_ref(), "avail-min", avail_min)
    }

    /// The size of intermediate buffer for substream.
    #[doc(alias = "buffer-size")]
    fn buffer_size(&self) -> u32 {
        ObjectExt::property(self.as_ref(), "buffer-size")
    }

    /// The size of intermediate buffer for substream.
    #[doc(alias = "buffer-size")]
    fn set_buffer_size(&self, buffer_size: u32) {
        ObjectExt::set_property(self.as_ref(), "buffer-size", buffer_size)
    }

    #[doc(alias = "active-sensing")]
    fn connect_active_sensing_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_active_sensing_trampoline<
            P: IsA<SubstreamParams>,
            F: Fn(&P) + 'static,
        >(
            this: *mut ffi::ALSARawmidiSubstreamParams,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(SubstreamParams::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"notify::active-sensing".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_active_sensing_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "avail-min")]
    fn connect_avail_min_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_avail_min_trampoline<
            P: IsA<SubstreamParams>,
            F: Fn(&P) + 'static,
        >(
            this: *mut ffi::ALSARawmidiSubstreamParams,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(SubstreamParams::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"notify::avail-min".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_avail_min_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "buffer-size")]
    fn connect_buffer_size_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_buffer_size_trampoline<
            P: IsA<SubstreamParams>,
            F: Fn(&P) + 'static,
        >(
            this: *mut ffi::ALSARawmidiSubstreamParams,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(SubstreamParams::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"notify::buffer-size".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_buffer_size_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

impl<O: IsA<SubstreamParams>> SubstreamParamsExt for O {}