1
0
Fork 0

Begin clap objects with vtables for pointer casts

This commit is contained in:
Robbert van der Helm 2022-02-28 16:50:16 +01:00
parent 17b51c8920
commit 31e2480458
2 changed files with 12 additions and 8 deletions

View file

@ -44,7 +44,7 @@ macro_rules! nih_export_clap {
::nih_plug::wrapper::clap::CLAP_PLUGIN_FACTORY_ID, ::nih_plug::wrapper::clap::CLAP_PLUGIN_FACTORY_ID,
) } ) }
{ {
&(*factory).clap_plugin_factory() as *const _ as *const ::std::ffi::c_void &(*factory).clap_plugin_factory as *const _ as *const ::std::ffi::c_void
} else { } else {
std::ptr::null() std::ptr::null()
} }

View file

@ -1,13 +1,16 @@
use clap_sys::plugin_factory::clap_plugin_factory; use clap_sys::plugin_factory::clap_plugin_factory;
use std::marker::PhantomData; use std::marker::PhantomData;
use std::mem;
use crate::ClapPlugin; use crate::ClapPlugin;
/// The plugin's factory. Initialized using a lazy_static from the entry poiunt's `get_factory()` /// The plugin's factory. Initialized using a lazy_static from the entry poiunt's `get_factory()`
/// function. From this point onwards we don't need to generate code with macros anymore. /// function. From this point onwards we don't need to generate code with macros anymore.
#[doc(hidden)] #[doc(hidden)]
#[repr(C)]
pub struct Factory<P: ClapPlugin> { pub struct Factory<P: ClapPlugin> {
// Keep the vtable as the first field so we can do a simple pointer cast
pub clap_plugin_factory: clap_plugin_factory,
/// The type will be used for constructing plugin instances later. /// The type will be used for constructing plugin instances later.
_phantom: PhantomData<P>, _phantom: PhantomData<P>,
} }
@ -15,17 +18,18 @@ pub struct Factory<P: ClapPlugin> {
impl<P: ClapPlugin> Default for Factory<P> { impl<P: ClapPlugin> Default for Factory<P> {
fn default() -> Self { fn default() -> Self {
Self { Self {
clap_plugin_factory: clap_plugin_factory {
get_plugin_count: Self::get_plugin_count,
get_plugin_descriptor: todo!(),
create_plugin: todo!(),
},
_phantom: PhantomData, _phantom: PhantomData,
} }
} }
} }
impl<P: ClapPlugin> Factory<P> { impl<P: ClapPlugin> Factory<P> {
pub fn clap_plugin_factory(&self) -> clap_plugin_factory { unsafe extern "C" fn get_plugin_count(_factory: *const clap_plugin_factory) -> u32 {
clap_plugin_factory { 1
get_plugin_count: todo!(),
get_plugin_descriptor: todo!(),
create_plugin: todo!(),
}
} }
} }