Skip to content

Commit

Permalink
added TextMarkGroup to widgets, renamed DBRange to LogDBRange, fixed …
Browse files Browse the repository at this point in the history
…bugs
  • Loading branch information
BillyDM committed Jul 29, 2020
1 parent 073256c commit bac4c75
Show file tree
Hide file tree
Showing 52 changed files with 1,834 additions and 296 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Take a look at the [roadmap] for a list of planned widgets.
## Each parameter can be mapped to one of four ranges:
* `FloatRange` - a linear range of f32 values
* `IntRange` - a discrete range of i32 values. This will cause the widget to "step" when moved.
* `DBRange` - a logarithmic range of decibel values. Values around 0 dB will increment slower than values farther away from 0 dB.
* `LogDBRange` - a logarithmic range of decibel values. Values around 0 dB will increment slower than values farther away from 0 dB.
* `FreqRange` - a logarithmic range of frequency values. Each octave in the 10 octave spectrum (from 20 Hz to 20480 Hz) is spaced evenly.

## Run examples with
Expand All @@ -50,7 +50,7 @@ cargo run --package phase_meter --release
Add `iced` and `iced_audio` as dependencies in your `Cargo.toml`:
```toml
iced = { version = "0.1", features = ["image"] }
iced_audio = "0.3"
iced_audio = "0.4"
```
Or to use the GitHub version of `iced`:
```toml
Expand All @@ -69,7 +69,7 @@ use iced::{
};
// Import iced_audio modules.
use iced_audio::{
h_slider, knob, v_slider, xy_pad, DBRange, FloatRange, FreqRange, HSlider,
h_slider, knob, v_slider, xy_pad, LogDBRange, FloatRange, FreqRange, HSlider,
IntRange, Knob, TickMark, TickMarkGroup, TickMarkTier, VSlider, XYPad,
};

Expand Down Expand Up @@ -103,14 +103,14 @@ pub struct App {
// * FloatRange - a linear range of f32 values
// * IntRange - a discrete range of i32 values. This will cause the widget
// to "step" when moved.
// * DBRange - a logarithmic range of decibel values. Values around 0 dB
// * LogDBRange - a logarithmic range of decibel values. Values around 0 dB
// will increment slower than values farther away from 0 dB.
// * FreqRange - a logarithmic range of frequency values. Each octave in
// the 10 octave spectrum (from 20 Hz to 20480 Hz) is spaced evenly.
//
float_range: FloatRange,
int_range: IntRange,
db_range: DBRange,
db_range: LogDBRange,
freq_range: FreqRange,

// The states of the widgets that will control the parameters.
Expand All @@ -135,7 +135,7 @@ impl Sandbox for App {
// Initalize each range:
let float_range = FloatRange::default_bipolar();
let int_range = IntRange::new(0, 10);
let db_range = DBRange::new(-12.0, 12.0, 0.5.into());
let db_range = LogDBRange::new(-12.0, 12.0, 0.5.into());
let freq_range = FreqRange::default();

App {
Expand Down
163 changes: 117 additions & 46 deletions examples/db_meter/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use iced::{
executor, Application, Color, Column, Command, Container, Element, Length,
Row, Settings, Subscription, Text,
executor, Application, Color, Column, Command, Container, Element, Font,
Length, Row, Settings, Subscription, Text,
};

use iced_audio::{
bar_tick_marks, db_meter, knob, DBMeter, DBRange, Knob, TickMark,
TickMarkGroup, TickMarkTier,
bar_text_marks, bar_tick_marks, db_meter, knob, DBMeter, FloatRange, Knob,
TextMark, TextMarkGroup, TickMark, TickMarkGroup, TickMarkTier,
};

use std::time::Instant;
Expand Down Expand Up @@ -35,7 +35,9 @@ enum Message {

struct DBMeterApp {
#[allow(dead_code)]
db_range: DBRange,
// Not to be confused with `LogDBRange` for use with controls.
// Decibel meters usually display decibels linearly.
linear_db_range: FloatRange,

left_main_db_knob_state: knob::State<ParamID>,
left_peak_db_knob_state: knob::State<ParamID>,
Expand All @@ -46,6 +48,7 @@ struct DBMeterApp {
db_meter_custom_state: db_meter::State,

tick_marks: TickMarkGroup,
text_marks: TextMarkGroup,

current: Instant,
}
Expand All @@ -62,74 +65,128 @@ impl Application for DBMeterApp {
type Flags = ();

fn new(_flags: ()) -> (Self, Command<Message>) {
let db_range = DBRange::new(-64.0, 3.0, 0.9.into());
// Not to be confused with `LogDBRange` for use with controls.
// Decibel meters usually display decibels linearly.
let linear_db_range = FloatRange::new(-50.0, 3.0);

(
DBMeterApp {
db_range,
linear_db_range,

left_main_db_knob_state: knob::State::new(
db_range.create_param(ParamID::LeftMainDB, -64.0, -64.0),
linear_db_range.create_param(
ParamID::LeftMainDB,
-50.0,
-50.0,
),
),
left_peak_db_knob_state: knob::State::new(
db_range.create_param(ParamID::LeftPeakDB, -64.0, -64.0),
linear_db_range.create_param(
ParamID::LeftPeakDB,
-50.0,
-50.0,
),
),
right_main_db_knob_state: knob::State::new(
db_range.create_param(ParamID::RightMainDB, -64.0, -64.0),
linear_db_range.create_param(
ParamID::RightMainDB,
-50.0,
-50.0,
),
),
right_peak_db_knob_state: knob::State::new(
db_range.create_param(ParamID::RightPeakDB, -64.0, -64.0),
linear_db_range.create_param(
ParamID::RightPeakDB,
-50.0,
-50.0,
),
),

db_meter_state: db_meter::State::new(
db_meter::BarState::default(),
Some(db_meter::BarState::default()),
db_meter::TierPositions {
clipping: db_range.to_normal(0.0),
med: Some(db_range.to_normal(-12.0)),
high: Some(db_range.to_normal(-3.0)),
clipping: linear_db_range.to_normal(0.0),
med: Some(linear_db_range.to_normal(-18.0)),
high: Some(linear_db_range.to_normal(-6.0)),
},
),

db_meter_custom_state: db_meter::State::new(
db_meter::BarState::default(),
None,
db_meter::TierPositions {
clipping: db_range.to_normal(0.0),
clipping: linear_db_range.to_normal(0.0),
med: None,
high: Some(db_range.to_normal(-6.0)),
high: Some(linear_db_range.to_normal(-12.0)),
},
),

tick_marks: TickMarkGroup::new(vec![
TickMark {
position: db_range.to_normal(0.0),
tier: TickMarkTier::One,
},
TickMark {
position: db_range.to_normal(-3.0),
tier: TickMarkTier::Two,
},
TickMark {
position: db_range.to_normal(-6.0),
tier: TickMarkTier::Two,
},
TickMark {
position: db_range.to_normal(-9.0),
tier: TickMarkTier::Two,
},
TickMark {
position: db_range.to_normal(-12.0),
tier: TickMarkTier::Two,
},
TickMark {
position: db_range.to_normal(-24.0),
tier: TickMarkTier::Two,
},
TickMark {
position: db_range.to_normal(-48.0),
tier: TickMarkTier::Two,
},
TickMark::new(
linear_db_range.to_normal(0.0),
TickMarkTier::One,
),
TickMark::new(
linear_db_range.to_normal(-3.0),
TickMarkTier::Two,
),
TickMark::new(
linear_db_range.to_normal(-6.0),
TickMarkTier::Two,
),
TickMark::new(
linear_db_range.to_normal(-9.0),
TickMarkTier::Two,
),
TickMark::new(
linear_db_range.to_normal(-12.0),
TickMarkTier::Two,
),
TickMark::new(
linear_db_range.to_normal(-15.0),
TickMarkTier::Two,
),
TickMark::new(
linear_db_range.to_normal(-18.0),
TickMarkTier::Two,
),
TickMark::new(
linear_db_range.to_normal(-21.0),
TickMarkTier::Two,
),
TickMark::new(
linear_db_range.to_normal(-24.0),
TickMarkTier::Two,
),
TickMark::new(
linear_db_range.to_normal(-30.0),
TickMarkTier::Two,
),
TickMark::new(
linear_db_range.to_normal(-36.0),
TickMarkTier::Two,
),
TickMark::new(
linear_db_range.to_normal(-42.0),
TickMarkTier::Two,
),
TickMark::new(
linear_db_range.to_normal(-48.0),
TickMarkTier::Two,
),
]),

text_marks: TextMarkGroup::new(vec![
TextMark::new("0", linear_db_range.to_normal(0.0)),
TextMark::new("-6", linear_db_range.to_normal(-6.0)),
TextMark::new("-12", linear_db_range.to_normal(-12.0)),
TextMark::new("-18", linear_db_range.to_normal(-18.0)),
TextMark::new("-24", linear_db_range.to_normal(-24.0)),
TextMark::new("-30", linear_db_range.to_normal(-30.0)),
TextMark::new("-36", linear_db_range.to_normal(-36.0)),
TextMark::new("-42", linear_db_range.to_normal(-42.0)),
TextMark::new("-48", linear_db_range.to_normal(-48.0)),
]),

current: Instant::now(),
Expand Down Expand Up @@ -192,13 +249,15 @@ impl Application for DBMeterApp {
let right_peak_knob =
Knob::new(&mut self.right_peak_db_knob_state, Message::ParamMoved);

let db_meter =
DBMeter::new(&mut self.db_meter_state).tick_marks(&self.tick_marks);
let db_meter = DBMeter::new(&mut self.db_meter_state)
.tick_marks(&self.tick_marks)
.text_marks(&self.text_marks);

let db_meter_custom = DBMeter::new(&mut self.db_meter_custom_state)
.orientation(db_meter::Orientation::Horizontal)
.height(Length::from(Length::Units(24)))
.tick_marks(&self.tick_marks)
.text_marks(&self.text_marks)
.style(CustomDBMeterStyle);

let row = Row::new()
Expand Down Expand Up @@ -352,4 +411,16 @@ impl db_meter::StyleSheet for CustomDBMeterStyle {
placement: bar_tick_marks::Placement::RightOrBottom,
})
}

fn text_mark_style(&self) -> Option<bar_text_marks::Style> {
Some(bar_text_marks::Style {
color: BORDER_COLOR,
offset: 8,
text_size: 12,
font: Font::Default,
bounds_width: 30,
bounds_height: 14,
placement: bar_text_marks::Placement::RightOrBottom,
})
}
}
Loading

0 comments on commit bac4c75

Please sign in to comment.