From e4509c1c8c0d736b45aef62c3119cb5069a15188 Mon Sep 17 00:00:00 2001 From: Micah Johnston Date: Mon, 2 Sep 2024 23:39:43 -0500 Subject: [PATCH] clap: factor out Instance::process_param_events method --- src/format/clap/instance.rs | 108 ++++++++++++++---------------------- 1 file changed, 41 insertions(+), 67 deletions(-) diff --git a/src/format/clap/instance.rs b/src/format/clap/instance.rs index 5999bf9..82efb64 100644 --- a/src/format/clap/instance.rs +++ b/src/format/clap/instance.rs @@ -158,6 +158,45 @@ impl Instance

{ }); } } + + unsafe fn process_param_events( + &self, + in_events: *const clap_input_events, + events: &mut Vec, + ) { + let mut params_changed = false; + + let size = (*in_events).size.unwrap()(in_events); + for i in 0..size { + let event = (*in_events).get.unwrap()(in_events, i); + + if (*event).space_id == CLAP_CORE_EVENT_SPACE_ID + && (*event).type_ == CLAP_EVENT_PARAM_VALUE + { + let event = &*(event as *const clap_event_param_value); + + if let Some(&index) = self.param_map.get(&event.param_id) { + let value = map_param_in(&self.info.params[index], event.value); + + events.push(Event { + time: event.header.time as i64, + data: Data::ParamChange { + id: event.param_id, + value, + }, + }); + + self.plugin_params.set(index, value); + + params_changed = true; + } + } + } + + if params_changed { + (*self.host).request_callback.unwrap()(self.host); + } + } } impl Instance

{ @@ -331,40 +370,7 @@ impl Instance

{ process_state.events.clear(); instance.sync_processor(&mut process_state.events); - - let mut params_changed = false; - - let in_events = process.in_events; - let size = (*in_events).size.unwrap()(in_events); - for i in 0..size { - let event = (*in_events).get.unwrap()(in_events, i); - - if (*event).space_id == CLAP_CORE_EVENT_SPACE_ID - && (*event).type_ == CLAP_EVENT_PARAM_VALUE - { - let event = &*(event as *const clap_event_param_value); - - if let Some(&index) = instance.param_map.get(&event.param_id) { - let value = map_param_in(&instance.info.params[index], event.value); - - process_state.events.push(Event { - time: event.header.time as i64, - data: Data::ParamChange { - id: event.param_id, - value, - }, - }); - - instance.plugin_params.set(index, value); - - params_changed = true; - } - } - } - - if params_changed { - (*instance.host).request_callback.unwrap()(instance.host); - } + instance.process_param_events(process.in_events, &mut process_state.events); processor.process( Buffers::from_raw_parts( @@ -689,39 +695,7 @@ impl Instance

{ process_state.events.clear(); instance.sync_processor(&mut process_state.events); - - let mut params_changed = false; - - let size = (*in_).size.unwrap()(in_); - for i in 0..size { - let event = (*in_).get.unwrap()(in_, i); - - if (*event).space_id == CLAP_CORE_EVENT_SPACE_ID - && (*event).type_ == CLAP_EVENT_PARAM_VALUE - { - let event = &*(event as *const clap_event_param_value); - - if let Some(&index) = instance.param_map.get(&event.param_id) { - let value = map_param_in(&instance.info.params[index], event.value); - - process_state.events.push(Event { - time: event.header.time as i64, - data: Data::ParamChange { - id: event.param_id, - value, - }, - }); - - instance.plugin_params.set(index, value); - - params_changed = true; - } - } - } - - if params_changed { - (*instance.host).request_callback.unwrap()(instance.host); - } + instance.process_param_events(in_, &mut process_state.events); processor.process( Buffers::from_raw_parts(