1
0
Fork 0

Fix group->unit conversion with missing parents

This caused Spectral Compressor's VST3 version to not work because the
compressor group didn't contain any parameters.
This commit is contained in:
Robbert van der Helm 2022-07-24 23:37:45 +02:00
parent fdbff129f8
commit 7f12c9f362

View file

@ -50,8 +50,10 @@ impl ParamUnits {
where where
I: Iterator<Item = (u32, &'a str)> + Clone, I: Iterator<Item = (u32, &'a str)> + Clone,
{ {
// First we'll build a unit for each unique parameter // First we'll build a unit for each unique parameter group. We need to be careful here to
let unique_group_names: HashSet<&str> = groups // expand `foo/bar/baz` into `foo/bar/baz`, `foo/bar` and `foo`, in case the parent groups
// don't contain any parameters and thus aren't present in `groups`.
let unique_group_names: HashSet<String> = groups
.clone() .clone()
.into_iter() .into_iter()
.filter_map(|(_, group_name)| { .filter_map(|(_, group_name)| {
@ -62,12 +64,26 @@ impl ParamUnits {
None None
} }
}) })
.flat_map(|group_name| {
// This is the expansion mentioned above
let mut expanded_group = String::new();
let mut expanded_groups = Vec::new();
for component in group_name.split('/') {
if !expanded_group.is_empty() {
expanded_group.push('/');
}
expanded_group.push_str(component);
expanded_groups.push(expanded_group.clone());
}
expanded_groups
})
.collect(); .collect();
let mut groups_units: Vec<(&str, ParamUnit)> = unique_group_names let mut groups_units: Vec<(&str, ParamUnit)> = unique_group_names
.into_iter() .iter()
.map(|group_name| { .map(|group_name| {
( (
group_name, group_name.as_str(),
ParamUnit { ParamUnit {
name: match group_name.rfind('/') { name: match group_name.rfind('/') {
Some(sep_pos) => group_name[sep_pos + 1..].to_string(), Some(sep_pos) => group_name[sep_pos + 1..].to_string(),