use clap_sys::process::*;
use std::fmt::Debug;
mod constant_mask;
pub use constant_mask::*;
#[repr(i32)]
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum ProcessStatus {
Continue = CLAP_PROCESS_CONTINUE,
ContinueIfNotQuiet = CLAP_PROCESS_CONTINUE_IF_NOT_QUIET,
Tail = CLAP_PROCESS_TAIL,
Sleep = CLAP_PROCESS_SLEEP,
}
impl ProcessStatus {
#[inline]
pub fn from_raw(raw: clap_process_status) -> Option<Result<Self, ()>> {
use ProcessStatus::*;
match raw {
CLAP_PROCESS_CONTINUE => Some(Ok(Continue)),
CLAP_PROCESS_CONTINUE_IF_NOT_QUIET => Some(Ok(ContinueIfNotQuiet)),
CLAP_PROCESS_SLEEP => Some(Ok(Sleep)),
CLAP_PROCESS_TAIL => Some(Ok(Tail)),
CLAP_PROCESS_ERROR => Some(Err(())),
_ => None,
}
}
#[inline]
pub fn combined_with(self, other: ProcessStatus) -> ProcessStatus {
use ProcessStatus::*;
match (self, other) {
(Continue, _) | (_, Continue) => Continue,
(ContinueIfNotQuiet, _) | (_, ContinueIfNotQuiet) => ContinueIfNotQuiet,
(Tail, _) | (_, Tail) => Tail,
(Sleep, Sleep) => Sleep,
}
}
}
#[derive(Copy, Clone, Debug, PartialEq)]
pub struct PluginAudioConfiguration {
pub sample_rate: f64,
pub min_frames_count: u32,
pub max_frames_count: u32,
}
impl PluginAudioConfiguration {
pub fn validate(&self) {
static MIN: &str = "min_frames_count";
static MAX: &str = "max_frames_count";
static INVALID: &str = "Invalid PluginAudioConfiguration: ";
static ZERO: &str = " cannot be 0";
if self.min_frames_count == 0 {
invalid();
#[cold]
fn invalid() -> ! {
panic!("{INVALID}{MIN}{ZERO}");
}
}
if self.max_frames_count == 0 {
invalid();
#[cold]
fn invalid() -> ! {
panic!("{INVALID}{MAX}{ZERO}");
}
}
if self.min_frames_count > self.max_frames_count {
invalid(self);
#[cold]
fn invalid(cfg: &PluginAudioConfiguration) -> ! {
panic!(
"{INVALID}{MIN} ({}) is greater than {MAX} ({})",
cfg.min_frames_count, cfg.max_frames_count
);
}
}
}
}
use clap_sys::audio_buffer::clap_audio_buffer;
pub struct AudioPortProcessingInfo {
channel_count: u32,
latency: u32,
constant_mask: ConstantMask,
}
impl AudioPortProcessingInfo {
#[inline]
pub fn from_raw(raw: &clap_audio_buffer) -> Self {
Self {
channel_count: raw.channel_count,
latency: raw.latency,
constant_mask: ConstantMask::from_bits(raw.constant_mask),
}
}
#[inline]
pub fn channel_count(&self) -> u32 {
self.channel_count
}
#[inline]
pub fn latency(&self) -> u32 {
self.latency
}
#[inline]
pub fn constant_mask(&self) -> ConstantMask {
self.constant_mask
}
}