Add a way to find out the current plugin API
This commit is contained in:
parent
2bc77ed691
commit
b88707769a
|
@ -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.
|
||||
|
|
|
@ -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};
|
||||
|
|
|
@ -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<P: ClapPlugin> GuiContext for WrapperGuiContext<P> {
|
||||
fn plugin_api(&self) -> PluginApi {
|
||||
PluginApi::Clap
|
||||
}
|
||||
|
||||
fn request_resize(&self) -> bool {
|
||||
self.wrapper.request_resize()
|
||||
}
|
||||
|
@ -92,6 +96,10 @@ impl<P: ClapPlugin> GuiContext for WrapperGuiContext<P> {
|
|||
}
|
||||
|
||||
impl<P: ClapPlugin> ProcessContext for WrapperProcessContext<'_, P> {
|
||||
fn plugin_api(&self) -> PluginApi {
|
||||
PluginApi::Clap
|
||||
}
|
||||
|
||||
fn transport(&self) -> &Transport {
|
||||
&self.transport
|
||||
}
|
||||
|
|
|
@ -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<P: Vst3Plugin> GuiContext for WrapperGuiContext<P> {
|
||||
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<P: Vst3Plugin> GuiContext for WrapperGuiContext<P> {
|
|||
}
|
||||
|
||||
impl<P: Vst3Plugin> ProcessContext for WrapperProcessContext<'_, P> {
|
||||
fn plugin_api(&self) -> PluginApi {
|
||||
PluginApi::Vst3
|
||||
}
|
||||
|
||||
fn transport(&self) -> &Transport {
|
||||
&self.transport
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue