conformal_component::parameters

Struct StatesMap

Source
pub struct StatesMap { /* private fields */ }
Expand description

A simple implementation of States that is backed by a HashMap.

This is useful for testing or other places when you want to pass a States to a component outside of a Conformal wrapper.

Implementations§

Source§

impl StatesMap

Source

pub fn new_override_defaults<'a, S: AsRef<str> + 'a>( infos: impl IntoIterator<Item = InfoRef<'a, S>> + 'a, overrides: &HashMap<&str, InternalValue>, ) -> Self

Create a new StatesMap from a list of Infos and overrides.

This creates a StatesMap with all parameters set to default values, except for the ones that are overridden by the overrides.

Note that if you want to pass this into a synth, you should use Self::new_override_synth_defaults instead.

overrides work exactly as in override_defaults.

§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 = StatesMap::new_override_defaults(infos.iter().cloned(), &overrides);
assert_eq!(states.get_numeric("numeric"), Some(0.5));
Source

pub fn new_defaults<'a, S: AsRef<str> + 'a>( infos: impl IntoIterator<Item = InfoRef<'a, S>> + 'a, ) -> Self

Create a new StatesMap from a list of Infos.

Each parameter in Infos will be set to its default value.

Note that if you want to pass this into a synth, you should use Self::new_synth_defaults 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 states = StatesMap::new_defaults(infos.iter().cloned());
assert_eq!(states.get_numeric("numeric"), Some(0.0));
Source

pub fn new_override_synth_defaults<'a, 'b: 'a>( infos: impl IntoIterator<Item = InfoRef<'a, &'b str>> + 'a, overrides: &HashMap<&str, InternalValue>, ) -> Self

Create a new StatesMap to pass to a synth from a list of Infos and overrides.

This is similar to Self::new_override_defaults, 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![
  // You can override declared parameters
  ("numeric", InternalValue::Numeric(0.5)),
  // Or you can override control parameters
  (MOD_WHEEL_PARAMETER, InternalValue::Numeric(0.2)),
].into_iter().collect();
let states = StatesMap::new_override_synth_defaults(infos.iter().cloned(), &overrides);

// Overridden parameters get the values you passed in
assert_eq!(states.get_numeric("numeric"), Some(0.5));
assert_eq!(states.get_numeric(MOD_WHEEL_PARAMETER), Some(0.2));

// Other parameters get their default values
assert_eq!(states.get_numeric(PITCH_BEND_PARAMETER), Some(0.0));
Source

pub fn new_synth_defaults<'a, 'b: 'a>( infos: impl IntoIterator<Item = InfoRef<'a, &'b str>> + 'a, ) -> Self

Create a new StatesMap to pass to a synth from a list of Infos.

Each parameter in Infos will be set to its default value.

This is similar to Self::new_defaults, 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 states = StatesMap::new_synth_defaults(infos.iter().cloned());
assert_eq!(states.get_numeric("numeric"), Some(0.0));

// Controller parameters will also be included
assert_eq!(states.get_numeric(MOD_WHEEL_PARAMETER), Some(0.0));

Trait Implementations§

Source§

impl Clone for StatesMap

Source§

fn clone(&self) -> StatesMap

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for StatesMap

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for StatesMap

Source§

fn default() -> StatesMap

Returns the “default value” for a type. Read more
Source§

impl<S: AsRef<str>> From<HashMap<S, InternalValue>> for StatesMap

Source§

fn from(map: HashMap<S, InternalValue>) -> Self

Converts to this type from the input type.
Source§

impl States for StatesMap

Source§

fn get_by_hash(&self, id_hash: IdHash) -> Option<InternalValue>

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

fn get(&self, unique_id: &str) -> Option<InternalValue>

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

fn numeric_by_hash(&self, id_hash: IdHash) -> Option<f32>

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

fn get_numeric(&self, unique_id: &str) -> Option<f32>

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

fn enum_by_hash(&self, id_hash: IdHash) -> Option<u32>

Get the current enum value of a parameter by it’s hashed unique ID. Read more
Source§

fn get_enum(&self, unique_id: &str) -> Option<u32>

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

fn switch_by_hash(&self, id_hash: IdHash) -> Option<bool>

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

fn get_switch(&self, unique_id: &str) -> Option<bool>

Get the current switch value of a parameter by it’s unique ID. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.