From f53f6829f0fb2c8ce905eed87a2452217342a4af Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Tue, 15 Mar 2022 22:08:29 +0100 Subject: [PATCH] Implement the CLAP event filter extension --- src/wrapper/clap/wrapper.rs | 39 +++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/src/wrapper/clap/wrapper.rs b/src/wrapper/clap/wrapper.rs index b8e2d3b4..0f17f657 100644 --- a/src/wrapper/clap/wrapper.rs +++ b/src/wrapper/clap/wrapper.rs @@ -6,10 +6,10 @@ use atomic_float::AtomicF32; use atomic_refcell::{AtomicRefCell, AtomicRefMut}; use clap_sys::events::{ clap_event_header, clap_event_note, clap_event_param_gesture, clap_event_param_value, - clap_input_events, clap_output_events, CLAP_CORE_EVENT_SPACE_ID, CLAP_EVENT_IS_LIVE, - CLAP_EVENT_MIDI, CLAP_EVENT_NOTE_EXPRESSION, CLAP_EVENT_NOTE_OFF, CLAP_EVENT_NOTE_ON, - CLAP_EVENT_PARAM_GESTURE_BEGIN, CLAP_EVENT_PARAM_GESTURE_END, CLAP_EVENT_PARAM_VALUE, - CLAP_TRANSPORT_HAS_BEATS_TIMELINE, CLAP_TRANSPORT_HAS_SECONDS_TIMELINE, + clap_event_type, clap_input_events, clap_output_events, CLAP_CORE_EVENT_SPACE_ID, + CLAP_EVENT_IS_LIVE, CLAP_EVENT_MIDI, CLAP_EVENT_NOTE_EXPRESSION, CLAP_EVENT_NOTE_OFF, + CLAP_EVENT_NOTE_ON, CLAP_EVENT_PARAM_GESTURE_BEGIN, CLAP_EVENT_PARAM_GESTURE_END, + CLAP_EVENT_PARAM_VALUE, CLAP_TRANSPORT_HAS_BEATS_TIMELINE, CLAP_TRANSPORT_HAS_SECONDS_TIMELINE, CLAP_TRANSPORT_HAS_TEMPO, CLAP_TRANSPORT_HAS_TIME_SIGNATURE, CLAP_TRANSPORT_IS_LOOP_ACTIVE, CLAP_TRANSPORT_IS_PLAYING, CLAP_TRANSPORT_IS_RECORDING, CLAP_TRANSPORT_IS_WITHIN_PRE_ROLL, }; @@ -20,6 +20,7 @@ use clap_sys::ext::audio_ports::{ use clap_sys::ext::audio_ports_config::{ clap_audio_ports_config, clap_plugin_audio_ports_config, CLAP_EXT_AUDIO_PORTS_CONFIG, }; +use clap_sys::ext::event_filter::{clap_plugin_event_filter, CLAP_EXT_EVENT_FILTER}; use clap_sys::ext::gui::{ clap_plugin_gui, clap_window, CLAP_EXT_GUI, CLAP_WINDOW_API_COCOA, CLAP_WINDOW_API_WIN32, CLAP_WINDOW_API_X11, @@ -148,6 +149,8 @@ pub struct Wrapper { clap_plugin_audio_ports: clap_plugin_audio_ports, + clap_plugin_event_filter: clap_plugin_event_filter, + clap_plugin_gui: clap_plugin_gui, clap_plugin_latency: clap_plugin_latency, @@ -365,6 +368,10 @@ impl Wrapper

{ get: Self::ext_audio_ports_get, }, + clap_plugin_event_filter: clap_plugin_event_filter { + accepts: Self::ext_event_filter_accepts, + }, + clap_plugin_gui: clap_plugin_gui { is_api_supported: Self::ext_gui_is_api_supported, create: Self::ext_gui_create, @@ -754,7 +761,6 @@ impl Wrapper

{ ) -> bool { let raw_event = &*event; match (raw_event.space_id, raw_event.type_) { - // TODO: Implement the event filter (CLAP_CORE_EVENT_SPACE_ID, CLAP_EVENT_PARAM_VALUE) => { let event = &*(event as *const clap_event_param_value); self.update_plain_value_by_hash( @@ -1166,12 +1172,14 @@ impl Wrapper

{ let id = CStr::from_ptr(id); // TODO: Implement: - // - event_filter + // - note ports // - tail if id == CStr::from_ptr(CLAP_EXT_AUDIO_PORTS_CONFIG) { &wrapper.clap_plugin_audio_ports_config as *const _ as *const c_void } else if id == CStr::from_ptr(CLAP_EXT_AUDIO_PORTS) { &wrapper.clap_plugin_audio_ports as *const _ as *const c_void + } else if id == CStr::from_ptr(CLAP_EXT_EVENT_FILTER) { + &wrapper.clap_plugin_event_filter as *const _ as *const c_void } else if id == CStr::from_ptr(CLAP_EXT_GUI) && wrapper.editor.is_some() { // Only report that we support this extension if the plugin has an editor &wrapper.clap_plugin_gui as *const _ as *const c_void @@ -1374,6 +1382,25 @@ impl Wrapper

{ } } + unsafe extern "C" fn ext_event_filter_accepts( + _plugin: *const clap_plugin, + space_id: u16, + event_type: clap_event_type, + ) -> bool { + match (space_id, event_type) { + (CLAP_CORE_EVENT_SPACE_ID, CLAP_EVENT_PARAM_VALUE) => true, + (CLAP_CORE_EVENT_SPACE_ID, CLAP_EVENT_NOTE_ON) + | (CLAP_CORE_EVENT_SPACE_ID, CLAP_EVENT_NOTE_OFF) + | (CLAP_CORE_EVENT_SPACE_ID, CLAP_EVENT_NOTE_EXPRESSION) + | (CLAP_CORE_EVENT_SPACE_ID, CLAP_EVENT_MIDI) + if P::ACCEPTS_MIDI => + { + true + } + _ => false, + } + } + unsafe extern "C" fn ext_gui_is_api_supported( _plugin: *const clap_plugin, api: *const c_char,