1
0
Fork 0

Add the ParamUnits to the VST3 wrapper

This commit is contained in:
Robbert van der Helm 2022-03-16 20:19:40 +01:00
parent ea30ba7ffb
commit 2bf32aa771

View file

@ -10,6 +10,7 @@ use vst3_sys::base::{kInvalidArgument, kResultOk, tresult};
use vst3_sys::vst::IComponentHandler; use vst3_sys::vst::IComponentHandler;
use super::context::{WrapperGuiContext, WrapperProcessContext}; use super::context::{WrapperGuiContext, WrapperProcessContext};
use super::param_units::ParamUnits;
use super::util::{ObjectPtr, VstPtr, BYPASS_PARAM_HASH, BYPASS_PARAM_ID}; use super::util::{ObjectPtr, VstPtr, BYPASS_PARAM_HASH, BYPASS_PARAM_ID};
use super::view::WrapperView; use super::view::WrapperView;
use crate::buffer::Buffer; use crate::buffer::Buffer;
@ -84,6 +85,7 @@ pub(crate) struct WrapperInner<P: Vst3Plugin> {
/// parameters belonging to the plugin. As long as `plugin` does not get recreated, these /// parameters belonging to the plugin. As long as `plugin` does not get recreated, these
/// addresses will remain stable, as they are obtained from a pinned object. /// addresses will remain stable, as they are obtained from a pinned object.
pub param_by_hash: HashMap<u32, ParamPtr>, pub param_by_hash: HashMap<u32, ParamPtr>,
pub param_units: ParamUnits,
/// The default normalized parameter value for every parameter in `param_ids`. We need to store /// The default normalized parameter value for every parameter in `param_ids`. We need to store
/// this in case the host requeries the parmaeter later. This is also indexed by the hash so we /// this in case the host requeries the parmaeter later. This is also indexed by the hash so we
/// can retrieve them later for the UI if needed. /// can retrieve them later for the UI if needed.
@ -138,6 +140,7 @@ impl<P: Vst3Plugin> WrapperInner<P> {
// parameters. Since the object returned by `params()` is pinned, these pointers are safe to // parameters. Since the object returned by `params()` is pinned, these pointers are safe to
// dereference as long as `wrapper.plugin` is alive // dereference as long as `wrapper.plugin` is alive
let param_map = plugin.read().params().param_map(); let param_map = plugin.read().params().param_map();
let param_groups = plugin.read().params().param_groups();
let param_ids = plugin.read().params().param_ids(); let param_ids = plugin.read().params().param_ids();
nih_debug_assert!( nih_debug_assert!(
!param_map.contains_key(BYPASS_PARAM_ID), !param_map.contains_key(BYPASS_PARAM_ID),
@ -145,33 +148,40 @@ impl<P: Vst3Plugin> WrapperInner<P> {
); );
// Only calculate these hashes once, and in the stable order defined by the plugin // Only calculate these hashes once, and in the stable order defined by the plugin
let param_id_hashes_ptrs: Vec<_> = param_ids let param_id_hashes_ptrs_groups: Vec<_> = param_ids
.iter() .iter()
.filter_map(|id| { .filter_map(|id| {
let param_ptr = param_map.get(id)?; let param_ptr = param_map.get(id)?;
Some((id, hash_param_id(id), param_ptr)) let param_group = param_groups.get(id)?;
Some((id, hash_param_id(id), param_ptr, param_group))
}) })
.collect(); .collect();
let param_hashes = param_id_hashes_ptrs let param_hashes = param_id_hashes_ptrs_groups
.iter() .iter()
.map(|&(_, hash, _)| hash) .map(|&(_, hash, _, _)| hash)
.collect(); .collect();
let param_by_hash = param_id_hashes_ptrs let param_by_hash = param_id_hashes_ptrs_groups
.iter() .iter()
.map(|&(_, hash, ptr)| (hash, *ptr)) .map(|&(_, hash, ptr, _)| (hash, *ptr))
.collect(); .collect();
let param_defaults_normalized = param_id_hashes_ptrs let param_units = ParamUnits::from_param_groups(
param_id_hashes_ptrs_groups
.iter()
.map(|&(_, hash, _, group_name)| (hash, group_name.as_str())),
)
.expect("Inconsistent parameter groups");
let param_defaults_normalized = param_id_hashes_ptrs_groups
.iter() .iter()
.map(|&(_, hash, ptr)| (hash, unsafe { ptr.normalized_value() })) .map(|&(_, hash, ptr, _)| (hash, unsafe { ptr.normalized_value() }))
.collect(); .collect();
let param_id_to_hash = param_id_hashes_ptrs let param_id_to_hash = param_id_hashes_ptrs_groups
.iter() .iter()
.map(|&(id, hash, _)| (*id, hash)) .map(|&(id, hash, _, _)| (*id, hash))
.collect(); .collect();
let param_ptr_to_hash = param_id_hashes_ptrs let param_ptr_to_hash = param_id_hashes_ptrs_groups
.into_iter() .into_iter()
.map(|(_, hash, ptr)| (*ptr, hash)) .map(|(_, hash, ptr, _)| (*ptr, hash))
.collect(); .collect();
let wrapper = Self { let wrapper = Self {
@ -209,6 +219,7 @@ impl<P: Vst3Plugin> WrapperInner<P> {
param_hashes, param_hashes,
param_by_hash, param_by_hash,
param_units,
param_defaults_normalized, param_defaults_normalized,
param_id_to_hash, param_id_to_hash,
param_ptr_to_hash, param_ptr_to_hash,