pub struct SynthRampedStatesMap { /* private fields */ }Expand description
A simple implementation of a SynthParamBufferStates that allows
for parameters to change between the start and end of a buffer.
This is similar to RampedStatesMap, but it also includes the expression controller parameters
needed for synths.
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 SynthRampedStatesMap
impl SynthRampedStatesMap
Sourcepub fn new<'a, S: AsRef<str> + 'a>(
infos: impl IntoIterator<Item = InfoRef<'a, S>> + 'a,
_: SynthRampedOverrides<'_, '_>,
buffer_size: usize,
) -> Self
pub fn new<'a, S: AsRef<str> + 'a>( infos: impl IntoIterator<Item = InfoRef<'a, S>> + 'a, _: SynthRampedOverrides<'_, '_>, buffer_size: usize, ) -> Self
Create a new SynthRampedStatesMap for synths from a list of Infos and overrides.
This is similar to RampedStatesMap::new, but it also includes the expression controller parameters.
§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_expression_overrides = vec![(NumericGlobalExpression::ModWheel, 1.0)].into_iter().collect();
let end_param_overrides = vec![("numeric", InternalValue::Numeric(0.5))].into_iter().collect();
let states = SynthRampedStatesMap::new(
infos.iter().cloned(),
SynthRampedOverrides {
start_params: &Default::default(),
end_params: &end_param_overrides,
start_numeric_expressions: &start_expression_overrides,
end_numeric_expressions: &Default::default(),
start_switch_expressions: &Default::default(),
end_switch_expressions: &Default::default(),
},
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_global_expression(NumericGlobalExpression::ModWheel) {
NumericBufferState::PiecewiseLinear(_) => (),
_ => panic!("Expected a ramped value"),
};
// Params left at default should be constants
match states.get_numeric_global_expression(NumericGlobalExpression::PitchBend) {
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_with_per_note<'a, S: AsRef<str> + 'a>(
infos: impl IntoIterator<Item = InfoRef<'a, S>> + 'a,
_: SynthRampedOverrides<'_, '_>,
start_per_note_expressions: &HashMap<(NumericPerNoteExpression, NoteID), f32>,
end_per_note_expressions: &HashMap<(NumericPerNoteExpression, NoteID), f32>,
buffer_size: usize,
) -> Self
pub fn new_with_per_note<'a, S: AsRef<str> + 'a>( infos: impl IntoIterator<Item = InfoRef<'a, S>> + 'a, _: SynthRampedOverrides<'_, '_>, start_per_note_expressions: &HashMap<(NumericPerNoteExpression, NoteID), f32>, end_per_note_expressions: &HashMap<(NumericPerNoteExpression, NoteID), f32>, buffer_size: usize, ) -> Self
Create a new SynthRampedStatesMap with per-note expression overrides.
This is similar to Self::new, but also allows specifying per-note expression
values for specific notes at the start and end of the buffer.
§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 note_id = NoteID::from_pitch(60);
let start_per_note = vec![
((NumericPerNoteExpression::PitchBend, note_id), 0.0),
].into_iter().collect();
let end_per_note = vec![
((NumericPerNoteExpression::PitchBend, note_id), 2.0),
].into_iter().collect();
let states = SynthRampedStatesMap::new_with_per_note(
infos.iter().cloned(),
SynthRampedOverrides {
start_params: &Default::default(),
end_params: &Default::default(),
start_numeric_expressions: &Default::default(),
end_numeric_expressions: &Default::default(),
start_switch_expressions: &Default::default(),
end_switch_expressions: &Default::default(),
},
&start_per_note,
&end_per_note,
10,
);
match states.get_numeric_expression_for_note(NumericPerNoteExpression::PitchBend, note_id) {
NumericBufferState::PiecewiseLinear(_) => (),
_ => panic!("Expected a ramped value"),
};Sourcepub fn new_const<'a, S: AsRef<str> + 'a>(
infos: impl IntoIterator<Item = InfoRef<'a, S>> + 'a,
overrides: &HashMap<&str, InternalValue>,
numeric_expression_overrides: &HashMap<NumericGlobalExpression, f32>,
switch_expression_overrides: &HashMap<SwitchGlobalExpression, bool>,
) -> Self
pub fn new_const<'a, S: AsRef<str> + 'a>( infos: impl IntoIterator<Item = InfoRef<'a, S>> + 'a, overrides: &HashMap<&str, InternalValue>, numeric_expression_overrides: &HashMap<NumericGlobalExpression, f32>, switch_expression_overrides: &HashMap<SwitchGlobalExpression, bool>, ) -> Self
Create a new SynthRampedStatesMap for synths with all parameters constant.
This is useful for performance testing because while the parameters
are constant at run-time, the SynthRampedStatesMap has the ability to
ramp between values, so consumers cannot be specialized to handle constant
values only
This is similar to RampedStatesMap::new_const, but it also includes the expression controller parameters.
§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 = SynthRampedStatesMap::new_const(infos.iter().cloned(), &overrides, &Default::default(), &Default::default());
// 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_global_expression(NumericGlobalExpression::ModWheel) {
NumericBufferState::Constant(0.0) => (),
_ => panic!("Expected constant value of 0.0"),
};Sourcepub fn new_const_with_per_note<'a, S: AsRef<str> + 'a>(
infos: impl IntoIterator<Item = InfoRef<'a, S>> + 'a,
overrides: &HashMap<&str, InternalValue>,
numeric_expression_overrides: &HashMap<NumericGlobalExpression, f32>,
switch_expression_overrides: &HashMap<SwitchGlobalExpression, bool>,
per_note_expression_overrides: &HashMap<(NumericPerNoteExpression, NoteID), f32>,
) -> Self
pub fn new_const_with_per_note<'a, S: AsRef<str> + 'a>( infos: impl IntoIterator<Item = InfoRef<'a, S>> + 'a, overrides: &HashMap<&str, InternalValue>, numeric_expression_overrides: &HashMap<NumericGlobalExpression, f32>, switch_expression_overrides: &HashMap<SwitchGlobalExpression, bool>, per_note_expression_overrides: &HashMap<(NumericPerNoteExpression, NoteID), f32>, ) -> Self
Create a new SynthRampedStatesMap for synths with all parameters constant,
including per-note expression overrides.
This is similar to Self::new_const, but also allows specifying per-note
expression values for specific notes.
§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 note_id = NoteID::from_pitch(60);
let per_note_overrides = vec![
((NumericPerNoteExpression::PitchBend, note_id), 1.5),
].into_iter().collect();
let states = SynthRampedStatesMap::new_const_with_per_note(
infos.iter().cloned(),
&Default::default(),
&Default::default(),
&Default::default(),
&per_note_overrides,
);
match states.get_numeric_expression_for_note(NumericPerNoteExpression::PitchBend, note_id) {
NumericBufferState::Constant(v) if (v - 1.5).abs() < 1e-6 => (),
_ => panic!("Expected constant value of 1.5"),
};Trait Implementations§
Source§impl BufferStates for SynthRampedStatesMap
impl BufferStates for SynthRampedStatesMap
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 SynthParamBufferStates for SynthRampedStatesMap
impl SynthParamBufferStates for SynthRampedStatesMap
Source§fn get_numeric_global_expression(
&self,
expression: NumericGlobalExpression,
) -> NumericBufferState<impl Iterator<Item = PiecewiseLinearCurvePoint> + Clone>
fn get_numeric_global_expression( &self, expression: NumericGlobalExpression, ) -> NumericBufferState<impl Iterator<Item = PiecewiseLinearCurvePoint> + Clone>
Source§fn get_switch_global_expression(
&self,
expression: SwitchGlobalExpression,
) -> SwitchBufferState<impl Iterator<Item = TimedValue<bool>> + Clone>
fn get_switch_global_expression( &self, expression: SwitchGlobalExpression, ) -> SwitchBufferState<impl Iterator<Item = TimedValue<bool>> + Clone>
Source§fn get_numeric_expression_for_note(
&self,
expression: NumericPerNoteExpression,
note_id: NoteID,
) -> NumericBufferState<impl Iterator<Item = PiecewiseLinearCurvePoint> + Clone>
fn get_numeric_expression_for_note( &self, expression: NumericPerNoteExpression, note_id: NoteID, ) -> NumericBufferState<impl Iterator<Item = PiecewiseLinearCurvePoint> + Clone>
Auto Trait Implementations§
impl Freeze for SynthRampedStatesMap
impl RefUnwindSafe for SynthRampedStatesMap
impl Send for SynthRampedStatesMap
impl Sync for SynthRampedStatesMap
impl Unpin for SynthRampedStatesMap
impl UnwindSafe for SynthRampedStatesMap
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> 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