Skip to content

Commit

Permalink
WIP: Update Spectral Compressor for upstream vizia changes
Browse files Browse the repository at this point in the history
This compiles, but the positioning isn't quite right.
  • Loading branch information
robbert-vdh committed Dec 30, 2023
1 parent 0dd58cd commit 99d853c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 49 deletions.
66 changes: 28 additions & 38 deletions plugins/spectral_compressor/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,49 +179,39 @@ fn main_column(cx: &mut Context) {
// We don't want to show the 'Upwards' prefix here, but it should still be in
// the parameter name so the parameter list makes sense
let upwards_compressor_params = Data::params.map(|p| p.compressors.upwards.clone());
GenericUi::new_custom(
cx,
upwards_compressor_params.clone(),
move |cx, param_ptr| {
let upwards_compressor_params = upwards_compressor_params.clone();
HStack::new(cx, move |cx| {
Label::new(
cx,
unsafe { param_ptr.name() }
.strip_prefix("Upwards ")
.expect("Expected parameter name prefix, this is a bug"),
)
.class("label");

GenericUi::draw_widget(cx, upwards_compressor_params, param_ptr);
})
.class("row");
},
);
GenericUi::new_custom(cx, upwards_compressor_params, |cx, param_ptr| {
HStack::new(cx, |cx| {
Label::new(
cx,
unsafe { param_ptr.name() }
.strip_prefix("Upwards ")
.expect("Expected parameter name prefix, this is a bug"),
)
.class("label");

GenericUi::draw_widget(cx, upwards_compressor_params, param_ptr);
})
.class("row");
});
});

make_column(cx, "Downwards", |cx| {
let downwards_compressor_params =
Data::params.map(|p| p.compressors.downwards.clone());
GenericUi::new_custom(
cx,
downwards_compressor_params.clone(),
move |cx, param_ptr| {
let downwards_compressor_params = downwards_compressor_params.clone();
HStack::new(cx, move |cx| {
Label::new(
cx,
unsafe { param_ptr.name() }
.strip_prefix("Downwards ")
.expect("Expected parameter name prefix, this is a bug"),
)
.class("label");

GenericUi::draw_widget(cx, downwards_compressor_params, param_ptr);
})
.class("row");
},
);
GenericUi::new_custom(cx, downwards_compressor_params, |cx, param_ptr| {
HStack::new(cx, |cx| {
Label::new(
cx,
unsafe { param_ptr.name() }
.strip_prefix("Downwards ")
.expect("Expected parameter name prefix, this is a bug"),
)
.class("label");

GenericUi::draw_widget(cx, downwards_compressor_params, param_ptr);
})
.class("row");
});
});
})
.height(Auto)
Expand Down
14 changes: 5 additions & 9 deletions plugins/spectral_compressor/src/editor/analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,8 @@ impl View for Analyzer {
// TODO: Display the frequency range below the graph

// Draw the border last
let border_width = match cx.border_width() {
Units::Pixels(val) => val,
Units::Percentage(val) => bounds.w.min(bounds.h) * (val / 100.0),
_ => 0.0,
};
let border_color: vg::Color = cx.border_color().cloned().unwrap_or_default().into();
let border_width = cx.border_width();
let border_color: vg::Color = cx.border_color().into();

let mut path = vg::Path::new();
{
Expand Down Expand Up @@ -206,7 +202,7 @@ fn draw_spectrum(

previous_physical_x_coord = physical_x_coord;
}
canvas.stroke_path(&mut bars_path, &bars_paint);
canvas.stroke_path(&bars_path, &bars_paint);

// The mesh path starts at the bottom left, follows the top envelope of the spectrum analyzer,
// and ends in the bottom right
Expand Down Expand Up @@ -249,15 +245,15 @@ fn draw_spectrum(
0.0,
previous_physical_x_coord,
0.0,
&[
[
(0.0, lighter_text_color),
(0.707, text_color),
(1.0, text_color),
],
)
// NOTE: This is very important, otherwise this looks all kinds of gnarly
.with_anti_alias(false);
canvas.fill_path(&mut mesh_path, &mesh_paint);
canvas.fill_path(&mesh_path, &mesh_paint);
}

/// Overlays the threshold curve over the spectrum analyzer. If either the upwards or downwards
Expand Down
4 changes: 2 additions & 2 deletions plugins/spectral_compressor/src/editor/mode_button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ pub struct EditorModeButton {

impl EditorModeButton {
/// Creates a new button bound to the editor mode setting.
pub fn new<L, T>(cx: &mut Context, lens: L, label: impl Res<T>) -> Handle<Self>
pub fn new<L, T>(cx: &mut Context, lens: L, label: impl Res<T> + Clone) -> Handle<Self>
where
L: Lens<Target = Arc<AtomicCell<EditorMode>>>,
T: ToString,
{
Self { mode: lens.get(cx) }
.build(cx, move |cx| {
.build(cx, |cx| {
Label::new(cx, label).hoverable(false);
})
.checked(lens.map(|v| v.load() == EditorMode::AnalyzerVisible))
Expand Down

0 comments on commit 99d853c

Please sign in to comment.