Skip to content

Commit

Permalink
wip range binding
Browse files Browse the repository at this point in the history
  • Loading branch information
magnetophon committed May 8, 2024
1 parent a0a6fa6 commit 6a808d7
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 18 deletions.
31 changes: 30 additions & 1 deletion src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ use cyma::{
visualizers::{Graph, Grid, Meter, UnitRuler},
};

use crate::DBScale;

// to allign the grid with the controls:
const METER_MIN: f32 = -52.3;
const METER_MAX: f32 = 3.05;
Expand All @@ -26,18 +28,40 @@ struct LambData {
gr_buffer_r: Arc<Mutex<MinimaBuffer>>,
show_left: bool,
show_right: bool,
meter_min: f32,
meter_max: f32,
}

impl LambData {}
pub enum AppEvent {
ShowLeft,
ShowRight,
ChangeDbScale,
}
impl Model for LambData {
fn event(&mut self, _cx: &mut EventContext, event: &mut Event) {
event.map(|app_event, _meta| match app_event {
AppEvent::ShowLeft => self.show_left = self.params.show_left.value(),
AppEvent::ShowRight => self.show_right = self.params.show_right.value(),
AppEvent::ChangeDbScale =>
match self.params.db_scale.value() {
DBScale::SixDB => {
self.meter_min = -7.0;
self.meter_max = 1.0
} ,
DBScale::TwelveDB => {
self.meter_min = -14.0;
self.meter_max = 2.0} ,
DBScale::TwentyfourDB => {
self.meter_min = -27.0;
self.meter_max = 2.0},
DBScale::FortyeightDB => {
self.meter_min = METER_MIN;
self.meter_max = METER_MAX},
DBScale::NinetysixDB => {
self.meter_min = -100.0;
self.meter_max = 5.0} ,
}
});
}
}
Expand Down Expand Up @@ -73,6 +97,8 @@ pub(crate) fn create(
gr_buffer_r: gr_buffer_r.clone(),
show_left: true,
show_right: true,
meter_min: METER_MIN,
meter_max: METER_MAX,
}
.build(cx);

Expand Down Expand Up @@ -190,7 +216,10 @@ pub(crate) fn create(
HStack::new(cx, |cx| {
ParamSlider::new(cx, LambData::params, |params| &params.time_scale)
.width(Stretch(1.0));
ParamSlider::new(cx, LambData::params, |params| &params.in_out)
ParamSlider::new(cx, LambData::params, |params| &params.db_scale)
// .on_change(|ex| ex.emit(AppEvent::ChangeDbScale))
.width(Stretch(1.0));
ParamSlider::new(cx, LambData::params, |params| &params.pre_post)
.set_style(ParamSliderStyle::CurrentStepLabeled { even: true })
.width(Stretch(1.0));
HStack::new(cx, |cx| {
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ impl Plugin for Lamb {
.store(false, Ordering::Release);
};

if self.params.in_out.value() {
if self.params.pre_post.value() {
for i in 0..count as usize {
self.level_buffer_l
.lock()
Expand Down
55 changes: 39 additions & 16 deletions src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ struct LambParams {
zoom_mode: EnumParam<ZoomMode>,
#[id = "time_scale"]
time_scale: EnumParam<TimeScale>,
#[id = "in_out"]
in_out: BoolParam,
#[id = "db_scale"]
db_scale: EnumParam<DBScale>,
#[id = "pre_post"]
pre_post: BoolParam,
#[id = "show_left"]
show_left: BoolParam,
#[id = "show_right"]
Expand Down Expand Up @@ -88,6 +90,25 @@ enum TimeScale {
#[name = "32 seconds"]
ThirtytwoSec,
}
// 6,12,24,48,96
#[derive(Enum, Debug, PartialEq)]
enum DBScale {
#[id = "6db"]
#[name = "6 dB"]
SixDB,
#[id = "12db"]
#[name = "12 dB"]
TwelveDB,
#[id = "24db"]
#[name = "24 dB"]
TwentyfourDB,
#[id = "48db"]
#[name = "48 dB"]
FortyeightDB,
#[id = "96"]
#[name = "96 dB"]
NinetysixDB,
}

#[derive(Enum, Debug, PartialEq)]
enum LatencyMode {
Expand Down Expand Up @@ -165,12 +186,12 @@ pub fn ratio_to_strength() -> Arc<dyn Fn(&str) -> Option<f32> + Send + Sync> {
})
}

// .with_value_to_string(bool_to_in_out())
// .with_string_to_value(in_out_to_bool())
// pub fn bool_to_in_out()
// .with_value_to_string(bool_to_pre_post())
// .with_string_to_value(pre_post_to_bool())
// pub fn bool_to_pre_post()

/// Display 'post' or 'pre' depending on whether the parameter is true or false.
pub fn v2s_bool_in_out() -> Arc<dyn Fn(bool) -> String + Send + Sync> {
pub fn v2s_bool_pre_post() -> Arc<dyn Fn(bool) -> String + Send + Sync> {
Arc::new(move |value| {
if value {
String::from("post")
Expand All @@ -180,8 +201,8 @@ pub fn v2s_bool_in_out() -> Arc<dyn Fn(bool) -> String + Send + Sync> {
})
}

/// Parse a string in the same format as [`v2s_bool_in_out()`].
pub fn s2v_bool_in_out() -> Arc<dyn Fn(&str) -> Option<bool> + Send + Sync> {
/// Parse a string in the same format as [`v2s_bool_pre_post()`].
pub fn s2v_bool_pre_post() -> Arc<dyn Fn(&str) -> Option<bool> + Send + Sync> {
Arc::new(|string| {
let string = string.trim();
if string.eq_ignore_ascii_case("post") {
Expand All @@ -194,11 +215,6 @@ pub fn s2v_bool_in_out() -> Arc<dyn Fn(&str) -> Option<bool> + Send + Sync> {
})
}

// impl LambParams {
// impl Default for LambParams {
// fn default() -> Self {
// fn default(should_update_time_scale: Arc<AtomicBool>) -> Self {
// pub fn new(should_update_time_scale: Arc<AtomicBool>) -> Self {
impl LambParams {
pub fn new(should_update_time_scale: Arc<AtomicBool>) -> Self {
Self {
Expand Down Expand Up @@ -347,9 +363,16 @@ impl LambParams {
})
.hide()
.hide_in_generic_ui(),
in_out: BoolParam::new("in_out", true)
.with_value_to_string(v2s_bool_in_out())
.with_string_to_value(s2v_bool_in_out())
db_scale: EnumParam::new("db_scale", DBScale::FortyeightDB)
// .with_callback({
// let should_update_db_scale = should_update_db_scale.clone();
// Arc::new(move |_| should_update_db_scale.store(true, Ordering::Release))
// })
.hide()
.hide_in_generic_ui(),
pre_post: BoolParam::new("pre_post", true)
.with_value_to_string(v2s_bool_pre_post())
.with_string_to_value(s2v_bool_pre_post())
.hide()
.hide_in_generic_ui(),
show_left: BoolParam::new("show_left", true)
Expand Down

0 comments on commit 6a808d7

Please sign in to comment.