Skip to content

Commit

Permalink
vst3: use ParamChange events instead of Processor::set_param
Browse files Browse the repository at this point in the history
  • Loading branch information
micahrj committed Mar 17, 2024
1 parent b405201 commit e02da1b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 11 deletions.
8 changes: 6 additions & 2 deletions src/format/vst3/buffers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ impl ScratchBuffers {
let mut scratch = &mut self.buffers[..];

if len == 0 {
self.ptrs.fill(NonNull::dangling().as_ptr());
return Ok(Buffers::from_raw_parts(&self.data, &self.ptrs, 0, len));
return Ok(self.get_empty_buffers());
}

let input_count = data.numInputs as usize;
Expand Down Expand Up @@ -245,4 +244,9 @@ impl ScratchBuffers {

Ok(Buffers::from_raw_parts(&self.data, &self.ptrs, 0, len))
}

pub fn get_empty_buffers(&mut self) -> Buffers {
self.ptrs.fill(NonNull::dangling().as_ptr());
unsafe { Buffers::from_raw_parts(&self.data, &self.ptrs, 0, 0) }
}
}
38 changes: 29 additions & 9 deletions src/format/vst3/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,6 @@ impl<P: Plugin> Component<P> {
plugin.set_param(id, value);
}
}

fn sync_processor(&self, processor: &mut P::Processor) {
for (index, value) in self.processor_params.poll() {
let id = self.info.params[index].id;
processor.set_param(id, value);
}
}
}

impl<P: Plugin> Class for Component<P> {
Expand Down Expand Up @@ -466,7 +459,25 @@ impl<P: Plugin> IAudioProcessorTrait for Component<P> {
};

if state == 0 {
self.sync_processor(processor);
// Flush plugin -> processor parameter changes
process_state.events.clear();
for (index, value) in self.processor_params.poll() {
process_state.events.push(Event {
time: 0,
data: Data::ParamChange {
id: self.info.params[index].id,
value,
},
});
}

if !process_state.events.is_empty() {
processor.process(
process_state.scratch_buffers.get_empty_buffers(),
Events::new(&process_state.events),
);
}

processor.reset();
}

Expand Down Expand Up @@ -494,6 +505,16 @@ impl<P: Plugin> IAudioProcessorTrait for Component<P> {

process_state.events.clear();

for (index, value) in self.processor_params.poll() {
process_state.events.push(Event {
time: 0,
data: Data::ParamChange {
id: self.info.params[index].id,
value,
},
});
}

if let Some(param_changes) = ComRef::from_raw(data.inputParameterChanges) {
for index in 0..param_changes.getParameterCount() {
let param_data = param_changes.getParameterData(index);
Expand Down Expand Up @@ -527,7 +548,6 @@ impl<P: Plugin> IAudioProcessorTrait for Component<P> {
}
}

self.sync_processor(processor);
processor.process(buffers, Events::new(&process_state.events));

kResultOk
Expand Down

0 comments on commit e02da1b

Please sign in to comment.