Skip to content

Commit

Permalink
tweak GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
magnetophon committed Apr 1, 2024
1 parent 41e1ae2 commit 2a0de42
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 49 deletions.
Binary file modified images/lamb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
70 changes: 35 additions & 35 deletions src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::sync::Arc;
use std::time::Duration;

use crate::LambParams;
use crate::TimeChoice;
use crate::ZoomMode;

include!("gain_reduction_meter.rs");

Expand Down Expand Up @@ -65,7 +65,8 @@ pub(crate) fn create(
VStack::new(cx, |cx| {
Label::new(cx, "input gain");
ParamSlider::new(cx, LambData::params, |params| &params.input_gain)
.bottom(Pixels(6.0));
.bottom(Pixels(6.0))
;
// level + time
HStack::new(cx, |cx| {
// level
Expand All @@ -84,11 +85,11 @@ pub(crate) fn create(
Label::new(cx, "link");
ParamSlider::new(cx, LambData::params, |params| &params.link);
})
.child_left(Stretch(1.0))
.child_right(Stretch(1.0))
.width(Percentage(47.5))
.right(Percentage(2.5)); // level
// time
.child_left(Stretch(1.0))
.child_right(Stretch(1.0))
.width(Percentage(47.5))
.right(Percentage(2.5)); // level
// time
VStack::new(cx, |cx| {
Label::new(cx, "attack");
ParamSlider::new(cx, LambData::params, |params| &params.attack);
Expand All @@ -102,32 +103,38 @@ pub(crate) fn create(
Label::new(cx, "release hold");
ParamSlider::new(cx, LambData::params, |params| &params.release_hold);
})
.child_left(Stretch(1.0))
.child_right(Stretch(1.0))
.width(Percentage(47.5))
.left(Percentage(2.5)); // time
.child_left(Stretch(1.0))
.child_right(Stretch(1.0))
.width(Percentage(47.5))
.left(Percentage(2.5)); // time
})
.width(Percentage(100.0)); // level + time
.width(Percentage(100.0)); // level + time

Label::new(cx, "output gain");
ParamSlider::new(cx, LambData::params, |params| &params.output_gain)
.bottom(Pixels(6.0));
})
.width(Percentage(100.0/3.0))
.width(Percentage(200.0 / 5.0))
.child_left(Stretch(1.0))
.child_right(Stretch(1.0)); // parameters
// graph + zoom
VStack::new(cx, |cx| {
// Label::new(cx, "attack release");
Label::new(cx, ""); // spacer
VStack::new(cx, |cx| {
Label::new(cx, "zoom mode");
ParamSlider::new(cx, LambData::params, |params| &params.zoom_mode)
.set_style(ParamSliderStyle::CurrentStepLabeled { even: true })
.bottom(Pixels(6.0));
Label::new(cx, ""); // spacer
AttackReleaseGraph::new(cx, LambData::params);
})
.child_left(Stretch(1.0))
.child_right(Stretch(1.0))
.left(Percentage(5.0));
})
.width(Percentage(200.0/3.0))
.height(Percentage(100.0))
; // graph + zoom
.width(Percentage(300.0 / 5.0))
.height(Percentage(100.0)); // graph + zoom
})
.width(Percentage(100.0))
; // parameters + graph
.width(Percentage(100.0)); // parameters + graph

// meters
VStack::new(cx, |cx| {
Expand Down Expand Up @@ -204,7 +211,7 @@ impl<AttackReleaseDataL: Lens<Target = Arc<LambParams>>> View
let attack_shape = self.attack_release_data.get(cx).attack_shape.value();
let release = self.attack_release_data.get(cx).release.value();
let release_shape = self.attack_release_data.get(cx).release_shape.value();
let time_choice = self.attack_release_data.get(cx).time_choice.value();
let zoom_mode = self.attack_release_data.get(cx).zoom_mode.value();

// let background_color = cx.background_color();
let border_color = cx.border_color();
Expand All @@ -217,7 +224,7 @@ impl<AttackReleaseDataL: Lens<Target = Arc<LambParams>>> View
// let border_width = cx.scale_factor() * cx.border_width();
let border_width = cx.border_width();

let rounding = 0.0 * border_width;
let rounding = 3.0 * border_width;

// Create a new `Path` from the `vg` module.
let mut path = vg::Path::new();
Expand Down Expand Up @@ -263,20 +270,19 @@ impl<AttackReleaseDataL: Lens<Target = Arc<LambParams>>> View
// add the attack / release curve
canvas.stroke_path(
&{

let x = bounds.x + border_width * 1.0;
let y = bounds.y + border_width * 1.5;
let w = bounds.w - border_width * 2.0;
let h = bounds.h - border_width * 3.0;
let center = match time_choice {
TimeChoice::Shape => w * 0.5,
TimeChoice::Relative => w * attack / (attack + release),
TimeChoice::Absolute => w * max_attack / (max_attack + max_release),
let center = match zoom_mode {
ZoomMode::Shape => w * 0.5,
ZoomMode::Relative => w * attack / (attack + release),
ZoomMode::Absolute => w * max_attack / (max_attack + max_release),
};

let mut start = 0.0;
let mut end = w;
if time_choice == TimeChoice::Absolute {
if zoom_mode == ZoomMode::Absolute {
start = ((max_attack - attack) / max_attack) * center;
end = center + ((release / max_release) * (w - center));
}
Expand Down Expand Up @@ -311,13 +317,7 @@ impl<AttackReleaseDataL: Lens<Target = Arc<LambParams>>> View
canvas.stroke_path(
&{
let mut path = vg::Path::new();
path.rounded_rect(
x,
y,
w,
h,
rounding,
);
path.rounded_rect(x, y, w, h, rounding);
path
},
// &vg::Paint::color(cx.font_color().into())
Expand Down
3 changes: 2 additions & 1 deletion src/gain_reduction_meter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const MAX_TICK: f32 = 0.0;
/// The ticks that will be shown beneath the peak meter's bar. The first value is shown as
/// -infinity, and at the last position we'll draw the `dBFS` string.
// const TEXT_TICKS: [i32; 6] = [-80, -60, -40, -20, 0, 12];
const TEXT_TICKS: [i32; 5] = [-24, -18, -12, -6, 0];
// const TEXT_TICKS: [i32; 5] = [-24, -18, -12, -6, 0];
const TEXT_TICKS: [i32; 9] = [-24, -21, -18, -15, -12, -9, -6, -3, 0];

/// A simple horizontal peak meter.
///
Expand Down
10 changes: 5 additions & 5 deletions src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ struct LambParams {
link: FloatParam,
#[id = "output_gain"]
output_gain: FloatParam,
#[id = "time_choice"]
time_choice: EnumParam<TimeChoice>,
#[id = "zoom_mode"]
zoom_mode: EnumParam<ZoomMode>,
/// The editor state, saved together with the parameter state so the custom scaling can be
/// restored.
#[persist = "editor-state"]
editor_state: Arc<ViziaState>,
}

#[derive(Enum, Debug, PartialEq)]
enum TimeChoice {
enum ZoomMode {
/// Don't show the length of the envelope, just the shape
#[id = "shape"]
#[name = "shape"]
Expand Down Expand Up @@ -98,7 +98,7 @@ impl Default for LambParams {
output_gain: FloatParam::new("output_gain", 0.0, FloatRange::Linear { min: -24.0, max: 24.0})
.with_unit(" dB")
.with_step_size(0.1),
time_choice: EnumParam::new("time_choice", TimeChoice::Relative),
zoom_mode: EnumParam::new("zoom_mode", ZoomMode::Relative),
}
}
}
Expand All @@ -118,4 +118,4 @@ pub const OUTPUT_GAIN_PI: ParamIndex = ParamIndex(11);
pub const GAIN_REDUCTION_LEFT_PI: ParamIndex = ParamIndex(12);
pub const GAIN_REDUCTION_RIGHT_PI: ParamIndex = ParamIndex(13);
pub const LATENCY_PI: ParamIndex = ParamIndex(14);
pub const TIME_CHOICE_PI: ParamIndex = ParamIndex(15);
pub const ZOOM_MODE_PI: ParamIndex = ParamIndex(15);
10 changes: 2 additions & 8 deletions src/style.css
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@

attack-release-graph {
/* height: 100%; */
/* width: 100%; */
width: 100%;
outline-color: #0a0a0a;
border-color: #696969;
/* outline-color: #696969; */
/* border-color: #0a0a0a; */
border-width: 1px;
background-color: transparent;
/* top: 20px; */
border-width: 1px;
bottom: 5px;
left: 5%;
}
label {
top: 7px;
Expand Down

0 comments on commit 2a0de42

Please sign in to comment.