diff --git a/src/editor.rs b/src/editor.rs index b30c49b..935137e 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -20,7 +20,7 @@ include!("gain_reduction_meter.rs"); #[derive(Lens, Clone)] struct LambData { params: Arc, - peak_meter: Arc, + // peak_meter: Arc, gain_reduction_left: Arc, gain_reduction_right: Arc, peak_buffer: Arc>, @@ -29,14 +29,14 @@ struct LambData { impl LambData { pub(crate) fn new( params: Arc, - peak_meter: Arc, + // peak_meter: Arc, gain_reduction_left: Arc, gain_reduction_right: Arc, peak_buffer: Arc>, ) -> Self { Self { params, - peak_meter, + // peak_meter, gain_reduction_left, gain_reduction_right, peak_buffer, @@ -49,12 +49,13 @@ impl Model for LambData {} // Makes sense to also define this here, makes it a bit easier to keep track of pub(crate) fn default_state() -> Arc { // width , height - ViziaState::new(|| (((16.0 / 9.0) * 720.0) as u32, 720)) + // ViziaState::new(|| (((16.0 / 9.0) * 720.0) as u32, 720)) + ViziaState::new(|| (1280 as u32, 960)) } pub(crate) fn create( params: Arc, - peak_meter: Arc, + // peak_meter: Arc, gain_reduction_left: Arc, gain_reduction_right: Arc, peak_buffer: Arc>, @@ -70,7 +71,7 @@ pub(crate) fn create( LambData { params: params.clone(), - peak_meter: peak_meter.clone(), + // peak_meter: peak_meter.clone(), gain_reduction_left: gain_reduction_left.clone(), gain_reduction_right: gain_reduction_right.clone(), peak_buffer: peak_buffer.clone(), @@ -182,7 +183,7 @@ pub(crate) fn create( .set_style(ParamSliderStyle::CurrentStepLabeled { even: true }) .bottom(Pixels(6.0)); Label::new(cx, "").class("fader-label"); // spacer - AttackReleaseGraph::new(cx, LambData::params).height(Pixels(372.0)); + AttackReleaseGraph::new(cx, LambData::params).height(Pixels(373.0)); }) // graph + zoom .height(Auto) .class("center"); @@ -193,13 +194,13 @@ pub(crate) fn create( peak_graph(cx); // meters VStack::new(cx, |cx| { - Label::new(cx, "input level").class("fader-label"); - PeakMeter::new( - cx, - LambData::peak_meter - .map(|peak_meter| util::gain_to_db(peak_meter.load(Ordering::Relaxed))), - Some(Duration::from_millis(600)), - ); + // Label::new(cx, "input level").class("fader-label"); + // PeakMeter::new( + // cx, + // LambData::peak_meter + // .map(|peak_meter| util::gain_to_db(peak_meter.load(Ordering::Relaxed))), + // Some(Duration::from_millis(600)), + // ); Label::new(cx, "gain reduction left").class("fader-label"); GainReductionMeter::new( cx, @@ -401,13 +402,16 @@ fn peak_graph(cx: &mut Context) { 0.0, vec![6.0, 0.0, -6.0, -12.0, -18.0, -24.0, -30.0], ) - .color(Color::rgb(60, 60, 60)); + .color(Color::rgb(60, 60, 60)) + ; Graph::new(cx, LambData::peak_buffer, (-32.0, 6.0), ValueScaling::Decibels) - .color(Color::rgba(255, 255, 255, 160)) - .background_color(Color::rgba(255, 255, 255, 60)); + .color(Color::rgba(0, 0, 0, 160)) + .background_color(Color::rgba(16, 16, 16, 60)) + ; }) - .background_color(Color::rgb(16, 16, 16)); + // .background_color(Color::rgb(16, 16, 16)) + ; UnitRuler::new( cx, @@ -435,9 +439,14 @@ fn peak_graph(cx: &mut Context) { Orientation::Vertical, ) .width(Pixels(32.0)) - .background_color(Color::rgb(60, 60, 60)); + .color(Color::rgb(0, 0, 0)) + .background_color(Color::rgb(80, 80, 80)) + ; }) - .col_between(Pixels(8.)) - .border_color(Color::rgb(80, 80, 80)) - .border_width(Pixels(1.)); + .top(Pixels(13.0)) + .height(Pixels(280.0)) + .width(Percentage(100.0)) + .col_between(Pixels(8.)) + .border_color(Color::rgb(80, 80, 80)) + .border_width(Pixels(1.)); } diff --git a/src/lib.rs b/src/lib.rs index 0ade825..f97c6d6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,7 +16,7 @@ const MAX_SOUNDCARD_BUFFER_SIZE: usize = 32768; mod editor; /// The time it takes for the peak meter to decay by 12 dB after switching to complete silence. -const PEAK_METER_DECAY_MS: f64 = 150.0; +// const PEAK_METER_DECAY_MS: f64 = 150.0; pub struct Lamb { params: Arc, @@ -34,7 +34,7 @@ pub struct Lamb { /// idea to put all of that in a struct behind a single `Arc`. /// /// This is stored as voltage gain. - peak_meter: Arc, + // peak_meter: Arc, gain_reduction_left: Arc, gain_reduction_right: Arc, @@ -47,7 +47,7 @@ impl Default for Lamb { params: Arc::new(LambParams::default()), peak_meter_decay_weight: 1.0, - peak_meter: Arc::new(AtomicF32::new(util::MINUS_INFINITY_DB)), + // peak_meter: Arc::new(AtomicF32::new(util::MINUS_INFINITY_DB)), gain_reduction_left: Arc::new(AtomicF32::new(0.0)), gain_reduction_right: Arc::new(AtomicF32::new(0.0)), @@ -120,9 +120,9 @@ impl Plugin for Lamb { // After `PEAK_METER_DECAY_MS` milliseconds of pure silence, the peak meter's value should // have dropped by 12 dB - self.peak_meter_decay_weight = 0.25f64 - .powf((buffer_config.sample_rate as f64 * PEAK_METER_DECAY_MS / 1000.0).recip()) - as f32; + // self.peak_meter_decay_weight = 0.25f64 + // .powf((buffer_config.sample_rate as f64 * PEAK_METER_DECAY_MS / 1000.0).recip()) + // as f32; self.sample_rate = buffer_config.sample_rate; @@ -144,7 +144,7 @@ impl Plugin for Lamb { fn editor(&mut self, _async_executor: AsyncExecutor) -> Option> { editor::create( self.params.clone(), - self.peak_meter.clone(), + // self.peak_meter.clone(), self.gain_reduction_left.clone(), self.gain_reduction_right.clone(), self.peak_buffer.clone(), @@ -161,45 +161,51 @@ impl Plugin for Lamb { let count = buffer.samples() as i32; self.accum_buffer.read_from_buffer(buffer); - for channel_samples in buffer.iter_samples() { - let mut amplitude = 0.0; - let num_samples = channel_samples.len(); - - for sample in channel_samples { - amplitude += *sample; - } - // To save resources, a plugin can (and probably should!) only perform expensive - // calculations that are only displayed on the GUI while the GUI is open - if self.params.editor_state.is_open() { - amplitude = (amplitude / num_samples as f32).abs(); - let current_peak_meter = self.peak_meter.load(std::sync::atomic::Ordering::Relaxed); - let new_peak_meter = if amplitude > current_peak_meter { - amplitude - } else { - current_peak_meter * self.peak_meter_decay_weight - + amplitude * (1.0 - self.peak_meter_decay_weight) - }; - - self.peak_meter - .store(new_peak_meter, std::sync::atomic::Ordering::Relaxed); - self.gain_reduction_left.store( - self.dsp - .get_param(GAIN_REDUCTION_LEFT_PI) - .expect("no GR read") as f32, - std::sync::atomic::Ordering::Relaxed, - ); - self.gain_reduction_right.store( - self.dsp - .get_param(GAIN_REDUCTION_RIGHT_PI) - .expect("no GR read") as f32, - std::sync::atomic::Ordering::Relaxed, - ); - self.peak_buffer - .lock() - .unwrap() - .enqueue_buffer(buffer, None); - } + // for channel_samples in buffer.iter_samples() { + // let mut amplitude = 0.0; + // let num_samples = channel_samples.len(); + + // for sample in channel_samples { + // amplitude += *sample; + // } + + // To save resources, a plugin can (and probably should!) only perform expensive + // calculations that are only displayed on the GUI while the GUI is open + if self.params.editor_state.is_open() { + // amplitude = (amplitude / num_samples as f32).abs(); + // let current_peak_meter = self.peak_meter.load(std::sync::atomic::Ordering::Relaxed); + // let new_peak_meter = if amplitude > current_peak_meter { + // amplitude + // } else { + // current_peak_meter * self.peak_meter_decay_weight + // + amplitude * (1.0 - self.peak_meter_decay_weight) + // }; + + // self.peak_meter + // .store(new_peak_meter, std::sync::atomic::Ordering::Relaxed); + self.gain_reduction_left.store( + self.dsp + .get_param(GAIN_REDUCTION_LEFT_PI) + .expect("no GR read") as f32, + std::sync::atomic::Ordering::Relaxed, + ); + self.gain_reduction_right.store( + self.dsp + .get_param(GAIN_REDUCTION_RIGHT_PI) + .expect("no GR read") as f32, + std::sync::atomic::Ordering::Relaxed, + ); + self.peak_buffer + .lock() + .unwrap() + .enqueue_buffer(buffer, None); } + // } + + // To save resources, a plugin can (and probably should!) only perform expensive + // calculations that are only displayed on the GUI while the GUI is open + // if self.params.editor_state.is_open() { + // } let output = buffer.as_slice(); let bypass: f64 = match self.params.bypass.value() { @@ -214,51 +220,51 @@ impl Plugin for Lamb { }; self.dsp.set_param(LATENCY_MODE_PI, latency_mode); self.dsp - .set_param(INPUT_GAIN_PI, self.params.input_gain.value() as f64); - self.dsp - .set_param(STRENGTH_PI, self.params.strength.value() as f64); - self.dsp - .set_param(THRESH_PI, self.params.thresh.value() as f64); - self.dsp - .set_param(ATTACK_PI, self.params.attack.value() as f64); - self.dsp - .set_param(ATTACK_SHAPE_PI, self.params.attack_shape.value() as f64); - self.dsp - .set_param(RELEASE_PI, self.params.release.value() as f64); - self.dsp - .set_param(RELEASE_SHAPE_PI, self.params.release_shape.value() as f64); - self.dsp - .set_param(RELEASE_HOLD_PI, self.params.release_hold.value() as f64); - self.dsp.set_param(KNEE_PI, self.params.knee.value() as f64); - self.dsp.set_param(LINK_PI, self.params.link.value() as f64); - self.dsp.set_param( - ADAPTIVE_RELEASE_PI, - self.params.adaptive_release.value() as f64, - ); - self.dsp - .set_param(LOOKAHEAD_PI, self.params.lookahead.value() as f64); - self.dsp - .set_param(OUTPUT_GAIN_PI, self.params.output_gain.value() as f64); - - self.dsp.compute( - count, - &self.accum_buffer.slice2d(), - &mut [ - &mut self.temp_output_buffer_l, - &mut self.temp_output_buffer_r, - ], - ); - - for i in 0..count as usize { - output[0][i] = self.temp_output_buffer_l[i] as f32; - output[1][i] = self.temp_output_buffer_r[i] as f32; - } + .set_param(INPUT_GAIN_PI, self.params.input_gain.value() as f64); + self.dsp + .set_param(STRENGTH_PI, self.params.strength.value() as f64); + self.dsp + .set_param(THRESH_PI, self.params.thresh.value() as f64); + self.dsp + .set_param(ATTACK_PI, self.params.attack.value() as f64); + self.dsp + .set_param(ATTACK_SHAPE_PI, self.params.attack_shape.value() as f64); + self.dsp + .set_param(RELEASE_PI, self.params.release.value() as f64); + self.dsp + .set_param(RELEASE_SHAPE_PI, self.params.release_shape.value() as f64); + self.dsp + .set_param(RELEASE_HOLD_PI, self.params.release_hold.value() as f64); + self.dsp.set_param(KNEE_PI, self.params.knee.value() as f64); + self.dsp.set_param(LINK_PI, self.params.link.value() as f64); + self.dsp.set_param( + ADAPTIVE_RELEASE_PI, + self.params.adaptive_release.value() as f64, + ); + self.dsp + .set_param(LOOKAHEAD_PI, self.params.lookahead.value() as f64); + self.dsp + .set_param(OUTPUT_GAIN_PI, self.params.output_gain.value() as f64); + + self.dsp.compute( + count, + &self.accum_buffer.slice2d(), + &mut [ + &mut self.temp_output_buffer_l, + &mut self.temp_output_buffer_r, + ], + ); + + for i in 0..count as usize { + output[0][i] = self.temp_output_buffer_l[i] as f32; + output[1][i] = self.temp_output_buffer_r[i] as f32; + } - let latency_samples = self.dsp.get_param(LATENCY_PI).expect("no latency read") as u32; - context.set_latency_samples(latency_samples); + let latency_samples = self.dsp.get_param(LATENCY_PI).expect("no latency read") as u32; + context.set_latency_samples(latency_samples); - ProcessStatus::Normal - } + ProcessStatus::Normal + } } impl ClapPlugin for Lamb {