diff --git a/src/wrapper/standalone.rs b/src/wrapper/standalone.rs index d4a32a71..078b3e56 100644 --- a/src/wrapper/standalone.rs +++ b/src/wrapper/standalone.rs @@ -1,7 +1,7 @@ //! A standalone plugin target that directly connects to the system's audio and MIDI ports instead //! of relying on a plugin host. This is mostly useful for quickly testing GUI changes. -use self::wrapper::{Wrapper, WrapperConfig}; +use self::wrapper::{Wrapper, WrapperConfig, WrapperError}; use crate::plugin::Plugin; mod context; @@ -38,17 +38,24 @@ mod wrapper; /// By default this will connect to the 'default' audio and MIDI ports. Use the command line options /// to change this. `--help` lists all available options. /// +/// If the wrapped plugin fails to initialize or throws an error during audio processing, then this +/// function will return `false`. +/// /// # TODOs /// /// The aforementioned command line options have not yet been implemented. Currently there's also no /// way to change these options at runtime, for instance through the plugin's GUI. And lastly /// there's no way to interact with parameters outside of what's exposed through the plugin's GUI. /// We should implement a REPL at some point for interacting with the plugin. -pub fn nih_export_standalone() { +pub fn nih_export_standalone() -> bool { nih_export_standalone_with_args::(std::env::args()) } -pub fn nih_export_standalone_with_args>(args: Args) { +/// The same as [`nih_export_standalone()`], but with the arguments taken from an iterator instead +/// of using [`std::env::args()`]. +pub fn nih_export_standalone_with_args>( + args: Args, +) -> bool { // TODO: Do something with the arguments // FIXME: The configuration should be set based on the command line arguments @@ -63,9 +70,21 @@ pub fn nih_export_standalone_with_args::new(config); + let wrapper = match Wrapper::

::new(config.clone()) { + Ok(wrapper) => wrapper, + Err(WrapperError::IncompatibleConfig) => { + eprintln!("The plugin does not support the {} channel input and {} channel output configuration", config.input_channels, config.output_channels); + return false; + } + Err(WrapperError::InitializationFailed) => { + eprintln!("The plugin failed to initialize"); + return false; + } + }; // TODO: Open the editor if available, do IO things // TODO: If the plugin has an editor, block until the editor is closed. Otherwise block // indefinitely or until SIGINT (how do signal handlers work in Rust?) + + true } diff --git a/src/wrapper/standalone/wrapper.rs b/src/wrapper/standalone/wrapper.rs index 4c4812c6..6e6e9c1d 100644 --- a/src/wrapper/standalone/wrapper.rs +++ b/src/wrapper/standalone/wrapper.rs @@ -6,6 +6,7 @@ use crate::context::Transport; use crate::plugin::{BufferConfig, BusConfig, Plugin}; /// Configuration for a standalone plugin that would normally be provided by the DAW. +#[derive(Debug, Clone)] pub struct WrapperConfig { /// The number of input channels. pub input_channels: u32,