use crate::{config::*, daq::StreamMgr};
mod clipstate;
mod ppm;
pub mod ppmchannel;
mod ppmdropspeed;
pub use clipstate::ClipState;
pub use ppm::PPM;
pub use ppmchannel::PPMChannelStatus;
pub use ppmdropspeed::PPMDropSpeed;
use std::{sync::Arc, time::Duration};
pub const LEVEL_THRESHOLD_FOR_LOW_LEVEL: Flt = -60.;
pub const LEVEL_THRESHOLD_FOR_HIGH_LEVEL: Flt = -10.;
pub const ALMOST_CLIPPED_REL_AMP: Flt = 0.98;
pub const CLIP_INDICATOR_WAIT_S: Flt = 2.;
pub const PEAK_LEVEL_HOLD_TIME_S: Flt = 1.;
#[cfg(feature = "python-bindings")]
#[cfg_attr(feature = "python-bindings", gen_stub_pyclass, pyclass(name = "PPM"))]
pub struct PPMWrapper {
PPM: Arc<PPM>,
}
#[cfg(feature = "python-bindings")]
#[cfg_attr(feature = "python-bindings", gen_stub_pymethods, pymethods)]
impl PPMWrapper {
#[staticmethod]
#[pyo3(name = "newMonitor")]
#[gen_stub(skip)]
fn newMonitor_py(smgr: &mut StreamMgr, dropSpeed: PPMDropSpeed) -> Self {
Self {
PPM: PPM::newMonitor(smgr, dropSpeed),
}
}
#[staticmethod]
#[pyo3(name = "newInput")]
#[gen_stub(skip)]
fn newInput_py(smgr: &mut StreamMgr, dropSpeed: PPMDropSpeed) -> Self {
Self {
PPM: PPM::newInput(smgr, dropSpeed),
}
}
#[pyo3(name = "getState")]
fn getState_py<'py>(
&self,
py: Python<'py>,
) -> (
Bound<'py, PyArray1<Flt>>,
Bound<'py, PyArray1<Flt>>,
Vec<ClipState>,
) {
let (levels, peak_levels, clips) = self.PPM.getState();
let levels = levels.to_pyarray(py);
let peak_levels = peak_levels.to_pyarray(py);
(levels, peak_levels, clips)
}
}
cfg_select! {
feature = "python-bindings" => {
pyo3_stub_gen::inventory::submit! {
gen_methods_from_python! {
r#"
import numpy
import numpy.typing
class PPMWrapper:
@staticmethod
def newMonitor(smgr: StreamMgr, dropSpeed: PPMDropSpeed) -> PPMWrapper:
"""Create a new monitor PPM instance"""
@staticmethod
def newInput(smgr: StreamMgr, dropSpeed: PPMDropSpeed) -> PPMWrapper:
"""Create a new input PPM instance"""
"#
}
}
},
_ => {}
}