pub struct RampedStatesMap { /* private fields */ }
Expand description
A simple implementation of a BufferStates
that allows
for parameters to change between the start and end of a buffer.
Each parameter can be either constant or ramped between two values.
For numeric parameters, the ramp is linear, for other parameter types the value changes half-way through the buffer.
Implementations§
Source§impl RampedStatesMap
impl RampedStatesMap
Sourcepub fn new<'a, S: AsRef<str> + 'a, H: BuildHasher, H_: BuildHasher>(
infos: impl IntoIterator<Item = InfoRef<'a, S>> + 'a,
start_overrides: &HashMap<&str, InternalValue, H>,
end_overrides: &HashMap<&str, InternalValue, H_>,
buffer_size: usize,
) -> Self
pub fn new<'a, S: AsRef<str> + 'a, H: BuildHasher, H_: BuildHasher>( infos: impl IntoIterator<Item = InfoRef<'a, S>> + 'a, start_overrides: &HashMap<&str, InternalValue, H>, end_overrides: &HashMap<&str, InternalValue, H_>, buffer_size: usize, ) -> Self
Constructor that creates a RampedStatesMap
from a list of Info
s and override
s.at the start and end of the buffer.
These overrides work the same way as in override_defaults
.
Note that if you want to pass this into a synth, you should use Self::new_synth
instead.
§Examples
let infos = vec![
StaticInfoRef {
title: "Numeric",
short_title: "Numeric",
unique_id: "numeric",
flags: Default::default(),
type_specific: TypeSpecificInfoRef::Numeric {
default: 0.0,
valid_range: 0.0..=1.0,
units: None,
},
},
];
let start_overrides: HashMap<_, _> = vec![].into_iter().collect();
let end_overrides: HashMap<_, _> = vec![("numeric", InternalValue::Numeric(0.5))].into_iter().collect();
let states = RampedStatesMap::new(infos.iter().cloned(), &start_overrides, &end_overrides, 10);
match states.get_numeric("numeric") {
Some(NumericBufferState::PiecewiseLinear(_)) => (),
_ => panic!("Expected a ramped value"),
};
§Panics
Panics if start_overrides
or end_overrides
do not match the type of the parameter
specified in infos
.
Also panics if any of the enum parameters in infos
has a number of values
that will not fit into a u32
.
Sourcepub fn new_synth<'a, 'b: 'a>(
infos: impl IntoIterator<Item = InfoRef<'a, &'b str>> + 'a,
start_overrides: &HashMap<&str, InternalValue>,
end_overrides: &HashMap<&str, InternalValue>,
buffer_size: usize,
) -> Self
pub fn new_synth<'a, 'b: 'a>( infos: impl IntoIterator<Item = InfoRef<'a, &'b str>> + 'a, start_overrides: &HashMap<&str, InternalValue>, end_overrides: &HashMap<&str, InternalValue>, buffer_size: usize, ) -> Self
Create a new RampedStatesMap
for synths from a list of Info
s and override
s.
This is similar to Self::new
, but it also includes the controller parameters
that are common to all synths. (crate::synth::CONTROLLER_PARAMETERS
).
Thus, this is more appropriate to use if you plan to pass the parameters to a synth.
§Examples
let infos = vec![
StaticInfoRef {
title: "Numeric",
short_title: "Numeric",
unique_id: "numeric",
flags: Default::default(),
type_specific: TypeSpecificInfoRef::Numeric {
default: 0.0,
valid_range: 0.0..=1.0,
units: None,
},
},
];
let start_overrides = vec![(MOD_WHEEL_PARAMETER, InternalValue::Numeric(1.0))].into_iter().collect();
let end_overrides = vec![("numeric", InternalValue::Numeric(0.5))].into_iter().collect();
let states = RampedStatesMap::new_synth(
infos.iter().cloned(),
&start_overrides,
&end_overrides,
10
);
// If we only overrode a value at the beginning or end
// it should be ramped
match states.get_numeric("numeric") {
Some(NumericBufferState::PiecewiseLinear(_)) => (),
_ => panic!("Expected a ramped value"),
};
match states.get_numeric(MOD_WHEEL_PARAMETER) {
Some(NumericBufferState::PiecewiseLinear(_)) => (),
_ => panic!("Expected a ramped value"),
};
// Params left at default should be constants
match states.get_numeric(PITCH_BEND_PARAMETER) {
Some(NumericBufferState::Constant(0.0)) => (),
_ => panic!("Expected a constant value"),
};
§Panics
Panics if start_overrides
or end_overrides
do not match the type of the parameter
specified in infos
.
Sourcepub fn new_const<'a, S: AsRef<str> + 'a>(
infos: impl IntoIterator<Item = InfoRef<'a, S>> + 'a,
overrides: &HashMap<&str, InternalValue>,
) -> Self
pub fn new_const<'a, S: AsRef<str> + 'a>( infos: impl IntoIterator<Item = InfoRef<'a, S>> + 'a, overrides: &HashMap<&str, InternalValue>, ) -> Self
Helper to make a RampedStatesMap
with all parameters constant.
This is useful for performance testing because while the parameters
are constant at run-time, the RampedStatesMap
has the ability to
ramp between values, so consumers cannot be specialized to handle constant
values only
Note that if you want to pass this into a synth, you should use Self::new_const_synth
instead.
§Examples
let infos = vec![
StaticInfoRef {
title: "Numeric",
short_title: "Numeric",
unique_id: "numeric",
flags: Default::default(),
type_specific: TypeSpecificInfoRef::Numeric {
default: 0.0,
valid_range: 0.0..=1.0,
units: None,
},
},
];
let overrides = vec![("numeric", InternalValue::Numeric(0.5))].into_iter().collect();
let states = RampedStatesMap::new_const(infos.iter().cloned(), &overrides);
match states.get_numeric("numeric") {
Some(NumericBufferState::Constant(0.5)) => (),
_ => panic!("Expected constant value of 0.5"),
};
Sourcepub fn new_const_synth<'a, 'b: 'a>(
infos: impl IntoIterator<Item = InfoRef<'a, &'b str>> + 'a,
overrides: &HashMap<&str, InternalValue>,
) -> Self
pub fn new_const_synth<'a, 'b: 'a>( infos: impl IntoIterator<Item = InfoRef<'a, &'b str>> + 'a, overrides: &HashMap<&str, InternalValue>, ) -> Self
Create a new RampedStatesMap
for synths with all parameters constant.
This is useful for performance testing because while the parameters
are constant at run-time, the RampedStatesMap
has the ability to
ramp between values, so consumers cannot be specialized to handle constant
values only
This is similar to Self::new_const
, but it also includes the controller parameters
that are common to all synths. (crate::synth::CONTROLLER_PARAMETERS
).
Thus, this is more appropriate to use if you plan to pass the parameters to a synth.
§Examples
let infos = vec![
StaticInfoRef {
title: "Numeric",
short_title: "Numeric",
unique_id: "numeric",
flags: Default::default(),
type_specific: TypeSpecificInfoRef::Numeric {
default: 0.0,
valid_range: 0.0..=1.0,
units: None,
},
},
];
let overrides = vec![("numeric", InternalValue::Numeric(0.5))].into_iter().collect();
let states = RampedStatesMap::new_const_synth(infos.iter().cloned(), &overrides);
// Overridden parameters get the values you passed in
match states.get_numeric("numeric") {
Some(NumericBufferState::Constant(0.5)) => (),
_ => panic!("Expected constant value of 0.5"),
};
// Controller parameters will also be included
match states.get_numeric(MOD_WHEEL_PARAMETER) {
Some(NumericBufferState::Constant(0.0)) => (),
_ => panic!("Expected constant value of 0.0"),
};
Trait Implementations§
Source§impl BufferStates for RampedStatesMap
impl BufferStates for RampedStatesMap
Source§fn get_by_hash(
&self,
id_hash: IdHash,
) -> Option<BufferState<impl Iterator<Item = PiecewiseLinearCurvePoint> + Clone, impl Iterator<Item = TimedValue<u32>> + Clone, impl Iterator<Item = TimedValue<bool>> + Clone>>
fn get_by_hash( &self, id_hash: IdHash, ) -> Option<BufferState<impl Iterator<Item = PiecewiseLinearCurvePoint> + Clone, impl Iterator<Item = TimedValue<u32>> + Clone, impl Iterator<Item = TimedValue<bool>> + Clone>>
Source§fn get(
&self,
unique_id: &str,
) -> Option<BufferState<impl Iterator<Item = PiecewiseLinearCurvePoint> + Clone, impl Iterator<Item = TimedValue<u32>> + Clone, impl Iterator<Item = TimedValue<bool>> + Clone>>
fn get( &self, unique_id: &str, ) -> Option<BufferState<impl Iterator<Item = PiecewiseLinearCurvePoint> + Clone, impl Iterator<Item = TimedValue<u32>> + Clone, impl Iterator<Item = TimedValue<bool>> + Clone>>
Source§fn numeric_by_hash(
&self,
param_id: IdHash,
) -> Option<NumericBufferState<impl Iterator<Item = PiecewiseLinearCurvePoint> + Clone>>
fn numeric_by_hash( &self, param_id: IdHash, ) -> Option<NumericBufferState<impl Iterator<Item = PiecewiseLinearCurvePoint> + Clone>>
Source§fn get_numeric(
&self,
unique_id: &str,
) -> Option<NumericBufferState<impl Iterator<Item = PiecewiseLinearCurvePoint> + Clone>>
fn get_numeric( &self, unique_id: &str, ) -> Option<NumericBufferState<impl Iterator<Item = PiecewiseLinearCurvePoint> + Clone>>
Source§fn enum_by_hash(
&self,
param_id: IdHash,
) -> Option<EnumBufferState<impl Iterator<Item = TimedValue<u32>> + Clone>>
fn enum_by_hash( &self, param_id: IdHash, ) -> Option<EnumBufferState<impl Iterator<Item = TimedValue<u32>> + Clone>>
Source§fn get_enum(
&self,
unique_id: &str,
) -> Option<EnumBufferState<impl Iterator<Item = TimedValue<u32>> + Clone>>
fn get_enum( &self, unique_id: &str, ) -> Option<EnumBufferState<impl Iterator<Item = TimedValue<u32>> + Clone>>
Source§fn switch_by_hash(
&self,
param_id: IdHash,
) -> Option<SwitchBufferState<impl Iterator<Item = TimedValue<bool>> + Clone>>
fn switch_by_hash( &self, param_id: IdHash, ) -> Option<SwitchBufferState<impl Iterator<Item = TimedValue<bool>> + Clone>>
Source§fn get_switch(
&self,
unique_id: &str,
) -> Option<SwitchBufferState<impl Iterator<Item = TimedValue<bool>> + Clone>>
fn get_switch( &self, unique_id: &str, ) -> Option<SwitchBufferState<impl Iterator<Item = TimedValue<bool>> + Clone>>
Source§impl Clone for RampedStatesMap
impl Clone for RampedStatesMap
Source§fn clone(&self) -> RampedStatesMap
fn clone(&self) -> RampedStatesMap
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for RampedStatesMap
impl Debug for RampedStatesMap
Source§impl Default for RampedStatesMap
impl Default for RampedStatesMap
Source§fn default() -> RampedStatesMap
fn default() -> RampedStatesMap
Auto Trait Implementations§
impl Freeze for RampedStatesMap
impl RefUnwindSafe for RampedStatesMap
impl Send for RampedStatesMap
impl Sync for RampedStatesMap
impl Unpin for RampedStatesMap
impl UnwindSafe for RampedStatesMap
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more