Merge origin/main into better-icons
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
3ac96fea35
16 files changed
+503
-18
No files matched your search
@@ -0,0 +1,36 @@
|
||||
// Peak meter display: maps a linear sample peak to the bar position and
|
||||
// lets the bar fall back smoothly instead of flickering.
|
||||
|
||||
///|
|
||||
/// How much of the full bar a falling meter drops per update (~25 updates
|
||||
/// per second, so silence empties a full bar in about a second).
|
||||
pub const METER_DECAY : Double = 0.04
|
||||
|
||||
///|
|
||||
/// Bar position 0..1 for a linear peak. Uses the same cubic curve as the
|
||||
/// volume sliders, so a full-scale signal at 50% volume shows at half the bar
|
||||
/// and quiet sounds are still visible.
|
||||
pub fn meter_level(linear_peak : Double) -> Double {
|
||||
if linear_peak <= 0.0 {
|
||||
0.0
|
||||
} else if linear_peak >= 1.0 {
|
||||
1.0
|
||||
} else {
|
||||
@math.cbrt(linear_peak)
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
/// Next bar position: jump up at once, fall by at most METER_DECAY.
|
||||
pub fn meter_step(shown : Double, level : Double) -> Double {
|
||||
if level >= shown {
|
||||
level
|
||||
} else {
|
||||
let fallen = shown - METER_DECAY
|
||||
if fallen > level {
|
||||
fallen
|
||||
} else {
|
||||
level
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
///|
|
||||
test "meter_level uses the cubic volume curve and clamps" {
|
||||
assert_eq(@model.meter_level(0.0), 0.0)
|
||||
assert_eq(@model.meter_level(-0.5), 0.0)
|
||||
assert_eq(@model.meter_level(1.0), 1.0)
|
||||
assert_eq(@model.meter_level(1.7), 1.0)
|
||||
assert_true((@model.meter_level(0.125) - 0.5).abs() < 1.0e-9)
|
||||
}
|
||||
|
||||
///|
|
||||
test "meter_step rises at once and decays slowly" {
|
||||
assert_eq(@model.meter_step(0.2, 0.9), 0.9)
|
||||
assert_true(
|
||||
(@model.meter_step(0.9, 0.0) - (0.9 - @model.METER_DECAY)).abs() < 1.0e-9,
|
||||
)
|
||||
assert_eq(@model.meter_step(0.5, 0.48), 0.48)
|
||||
assert_eq(@model.meter_step(0.01, 0.0), 0.0)
|
||||
}
|
||||
@@ -12,6 +12,8 @@ pub const ICON_MISSING : String = "image-missing"
|
||||
|
||||
pub const MAX_PERCENT : Double = 150.0
|
||||
|
||||
pub const METER_DECAY : Double = 0.04
|
||||
|
||||
pub const NORM_PERCENT : Double = 100.0
|
||||
|
||||
pub fn clamp_percent(Double) -> Double
|
||||
@@ -46,6 +48,10 @@ pub fn linear_to_percent(Double) -> Double
|
||||
|
||||
pub fn linked_percent(Array[Double]) -> Double
|
||||
|
||||
pub fn meter_level(Double) -> Double
|
||||
|
||||
pub fn meter_step(Double, Double) -> Double
|
||||
|
||||
pub fn percent_to_linear(Double) -> Double
|
||||
|
||||
pub fn rows(State, Tab) -> Array[Row]
|
||||
|
||||
Reference in new issue
Block a user