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, StreamDirection, SubstreamInfo};
use glib::translate::*;

/// Get the list of numeric identifier for available rawmidi devices of sound card.
///
/// Nodes under sound subsystem in sysfs are used to gather the information.
/// ## `card_id`
/// The numeric identifier of sound card.
///
/// # Returns
///
/// [`true`] when the overall operation finishes successfully, else [`false`].
///
/// ## `entries`
/// The list of numeric identifier for rawmidi device.
#[doc(alias = "alsarawmidi_get_device_id_list")]
#[doc(alias = "get_device_id_list")]
pub fn device_id_list(card_id: u32) -> Result<Vec<u32>, glib::Error> {
    unsafe {
        let mut entries = std::ptr::null_mut();
        let mut entry_count = std::mem::MaybeUninit::uninit();
        let mut error = std::ptr::null_mut();
        let is_ok = ffi::alsarawmidi_get_device_id_list(
            card_id,
            &mut entries,
            entry_count.as_mut_ptr(),
            &mut error,
        );
        debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
        if error.is_null() {
            Ok(FromGlibContainer::from_glib_full_num(
                entries,
                entry_count.assume_init() as _,
            ))
        } else {
            Err(from_glib_full(error))
        }
    }
}

/// Allocate devnode string for rawmidi device and return it when exists.
///
/// Nodes under sound subsystem in sysfs are used to gather the information.
/// ## `card_id`
/// The numeridcal identifier of sound card.
/// ## `device_id`
/// The numeric identifier of rawmidi device for the sound card.
///
/// # Returns
///
/// [`true`] when the overall operation finishes successfully, else [`false`].
///
/// ## `devnode`
/// The string for devnode of rawmidi device.
#[doc(alias = "alsarawmidi_get_rawmidi_devnode")]
#[doc(alias = "get_rawmidi_devnode")]
pub fn rawmidi_devnode(card_id: u32, device_id: u32) -> Result<glib::GString, glib::Error> {
    unsafe {
        let mut devnode = std::ptr::null_mut();
        let mut error = std::ptr::null_mut();
        let is_ok =
            ffi::alsarawmidi_get_rawmidi_devnode(card_id, device_id, &mut devnode, &mut error);
        debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
        if error.is_null() {
            Ok(from_glib_full(devnode))
        } else {
            Err(from_glib_full(error))
        }
    }
}

/// Allocate sysname for rawmidi device and return it when it exists.
///
/// Nodes under sound subsystem in sysfs are used to gather the information.
/// ## `card_id`
/// The numeridcal identifier of sound card.
/// ## `device_id`
/// The numeric identifier of rawmidi device for the sound card.
///
/// # Returns
///
/// [`true`] when the overall operation finishes successfully, else [`false`].
///
/// ## `sysname`
/// The string for sysname of rawmidi device.
#[doc(alias = "alsarawmidi_get_rawmidi_sysname")]
#[doc(alias = "get_rawmidi_sysname")]
pub fn rawmidi_sysname(card_id: u32, device_id: u32) -> Result<glib::GString, glib::Error> {
    unsafe {
        let mut sysname = std::ptr::null_mut();
        let mut error = std::ptr::null_mut();
        let is_ok =
            ffi::alsarawmidi_get_rawmidi_sysname(card_id, device_id, &mut sysname, &mut error);
        debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
        if error.is_null() {
            Ok(from_glib_full(sysname))
        } else {
            Err(from_glib_full(error))
        }
    }
}

/// Get the list of numeric identifier for subdevices belongs to the numerical identifier of card,
/// device, and the direction.
///
/// The call of function executes `open(2)`, `close(2)`, and `ioctl(2)` system call with
/// `SNDRV_CTL_IOCTL_RAWMIDI_INFO` command for ALSA control character device.
/// ## `card_id`
/// The numeric value for sound card to query.
/// ## `device_id`
/// The numeric value of rawmidi device to query.
/// ## `direction`
/// The direction of stream to query, one of [`StreamDirection`][crate::StreamDirection].
///
/// # Returns
///
/// [`true`] when the overall operation finishes successfully, else [`false`].
///
/// ## `entries`
/// The list of numeric identifier of subdevice.
#[doc(alias = "alsarawmidi_get_subdevice_id_list")]
#[doc(alias = "get_subdevice_id_list")]
pub fn subdevice_id_list(
    card_id: u32,
    device_id: u32,
    direction: StreamDirection,
) -> Result<Vec<u32>, glib::Error> {
    unsafe {
        let mut entries = std::ptr::null_mut();
        let mut entry_count = std::mem::MaybeUninit::uninit();
        let mut error = std::ptr::null_mut();
        let is_ok = ffi::alsarawmidi_get_subdevice_id_list(
            card_id,
            device_id,
            direction.into_glib(),
            &mut entries,
            entry_count.as_mut_ptr(),
            &mut error,
        );
        debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
        if error.is_null() {
            Ok(FromGlibContainer::from_glib_full_num(
                entries,
                entry_count.assume_init() as _,
            ))
        } else {
            Err(from_glib_full(error))
        }
    }
}

/// Get the information of substream pointed by the numeric identifier of card, device, subdevice,
/// and the direction.
///
/// The call of function executes `open(2)`, `close(2)`, and `ioctl(2)` system call with
/// `SNDRV_CTL_IOCTL_RAWMIDI_INFO` command for ALSA control character device.
/// ## `card_id`
/// The numeric value for sound card to query.
/// ## `device_id`
/// The numeric value of rawmidi device to query.
/// ## `direction`
/// The direction of stream, one of [`StreamDirection`][crate::StreamDirection].
/// ## `subdevice_id`
/// The numeric value of subdevice in rawmidi device.
///
/// # Returns
///
/// [`true`] when the overall operation finishes successfully, else [`false`].
///
/// ## `substream_info`
/// The information of substream for the subdevice.
#[doc(alias = "alsarawmidi_get_substream_info")]
#[doc(alias = "get_substream_info")]
pub fn substream_info(
    card_id: u32,
    device_id: u32,
    direction: StreamDirection,
    subdevice_id: u32,
) -> Result<SubstreamInfo, glib::Error> {
    unsafe {
        let mut substream_info = std::ptr::null_mut();
        let mut error = std::ptr::null_mut();
        let is_ok = ffi::alsarawmidi_get_substream_info(
            card_id,
            device_id,
            direction.into_glib(),
            subdevice_id,
            &mut substream_info,
            &mut error,
        );
        debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
        if error.is_null() {
            Ok(from_glib_full(substream_info))
        } else {
            Err(from_glib_full(error))
        }
    }
}