From 5bfe9e8c97e28c58023bf0eb40a89c58625a76d7 Mon Sep 17 00:00:00 2001 From: Weird Constructor Date: Wed, 27 Jul 2022 06:02:06 +0200 Subject: [PATCH] Added threshold to ScopeHandle --- src/dsp/node_scope.rs | 11 ++++++++--- src/scope_handle.rs | 21 ++++++++++++++++++++- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/dsp/node_scope.rs b/src/dsp/node_scope.rs index 8d30b1c..ea1298d 100644 --- a/src/dsp/node_scope.rs +++ b/src/dsp/node_scope.rs @@ -135,15 +135,18 @@ impl DspNode for Scope { self.handle.set_offs_gain( 0, denorm::Scope::off1(inp::Scope::off1(inputs), 0), - denorm::Scope::gain1(inp::Scope::gain1(inputs), 0)); + denorm::Scope::gain1(inp::Scope::gain1(inputs), 0), + ); self.handle.set_offs_gain( 1, denorm::Scope::off2(inp::Scope::off2(inputs), 0), - denorm::Scope::gain2(inp::Scope::gain2(inputs), 0)); + denorm::Scope::gain2(inp::Scope::gain2(inputs), 0), + ); self.handle.set_offs_gain( 2, denorm::Scope::off3(inp::Scope::off3(inputs), 0), - denorm::Scope::gain3(inp::Scope::gain3(inputs), 0)); + denorm::Scope::gain3(inp::Scope::gain3(inputs), 0), + ); let time = denorm::Scope::time(time, 0).clamp(0.1, 1000.0 * 300.0); let samples_per_block = (time * self.srate_ms) / SCOPE_SAMPLES as f32; @@ -156,6 +159,8 @@ impl DspNode for Scope { let trigger_input = if tsrc.i() == 2 { trig } else { in1 }; let trigger_disabled = tsrc.i() == 0; + self.handle.set_threshold(if trigger_disabled { None } else { Some(threshold) }); + //d// println!("TIME time={}; st={}; tpb={}; frame_time={}", time, sample_time, time_per_block, self.frame_time); if samples_per_block < 1.0 { let copy_count = ((1.0 / samples_per_block) as usize).min(SCOPE_SAMPLES); diff --git a/src/scope_handle.rs b/src/scope_handle.rs index 41ee1f2..ec5337e 100644 --- a/src/scope_handle.rs +++ b/src/scope_handle.rs @@ -3,7 +3,7 @@ // See README.md and COPYING for details. use crate::nodes::SCOPE_SAMPLES; -use crate::util::AtomicFloatPair; +use crate::util::{AtomicFloatPair, AtomicFloat}; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; @@ -12,6 +12,7 @@ pub struct ScopeHandle { bufs: [Vec; 3], active: [AtomicBool; 3], offs_gain: [AtomicFloatPair; 3], + threshold: (AtomicBool, AtomicFloat), } impl ScopeHandle { @@ -30,6 +31,7 @@ impl ScopeHandle { AtomicFloatPair::default(), AtomicFloatPair::default(), ], + threshold: (AtomicBool::new(false), AtomicFloat::default()), }) } @@ -48,6 +50,23 @@ impl ScopeHandle { self.offs_gain[buf_idx % 3].get() } + pub fn set_threshold(&self, thresh: Option) { + if let Some(t) = thresh { + self.threshold.1.set(t); + self.threshold.0.store(true, Ordering::Relaxed); + } else { + self.threshold.0.store(false, Ordering::Relaxed); + } + } + + pub fn get_threshold(&self) -> Option { + if self.threshold.0.load(Ordering::Relaxed) { + Some(self.threshold.1.get()) + } else { + None + } + } + pub fn write(&self, buf_idx: usize, idx: usize, v: (f32, f32)) { self.bufs[buf_idx % 3][idx % SCOPE_SAMPLES].set(v); }