Skip to content

Commit

Permalink
put input and output meters in delay graph
Browse files Browse the repository at this point in the history
  • Loading branch information
magnetophon committed Nov 15, 2024
1 parent 9f798b5 commit dc67eef
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 92 deletions.
87 changes: 58 additions & 29 deletions src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@ use nih_plug_vizia::{
};

use crate::{
editor::dual_meter::DualMeter, util, AtomicBoolArray, AtomicByteArray, AtomicF32,
AtomicF32Array, Del2Params, LastPlayedNotes, CLEAR_TAPS, LEARNING, LOCK_TAPS, MUTE_IN,
MUTE_OUT, NO_LEARNED_NOTE,
util, AtomicBoolArray, AtomicByteArray, AtomicF32, AtomicF32Array, Del2Params, LastPlayedNotes,
CLEAR_TAPS, LEARNING, LOCK_TAPS, MUTE_IN, MUTE_OUT, NO_LEARNED_NOTE,
};

mod dual_meter;

const ZOOM_SMOOTH_POLE: f32 = 0.915;

/// The minimum decibel value that the meters display
Expand Down Expand Up @@ -342,33 +339,11 @@ pub fn create(editor_data: Data, editor_state: Arc<ViziaState>) -> Option<Box<dy
.class("parameters");
VStack::new(cx, |cx| {
ZStack::new(cx, |cx| {
DelayGraph::new(cx, Data::params, Data::tap_meters)
DelayGraph::new(cx, Data::params, Data::tap_meters, Data::input_meter, Data::output_meter)
// .overflow(Overflow::Hidden)
;
Label::new(cx, "DEL2").class("plugin-name");
});
VStack::new(cx, |cx| {
//meters
HStack::new(cx, |cx| {
VStack::new(cx, |cx| {
Label::new(cx, "in").class("peak-meter-label");
Label::new(cx, "out").class("peak-meter-label");
})
.class("peak-meter-label-group");
DualMeter::new(
cx,
Data::input_meter.map(|input_meter| {
util::gain_to_db(input_meter.load(Ordering::Relaxed))
}),
Data::output_meter.map(|output_meter| {
util::gain_to_db(output_meter.load(Ordering::Relaxed))
}),
Some(Duration::from_millis(600)),
);
})
.class("peak-meter-plus-label-group");
})
.class("peak-meter-group");
ResizeHandle::new(cx);
});
});
Expand All @@ -382,6 +357,8 @@ pub fn create(editor_data: Data, editor_state: Arc<ViziaState>) -> Option<Box<dy
pub struct DelayGraph {
params: Arc<Del2Params>,
tap_meters: Arc<AtomicF32Array>,
input_meter: Arc<AtomicF32>,
output_meter: Arc<AtomicF32>,
}

// TODO: add grid to show bars & beats
Expand All @@ -405,6 +382,8 @@ impl View for DelayGraph {
let border_width = draw_context.border_width();
let outline_width = draw_context.outline_width();
let tap_meters = self.tap_meters.clone();
let input_meter = self.input_meter.clone();
let output_meter = self.output_meter.clone();

// Compute the time scaling factor
let target_time_scaling_factor = Self::compute_time_scaling_factor(
Expand Down Expand Up @@ -447,6 +426,8 @@ impl View for DelayGraph {
canvas,
params.clone(),
tap_meters.clone(),
input_meter.clone(),
output_meter.clone(),
bounds,
outline_color,
border_color,
Expand All @@ -471,18 +452,24 @@ impl View for DelayGraph {
}

impl DelayGraph {
fn new<ParamsL, TapMetersL>(
fn new<ParamsL, TapMetersL, InputMeterL, OutputMeterL>(
cx: &mut Context,
params: ParamsL,
tap_meters: TapMetersL,
input_meter: InputMeterL,
output_meter: OutputMeterL,
) -> Handle<Self>
where
ParamsL: Lens<Target = Arc<Del2Params>>,
TapMetersL: Lens<Target = Arc<AtomicF32Array>>,
InputMeterL: Lens<Target = Arc<AtomicF32>>,
OutputMeterL: Lens<Target = Arc<AtomicF32>>,
{
Self {
params: params.get(cx),
tap_meters: tap_meters.get(cx),
input_meter: input_meter.get(cx),
output_meter: output_meter.get(cx),
}
.build(cx, |cx| {
Label::new(
Expand Down Expand Up @@ -593,6 +580,8 @@ impl DelayGraph {
canvas: &mut Canvas,
params: Arc<Del2Params>,
tap_meters: Arc<AtomicF32Array>,
input_meter: Arc<AtomicF32>,
output_meter: Arc<AtomicF32>,
bounds: BoundingBox,
velocity_color: vg::Color,
meter_color: vg::Color,
Expand Down Expand Up @@ -644,6 +633,46 @@ impl DelayGraph {
&vg::Paint::color(meter_color).with_line_width(line_width * 1.5),
);
}

// Draw input_meter to the far left
let input_db = util::gain_to_db(input_meter.load(std::sync::atomic::Ordering::Relaxed));
let input_height = {
let tick_fraction = (input_db - MIN_TICK) / (MAX_TICK - MIN_TICK);
(tick_fraction * bounds.h).max(0.0)
};
let mut path = vg::Path::new();
path.move_to(
bounds.x + border_width + 0.5 * line_width,
bounds.y + bounds.h - input_height,
);
path.line_to(
bounds.x + border_width + 0.5 * line_width,
bounds.y + bounds.h,
);
canvas.stroke_path(
&path,
&vg::Paint::color(meter_color).with_line_width(line_width),
);

// Draw output_meter to the far right
let output_db = util::gain_to_db(output_meter.load(std::sync::atomic::Ordering::Relaxed));
let output_height = {
let tick_fraction = (output_db - MIN_TICK) / (MAX_TICK - MIN_TICK);
(tick_fraction * bounds.h).max(0.0)
};
path = vg::Path::new();
path.move_to(
bounds.x + bounds.w - border_width - 0.5 * line_width,
bounds.y + bounds.h - output_height,
);
path.line_to(
bounds.x + bounds.w - border_width - 0.5 * line_width,
bounds.y + bounds.h,
);
canvas.stroke_path(
&path,
&vg::Paint::color(meter_color).with_line_width(line_width),
);
}

fn draw_tap_notes_and_pans(
Expand Down
11 changes: 3 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1011,23 +1011,18 @@ impl Plugin for Del2 {
let right = self.delayed_audio_r[tap_index][sample_idx] * post_filter_gain;
output[0][sample_idx] += left;
output[1][sample_idx] += right;
amplitude += left.abs(); // + right.abs();
amplitude += left.abs() + right.abs();
}

if self.params.editor_state.is_open() {
let weight = self.peak_meter_decay_weight * 0.93; // TODO: way too slow without this, why is that?
amplitude = (amplitude / block_len as f32).abs();
let current_peak_meter =
self.tap_meters[tap_index].load(std::sync::atomic::Ordering::Relaxed);
let new_peak_meter = if amplitude > current_peak_meter {
amplitude
} else {
// println!("self.peak_meter_decay_weight: {}",self.peak_meter_decay_weight);

current_peak_meter.mul_add(0.8, amplitude * (1.0 - 0.8))
// current_peak_meter.mul_add(
// self.peak_meter_decay_weight,
// amplitude * (1.0 - self.peak_meter_decay_weight),
// )
current_peak_meter.mul_add(weight, amplitude * (1.0 - weight))
};

self.tap_meters[tap_index]
Expand Down
56 changes: 1 addition & 55 deletions src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ param-slider .value-entry {

delay-graph {
top: 9px;
bottom: 14px;
right: 9px;
border-width: 1px;
outline-width: 5px;
Expand Down Expand Up @@ -125,11 +126,6 @@ generic-ui {
child-right: 0px;
}

/* generic-ui .row { */
/* col-between: 6px; */
/* height: auto; */
/* layout-type: row; */
/* } */
.row {
height: 30px;
layout-type: row;
Expand All @@ -156,53 +152,3 @@ generic-ui .label {
top: 1s;
bottom: 1s;
}

.peak-meter-group {
height: 85px;
left: 0px;
right: 9px;
top: 3px;
bottom: 0px;
}

dual-meter {
/* width: 584px; */
width: 1s;
height: 25px;
color: #e0ce91;
left: 0px;
bottom: 0px;
}

dual-meter .bar {
height: 50%;
border-width: 1px;
outline-width: 1.3px;
border-color: #4e4e4e;
color: #e0ce91;
top: 13px;
}

dual-meter .ticks {
height: 50%;
}
dual-meter .ticks__tick {
top: 0px;
width: 1px;
height: 30%;
}
dual-meter .ticks__label {
top: 4px; /* In pixels in an attempt to get this to better align to the grid */
font-size: 13;
}
.peak-meter-label {
left: 0px;
}

.peak-meter-label-group {
right: 9px;
top: 2px;
bottom: 22px;
font-size: 16;
width: 29px;
}

0 comments on commit dc67eef

Please sign in to comment.