conformal_component::parameters

Function override_synth_defaults

Source
pub fn override_synth_defaults<'a, 'b: 'a, H: BuildHasher>(
    infos: impl IntoIterator<Item = InfoRef<'a, &'b str>> + 'a,
    overrides: &HashMap<&str, InternalValue, H>,
) -> HashMap<String, InternalValue>
Expand description

Helper function to get a map of synth param values based on the default values from a list of Infos.

This is similar to 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,
    },
  },
];

// Without overrides, we'll get the default value.
assert_eq!(
  override_synth_defaults(infos.iter().cloned(), &HashMap::new()).get("numeric"),
  Some(&InternalValue::Numeric(0.0)),
);

// Note that control parameters are included in the result.
assert_eq!(
  override_synth_defaults(infos.iter().cloned(), &HashMap::new()).get(MOD_WHEEL_PARAMETER),
  Some(&InternalValue::Numeric(0.0)),
);

// If we override the default value of a parameter, we'll get that instead.
assert_eq!(
  override_synth_defaults(
    infos.iter().cloned(),
    &vec![("numeric", InternalValue::Numeric(0.5))].into_iter().collect::<HashMap<_, _>>()
  ).get("numeric"),
  Some(&InternalValue::Numeric(0.5)),
);

// We can also override control parameters
assert_eq!(
  override_synth_defaults(
    infos.iter().cloned(),
    &vec![(MOD_WHEEL_PARAMETER, InternalValue::Numeric(0.5))].into_iter().collect::<HashMap<_, _>>()
  ).get(MOD_WHEEL_PARAMETER),
  Some(&InternalValue::Numeric(0.5)),
);