Skip to content

Commit

Permalink
clap: handle flush on the audio thread
Browse files Browse the repository at this point in the history
  • Loading branch information
micahrj committed Oct 24, 2023
1 parent 5e771c8 commit c95a659
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions src/format/clap/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,17 +555,37 @@ impl<P: Plugin> Instance<P> {
_out: *const clap_output_events,
) {
let instance = &*(plugin as *const Self);
let main_thread_state = &mut *instance.main_thread_state.get();
let process_state = &mut *instance.process_state.get();

let size = (*in_).size.unwrap()(in_);
for i in 0..size {
let event = (*in_).get.unwrap()(in_, i);
// If we are in the active state, flush will be called on the audio thread.
if let Some(processor) = &mut process_state.processor {
let size = (*in_).size.unwrap()(in_);
for i in 0..size {
let event = (*in_).get.unwrap()(in_, i);

if (*event).type_ == CLAP_EVENT_PARAM_VALUE {
let event = &*(event as *const clap_event_param_value);
if (*event).type_ == CLAP_EVENT_PARAM_VALUE {
let event = &*(event as *const clap_event_param_value);

if instance.param_map.contains_key(&event.param_id) {
main_thread_state.plugin.set_param(event.param_id, event.value);
if instance.param_map.contains_key(&event.param_id) {
processor.set_param(event.param_id, event.value);
}
}
}
}
// Otherwise, flush will be called on the main thread.
else {
let main_thread_state = &mut *instance.main_thread_state.get();

let size = (*in_).size.unwrap()(in_);
for i in 0..size {
let event = (*in_).get.unwrap()(in_, i);

if (*event).type_ == CLAP_EVENT_PARAM_VALUE {
let event = &*(event as *const clap_event_param_value);

if instance.param_map.contains_key(&event.param_id) {
main_thread_state.plugin.set_param(event.param_id, event.value);
}
}
}
}
Expand Down

0 comments on commit c95a659

Please sign in to comment.