Skip to main content

clack_host/plugin/
error.rs

1use crate::host::HostHandlers;
2use crate::process::ProcessingStartError;
3use core::fmt;
4use core::fmt::{Debug, Display, Formatter};
5use std::error::Error;
6
7/// All errors that can arise using plugin instances.
8#[derive(Copy, Clone, Debug, Eq, PartialEq)]
9pub enum PluginInstanceError {
10    /// The plugin's audio processing could not be started.
11    StartProcessingFailed,
12    /// Tried to activate a plugin that was already activated.
13    AlreadyActivatedPlugin,
14    /// Tried to deactivate a plugin instance while its audio processor was still alive.
15    StillActivatedPlugin,
16    /// Attempted to perform an operation on the plugin instance's audio processor, but it was
17    /// not activated yet.
18    DeactivatedPlugin,
19    /// The plugin instance's audio processor's activation failed.
20    ActivationFailed,
21    /// No plugin with a matching ID was found during instantiation.
22    PluginNotFound,
23    /// Tried to instantiate a plugin from an entry which lacks a [`PluginFactory`](crate::factory::plugin::PluginFactory).
24    ///
25    /// This is a sign of a misbehaving plugin implementation.
26    MissingPluginFactory,
27    /// The plugin's instantiation failed.
28    InstantiationFailed,
29    /// The plugin has already been destroyed.
30    PluginDestroyed,
31    /// The plugin's audio processing failed.
32    ProcessingFailed,
33    /// Tried to perform or stop processing when the audio processor was not started yet.
34    ProcessingStopped,
35    /// Tried to start processing when the processing was already started.
36    ProcessingStarted,
37    /// The underlying plugin's `create_plugin` C function was a null pointer.
38    ///
39    /// This is a sign of a misbehaving plugin implementation.
40    NullFactoryCreatePluginFunction,
41    /// The underlying plugin's `process` C function was a null pointer.
42    ///
43    /// This is a sign of a misbehaving plugin implementation.
44    NullProcessFunction,
45    /// The underlying plugin's `activate` C function was a null pointer.
46    ///
47    /// This is a sign of a misbehaving plugin implementation.
48    NullActivateFunction,
49}
50
51impl PluginInstanceError {
52    pub(crate) fn msg(&self) -> &'static str {
53        match self {
54            Self::StartProcessingFailed => "Could not start processing",
55            Self::AlreadyActivatedPlugin => "Plugin was already activated",
56            Self::StillActivatedPlugin => {
57                "Attempted to deactivate Plugin which still has an active AudioProcessor"
58            }
59            Self::DeactivatedPlugin => "Plugin is currently deactivated",
60            Self::ActivationFailed => "Unable to activate",
61            Self::PluginNotFound => "Specified plugin was not found",
62            Self::MissingPluginFactory => "No plugin factory was provided",
63            Self::InstantiationFailed => "Could not instantiate",
64            Self::PluginDestroyed => "Plugin was destroyed",
65            Self::ProcessingFailed => "Could not process",
66            Self::ProcessingStopped => "Audio Processor is currently stopped",
67            Self::ProcessingStarted => "Audio Processor is currently started",
68            Self::NullProcessFunction => "Plugin's process function is null",
69            Self::NullActivateFunction => "Plugin's activate function is null",
70            Self::NullFactoryCreatePluginFunction => {
71                "Plugin Factory's create_plugin function is null"
72            }
73        }
74    }
75}
76
77impl Display for PluginInstanceError {
78    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
79        f.write_str(self.msg())
80    }
81}
82
83impl Error for PluginInstanceError {}
84
85impl<H: HostHandlers> From<ProcessingStartError<H>> for PluginInstanceError {
86    #[inline]
87    fn from(_: ProcessingStartError<H>) -> Self {
88        Self::StartProcessingFailed
89    }
90}