azo 0.0.7

Re-implementation of ASIO (Audio Stream Input/Output)
use std::ffi::{CString, c_long};
use std::num::NonZeroI32;
use std::range::RangeInclusive;
use crate::utils::cstring_from_bytes_until_nul;
use azo_sys as sys;

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ChannelCounts {
    pub in_: c_long,
    pub out: c_long
}

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Latencies {
    pub in_: c_long,
    pub out: c_long
}

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct SamplePosition {
    pub position: sys::Samples,
    pub time_stamp: sys::TimeStamp
}

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ChannelInfoResponse {
    pub is_active  : bool,
	pub group      : sys::ChannelGroup,
	pub sample_type: sys::SampleType,
	pub name       : CString
}

impl From<sys::ChannelInfo> for ChannelInfoResponse {
    fn from(value: sys::ChannelInfo) -> Self {
        Self {
            is_active  : value.is_active.try_into().unwrap_or(false),
            group      : value.channel_group,
            sample_type: value.sample_type,
            name       : cstring_from_bytes_until_nul(&value.name)
        }
    }
}

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct BufferSize {
    pub preferred: i32,
    pub range: Option<(RangeInclusive<i32>, Granularity)>
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Granularity {
    FixedStep(NonZeroI32),
    PowersOf2
}

impl From<NonZeroI32> for Granularity {
    fn from(value: NonZeroI32) -> Self {
        if value.get() == -1 {
            Self::PowersOf2
        } else {
            Self::FixedStep(value)
        }
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct ChannelId {
    pub input: bool,
    pub index: sys::ChannelIndex
}