diff --git a/src/context.rs b/src/context.rs index b16425b8..b573cee3 100644 --- a/src/context.rs +++ b/src/context.rs @@ -1,5 +1,7 @@ //! Different contexts the plugin can use to make callbacks to the host in different...contexts. +use std::fmt::Display; + use crate::midi::NoteEvent; use crate::param::internals::ParamPtr; use crate::param::Param; @@ -16,6 +18,9 @@ use crate::wrapper::state::PluginState; // The implementing wrapper needs to be able to handle concurrent requests, and it should perform // the actual callback within [MainThreadQueue::do_maybe_async]. pub trait ProcessContext { + /// Get the current plugin API. + fn plugin_api(&self) -> PluginApi; + /// Get information about the current transport position and status. fn transport(&self) -> &Transport; @@ -77,6 +82,10 @@ pub trait ProcessContext { // The implementing wrapper can assume that everything is being called from the main thread. Since // NIH-plug doesn't own the GUI event loop, this invariant cannot be part of the interface. pub trait GuiContext: Send + Sync + 'static { + /// Get the current plugin API. This may be useful to display in the plugin's GUI as part of an + /// about screen. + fn plugin_api(&self) -> PluginApi; + /// Ask the host to resize the editor window to the size specified by /// [`Editor::size()`][crate::prelude::Editor::size()]. This will return false if the host /// somehow didn't like this and rejected the resize, in which case the window should revert to @@ -186,6 +195,23 @@ pub struct ParamSetter<'a> { pub raw_context: &'a dyn GuiContext, } +/// The currently active plugin API. This may be useful to display in an about screen in the +/// plugin's GUI for debugging purposes. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum PluginApi { + Clap, + Vst3, +} + +impl Display for PluginApi { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + PluginApi::Clap => write!(f, "CLAP"), + PluginApi::Vst3 => write!(f, "VST3"), + } + } +} + // TODO: These conversions have not really been tested yet, there might be an error in there somewhere impl Transport { /// Initialize the transport struct without any information. diff --git a/src/prelude.rs b/src/prelude.rs index 622140ec..49d73337 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -13,7 +13,7 @@ pub use crate::formatters; pub use crate::util; pub use crate::buffer::Buffer; -pub use crate::context::{GuiContext, ParamSetter, ProcessContext}; +pub use crate::context::{GuiContext, ParamSetter, PluginApi, ProcessContext}; // This also includes the derive macro pub use crate::midi::{control_change, MidiConfig, NoteEvent}; pub use crate::param::enums::{Enum, EnumParam}; diff --git a/src/wrapper/clap/context.rs b/src/wrapper/clap/context.rs index f128cb39..3947f70a 100644 --- a/src/wrapper/clap/context.rs +++ b/src/wrapper/clap/context.rs @@ -4,7 +4,7 @@ use std::sync::atomic::Ordering; use std::sync::Arc; use super::wrapper::{OutputParamEvent, Task, Wrapper}; -use crate::context::{GuiContext, ProcessContext, Transport}; +use crate::context::{GuiContext, PluginApi, ProcessContext, Transport}; use crate::event_loop::EventLoop; use crate::midi::NoteEvent; use crate::param::internals::ParamPtr; @@ -28,6 +28,10 @@ pub(crate) struct WrapperProcessContext<'a, P: ClapPlugin> { } impl GuiContext for WrapperGuiContext

{ + fn plugin_api(&self) -> PluginApi { + PluginApi::Clap + } + fn request_resize(&self) -> bool { self.wrapper.request_resize() } @@ -92,6 +96,10 @@ impl GuiContext for WrapperGuiContext

{ } impl ProcessContext for WrapperProcessContext<'_, P> { + fn plugin_api(&self) -> PluginApi { + PluginApi::Clap + } + fn transport(&self) -> &Transport { &self.transport } diff --git a/src/wrapper/vst3/context.rs b/src/wrapper/vst3/context.rs index 322f4d6b..f98ceca1 100644 --- a/src/wrapper/vst3/context.rs +++ b/src/wrapper/vst3/context.rs @@ -5,7 +5,7 @@ use std::sync::Arc; use vst3_sys::vst::{IComponentHandler, RestartFlags}; use super::inner::{Task, WrapperInner}; -use crate::context::{GuiContext, ProcessContext, Transport}; +use crate::context::{GuiContext, PluginApi, ProcessContext, Transport}; use crate::midi::NoteEvent; use crate::param::internals::ParamPtr; use crate::plugin::Vst3Plugin; @@ -29,6 +29,10 @@ pub(crate) struct WrapperProcessContext<'a, P: Vst3Plugin> { } impl GuiContext for WrapperGuiContext

{ + fn plugin_api(&self) -> PluginApi { + PluginApi::Vst3 + } + fn request_resize(&self) -> bool { let task_posted = self.inner.do_maybe_async(Task::RequestResize); nih_debug_assert!(task_posted, "The task queue is full, dropping task..."); @@ -102,6 +106,10 @@ impl GuiContext for WrapperGuiContext

{ } impl ProcessContext for WrapperProcessContext<'_, P> { + fn plugin_api(&self) -> PluginApi { + PluginApi::Vst3 + } + fn transport(&self) -> &Transport { &self.transport }