Skip to main content

Module plugin

Module plugin 

Source
Expand description

Core types and traits to implement a Clack plugin.

The PluginAudioProcessor trait is the main one required to be implemented for a Clack plugin. It can also be associated to two more types, implementing PluginMainThread and PluginShared, following the CLAP thread model, as described below.

§Thread model

CLAP’s thread model for plugins is split into three classes of operations: those happening in an audio processing thread, those happening in the main thread, and thread-safe operations:

  • The audio thread ([audio-thread] in the CLAP specification): this is represented by a type implementing the main PluginAudioProcessor trait (also named the audio processor), which is Send but !Sync, and is the only one required to implement a Clack plugin.

    This type handles all DSP in one of the host’s audio threads, of which there may be multiple, if the host uses a thread pool for example.

    The host is free to Send the PluginAudioProcessor type between any of its audio threads, but any operation of this class is guaranteed to be exclusive (&mut) to a single audio thread.

    One exception is for CLAP plugins’ activation and deactivation (represented in Clack by the plugin type’s construction and destruction), which is guaranteed to happen in the Main Thread instead. This allows the plugin’s activate and deactivate methods to receive temporary exclusive references to the main thread type during its construction and destruction.

  • The main thread ([main-thread] in the CLAP specification): this is represented by a type implementing the PluginMainThread trait, which is neither Send nor Sync. If main-thread operations are not needed by a plugin implementation, () can be used instead.

    This type can handle all non-thread-safe operations, such as those related to GUI handling, however extensions can extend its use to more kinds of operations.

    The host cannot Send this type to any other threads, and this type has to be constructed before any other operation is done on the plugin.

  • Thread-safe operations ([thread-safe] in the CLAP specification) are represented by a type implementing the PluginShared trait, which is both Send and Sync, and will be shared between the main thread and the audio thread. If it isn’t needed , () can be used instead.

    It can be used to hold read-only data (such as all the detected host extensions), or to hold any other kind of synchronized state.

    However, it should be noted that this type can be used by the host simultaneously from threads that are neither the main thread nor the audio thread.

Modules§

features
A set of standard plugin features meant to be used for a plugin descriptor’s features.

Structs§

FeaturesIter
An iterator over a PluginDescriptor’s features list.
PluginDescriptor
Provides metadata about a given Plugin, such as its ID, name, version, and more.
PluginInstance
A wrapper around a Plugin instance.

Enums§

PluginError
A generic, type-erased error type for plugin-originating errors.

Traits§

Plugin
The main trait required to implement a CLAP plugin.
PluginAudioProcessor
The audio processor and main part of a plugin.
PluginMainThread
The part of the data and operation of a plugin that must be on the main thread.
PluginShared
The part of the data and operations of a plugin that are thread-safe.