4 releases

0.1.3 Nov 26, 2020
0.1.2 Nov 24, 2020
0.1.1 Nov 18, 2020
0.1.0 Oct 29, 2020

#1728 in Algorithms


Used in audio-widgets

MIT/Apache

40KB
1K SLoC

Scales

Build Status Current Crates.io Version

A utility library for converting values between scales.

What does it do?

It provides reusable converters that make translating ranged values from one scale to another easy. Imagine you have a slider in your UI that has a linear internal value but it controls a logarithmic parameter. Normally you would be doing something like this:

let relative = (slider.value() - slider.min()) / (slider.max() - slider.min());
let log_range = parameter.max().log10() - parameter.min().log10();
let exp = parameter.min().log10() + relative * log_range;
let new_value = 10f64.powf(exp);
parameter.set(new_value);

Using scales you can reduce that to:

let new_value = (&slider_scale, &parameter_scale).convert(slider.value());
parameter.set(new_value);

where slider_scale and parameter_scale are reusable components that look like this:

let slider_scale = LinearScale::new(slider.min(), slider.max());
let parameter_scale = LogarithmicScale::new(parameter.min(), parameter.max());

Early development status!

Expect breaking changes anytime!

No runtime deps