SynthRampedStatesMap

Struct SynthRampedStatesMap 

Source
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

Source

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.

Source

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"),
};
Source

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"),
};
Source

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

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>>

Get the state of a parameter by it’s hashed unique ID. Read more
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>>

Get the state of a parameter by it’s unique ID. Read more
Source§

fn numeric_by_hash( &self, param_id: IdHash, ) -> Option<NumericBufferState<impl Iterator<Item = PiecewiseLinearCurvePoint> + Clone>>

Get the state of a numeric parameter by it’s hashed unique ID. Read more
Source§

fn get_numeric( &self, unique_id: &str, ) -> Option<NumericBufferState<impl Iterator<Item = PiecewiseLinearCurvePoint> + Clone>>

Get the state of a numeric parameter by it’s unique ID. Read more
Source§

fn enum_by_hash( &self, param_id: IdHash, ) -> Option<EnumBufferState<impl Iterator<Item = TimedValue<u32>> + Clone>>

Get the state of an enum parameter by it’s hashed unique ID. Read more
Source§

fn get_enum( &self, unique_id: &str, ) -> Option<EnumBufferState<impl Iterator<Item = TimedValue<u32>> + Clone>>

Get the state of an enum parameter by it’s unique ID. Read more
Source§

fn switch_by_hash( &self, param_id: IdHash, ) -> Option<SwitchBufferState<impl Iterator<Item = TimedValue<bool>> + Clone>>

Get the state of a switch parameter by it’s hashed unique ID. Read more
Source§

fn get_switch( &self, unique_id: &str, ) -> Option<SwitchBufferState<impl Iterator<Item = TimedValue<bool>> + Clone>>

Get the state of a switch parameter by it’s unique ID. Read more
Source§

impl SynthParamBufferStates for SynthRampedStatesMap

Source§

fn get_numeric_global_expression( &self, expression: NumericGlobalExpression, ) -> NumericBufferState<impl Iterator<Item = PiecewiseLinearCurvePoint> + Clone>

Get the current value of a numeric global expression controller.
Source§

fn get_switch_global_expression( &self, expression: SwitchGlobalExpression, ) -> SwitchBufferState<impl Iterator<Item = TimedValue<bool>> + Clone>

Get the current value of a switch global expression controller.
Source§

fn get_numeric_expression_for_note( &self, expression: NumericPerNoteExpression, note_id: NoteID, ) -> NumericBufferState<impl Iterator<Item = PiecewiseLinearCurvePoint> + Clone>

Get the current value of a numeric per-note expression controller.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.