Skip to main content

PluginInstance

Struct PluginInstance 

Source
pub struct PluginInstance<'a> { /* private fields */ }
Expand description

A wrapper around a Plugin instance.

This type is created with its new method when the host wants to instantiate a given plugin type, and is what needs to be returned by the PluginFactory::instantiate_plugin method.

Implementations§

Source§

impl<'a> PluginInstance<'a>

Source

pub fn new<P: Plugin>( host_info: HostInfo<'a>, descriptor: &'a PluginDescriptor, shared_initializer: impl FnOnce(HostSharedHandle<'a>) -> Result<P::Shared<'a>, PluginError> + 'a, main_thread_initializer: impl FnOnce(HostMainThreadHandle<'a>, &'a P::Shared<'a>) -> Result<P::MainThread<'a>, PluginError> + 'a, ) -> PluginInstance<'a>

Instantiates a plugin of a given implementation P.

Instantiated plugins also require an HostInfo instance given by the host, and a reference to the associated PluginDescriptor.

See the PluginFactory’s trait documentation for a usage example.

Source

pub fn new_with_initializer<P: Plugin, FM>( host_info: HostInfo<'a>, descriptor: &'a PluginDescriptor, initializer: impl FnOnce(HostMainThreadHandle<'a>) -> Result<(P::Shared<'a>, FM), PluginError> + 'a, ) -> PluginInstance<'a>
where FM: 'a + FnOnce(&'a P::Shared<'a>) -> Result<P::MainThread<'a>, PluginError>,

Instantiates a plugin of a given implementation P with a custom initializer.

This initializer allows to perform custom work on the main thread at initialization time before the plugin is split into its shared and main thread components.

Instantiated plugins also require an HostInfo instance given by the host, and a reference to the associated PluginDescriptor.

§Example

This example shows how to use this API to create a PluginShared struct and a PluginMainThread struct that each use one end of a channel.

use std::sync::mpsc::{channel, Receiver, Sender};

use clack_plugin::prelude::*;
use clack_plugin::entry::prelude::*;

struct MyPlugin;

impl Plugin for MyPlugin {
    type AudioProcessor<'a> = ();
    type Shared<'a> = MyPluginShared<'a>;
    type MainThread<'a> = MyPluginMainThread<'a>;
}

struct MyPluginShared<'a>(HostSharedHandle<'a>, Sender<u32>);
struct MyPluginMainThread<'a>(HostMainThreadHandle<'a>, &'a MyPluginShared<'a>, Receiver<u32>);

impl<'a> PluginShared<'a> for MyPluginShared<'a> {}
impl<'a> PluginMainThread<'a, MyPluginShared<'a>> for MyPluginMainThread<'a> {}

fn create_plugin<'a>(host_info: HostInfo<'a>) -> Result<PluginInstance<'a>, PluginError> {
    let plugin_descriptor: &'a PluginDescriptor = /* ... */
    Ok(PluginInstance::new_with_initializer::<MyPlugin, _>(host_info, plugin_descriptor, |host| {
        let (tx, rx) = channel();

        Ok((
            MyPluginShared(host.shared(), tx),
            move |shared| Ok(MyPluginMainThread(host, shared, rx))
        ))
    }))
}
Source

pub fn as_raw(&self) -> &clap_plugin

Returns a raw, C FFI-compatible reference to this plugin instance.

Trait Implementations§

Source§

impl Drop for PluginInstance<'_>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for PluginInstance<'a>

§

impl<'a> RefUnwindSafe for PluginInstance<'a>

§

impl<'a> Send for PluginInstance<'a>

§

impl<'a> Sync for PluginInstance<'a>

§

impl<'a> Unpin for PluginInstance<'a>

§

impl<'a> UnsafeUnpin for PluginInstance<'a>

§

impl<'a> UnwindSafe for PluginInstance<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.