Skip to content

Commit

Permalink
ParamValues constructor takes count instead of &[ParamInfo]
Browse files Browse the repository at this point in the history
Since ParamValues::poll only returns values that have been set via
ParamValues::set, the initial values in the AtomicF64s will never be observed,
so it is unnecessary to initialize them to the parameters' actual default
values.
  • Loading branch information
micahrj committed Sep 1, 2024
1 parent 0d6c1e6 commit 1cd580b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/format/clap/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ impl<P: Plugin> Instance<P> {
input_bus_map,
output_bus_map,
param_map,
plugin_params: ParamValues::new(&info.params),
processor_params: ParamValues::new(&info.params),
plugin_params: ParamValues::with_count(info.params.len()),
processor_params: ParamValues::with_count(info.params.len()),
main_thread_state: UnsafeCell::new(MainThreadState {
layout_index: 0,
plugin: P::new(Host::from_inner(Arc::new(ClapHost {}))),
Expand Down
4 changes: 2 additions & 2 deletions src/format/vst3/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ impl<P: Plugin> Component<P> {
output_bus_map,
layout_set,
param_map,
plugin_params: ParamValues::new(&info.params),
processor_params: ParamValues::new(&info.params),
plugin_params: ParamValues::with_count(info.params.len()),
processor_params: ParamValues::with_count(info.params.len()),
_host: host.clone(),
main_thread_state: Arc::new(UnsafeCell::new(MainThreadState {
config: config.clone(),
Expand Down
8 changes: 4 additions & 4 deletions src/sync/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ use std::sync::atomic::Ordering;

use super::bitset::{self, AtomicBitset};
use super::float::AtomicF64;
use crate::params::{ParamInfo, ParamValue};
use crate::params::ParamValue;

pub struct ParamValues {
values: Vec<AtomicF64>,
dirty: AtomicBitset,
}

impl ParamValues {
pub fn new(params: &[ParamInfo]) -> ParamValues {
pub fn with_count(count: usize) -> ParamValues {
ParamValues {
values: params.iter().map(|p| AtomicF64::new(p.default)).collect(),
dirty: AtomicBitset::with_len(params.len()),
values: (0..count).map(|_| AtomicF64::new(0.0)).collect(),
dirty: AtomicBitset::with_len(count),
}
}

Expand Down

0 comments on commit 1cd580b

Please sign in to comment.