1
0
Fork 0

Implement the CLAP voice info extension

This commit is contained in:
Robbert van der Helm 2022-07-05 22:59:45 +02:00
parent 1de561e4a0
commit f828761677

View file

@ -21,6 +21,10 @@ use clap_sys::ext::audio_ports::{
use clap_sys::ext::audio_ports_config::{ use clap_sys::ext::audio_ports_config::{
clap_audio_ports_config, clap_plugin_audio_ports_config, CLAP_EXT_AUDIO_PORTS_CONFIG, clap_audio_ports_config, clap_plugin_audio_ports_config, CLAP_EXT_AUDIO_PORTS_CONFIG,
}; };
use clap_sys::ext::draft::voice_info::{
clap_plugin_voice_info, clap_voice_info, CLAP_EXT_VOICE_INFO,
CLAP_VOICE_INFO_SUPPORTS_OVERLAPPING_NOTES,
};
use clap_sys::ext::gui::{ use clap_sys::ext::gui::{
clap_gui_resize_hints, clap_host_gui, clap_plugin_gui, clap_window, CLAP_EXT_GUI, clap_gui_resize_hints, clap_host_gui, clap_plugin_gui, clap_window, CLAP_EXT_GUI,
CLAP_WINDOW_API_COCOA, CLAP_WINDOW_API_WIN32, CLAP_WINDOW_API_X11, CLAP_WINDOW_API_COCOA, CLAP_WINDOW_API_WIN32, CLAP_WINDOW_API_X11,
@ -235,6 +239,8 @@ pub struct Wrapper<P: ClapPlugin> {
clap_plugin_tail: clap_plugin_tail, clap_plugin_tail: clap_plugin_tail,
clap_plugin_voice_info: clap_plugin_voice_info,
/// A queue of tasks that still need to be performed. Because CLAP lets the plugin request a /// A queue of tasks that still need to be performed. Because CLAP lets the plugin request a
/// host callback directly, we don't need to use the OsEventLoop we use in our other plugin /// host callback directly, we don't need to use the OsEventLoop we use in our other plugin
/// implementations. Instead, we'll post tasks to this queue, ask the host to call /// implementations. Instead, we'll post tasks to this queue, ask the host to call
@ -607,6 +613,10 @@ impl<P: ClapPlugin> Wrapper<P> {
get: Some(Self::ext_tail_get), get: Some(Self::ext_tail_get),
}, },
clap_plugin_voice_info: clap_plugin_voice_info {
get: Some(Self::ext_voice_info_get),
},
tasks: ArrayQueue::new(TASK_QUEUE_CAPACITY), tasks: ArrayQueue::new(TASK_QUEUE_CAPACITY),
main_thread_id: thread::current().id(), main_thread_id: thread::current().id(),
}; };
@ -2201,6 +2211,8 @@ impl<P: ClapPlugin> Wrapper<P> {
&wrapper.clap_plugin_state as *const _ as *const c_void &wrapper.clap_plugin_state as *const _ as *const c_void
} else if id == CLAP_EXT_TAIL { } else if id == CLAP_EXT_TAIL {
&wrapper.clap_plugin_tail as *const _ as *const c_void &wrapper.clap_plugin_tail as *const _ as *const c_void
} else if id == CLAP_EXT_VOICE_INFO && P::CLAP_POLY_MODULATION_CONFIG.is_some() {
&wrapper.clap_plugin_voice_info as *const _ as *const c_void
} else { } else {
nih_trace!("Host tried to query unknown extension {:?}", id); nih_trace!("Host tried to query unknown extension {:?}", id);
ptr::null() ptr::null()
@ -3063,6 +3075,31 @@ impl<P: ClapPlugin> Wrapper<P> {
_ => 0, _ => 0,
} }
} }
unsafe extern "C" fn ext_voice_info_get(
plugin: *const clap_plugin,
info: *mut clap_voice_info,
) -> bool {
check_null_ptr!(false, plugin, info);
// TODO: Allow the plugin to set the active voice count
match P::CLAP_POLY_MODULATION_CONFIG {
Some(config) => {
*info = clap_voice_info {
voice_count: config.max_voices,
voice_capacity: config.max_voices,
flags: if config.supports_overlapping_voices {
CLAP_VOICE_INFO_SUPPORTS_OVERLAPPING_NOTES
} else {
0
},
};
true
}
None => false,
}
}
} }
/// Convenience function to query an extennsion from the host. /// Convenience function to query an extennsion from the host.