2022-04-22 17:00:59 +02:00
|
|
|
//! 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.
|
|
|
|
|
2022-04-22 18:38:32 +02:00
|
|
|
use self::wrapper::{Wrapper, WrapperConfig, WrapperError};
|
2022-04-22 17:00:59 +02:00
|
|
|
use crate::plugin::Plugin;
|
|
|
|
|
2022-04-22 18:29:00 +02:00
|
|
|
mod context;
|
2022-04-22 17:00:59 +02:00
|
|
|
mod wrapper;
|
|
|
|
|
|
|
|
/// Open an NIH-plug plugin as a standalone application. If the plugin has an editor, this will open
|
|
|
|
/// the editor and block until the editor is closed. Otherwise this will block until SIGINT is
|
2022-04-22 17:17:42 +02:00
|
|
|
/// received. This is mainly useful for quickly testing plugin GUIs. In order to use this, you will
|
|
|
|
/// first need to make your plugin's main struct `pub` and expose a `lib` artifact in addition to
|
|
|
|
/// your plugin's `cdylib`:
|
|
|
|
///
|
|
|
|
/// ```toml
|
|
|
|
/// # Cargo.toml
|
|
|
|
///
|
|
|
|
/// [lib]
|
|
|
|
/// # The `lib` artifact is needed for the standalone target
|
|
|
|
/// crate-type = ["cdylib", "lib"]
|
|
|
|
/// ```
|
|
|
|
///
|
|
|
|
/// You can then create a `src/main.rs` file that calls this function:
|
|
|
|
///
|
|
|
|
/// ```ignore
|
|
|
|
/// // src/main.rs
|
|
|
|
///
|
|
|
|
/// use plugin_name::prelude::*;
|
|
|
|
///
|
|
|
|
/// use plugin_name::PluginName;
|
|
|
|
///
|
|
|
|
/// fn main() {
|
|
|
|
/// nih_export_standalone::<PluginName>();
|
|
|
|
/// }
|
|
|
|
/// ```
|
2022-04-22 17:00:59 +02:00
|
|
|
///
|
|
|
|
/// 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.
|
|
|
|
///
|
2022-04-22 18:38:32 +02:00
|
|
|
/// If the wrapped plugin fails to initialize or throws an error during audio processing, then this
|
|
|
|
/// function will return `false`.
|
|
|
|
///
|
2022-04-22 17:59:01 +02:00
|
|
|
/// # TODOs
|
2022-04-22 17:00:59 +02:00
|
|
|
///
|
2022-04-22 17:59:01 +02:00
|
|
|
/// 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.
|
2022-04-22 18:38:32 +02:00
|
|
|
pub fn nih_export_standalone<P: Plugin>() -> bool {
|
2022-04-22 17:00:59 +02:00
|
|
|
nih_export_standalone_with_args::<P, _>(std::env::args())
|
|
|
|
}
|
|
|
|
|
2022-04-22 18:38:32 +02:00
|
|
|
/// 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<P: Plugin, Args: IntoIterator<Item = String>>(
|
|
|
|
args: Args,
|
|
|
|
) -> bool {
|
2022-04-22 17:00:59 +02:00
|
|
|
// TODO: Do something with the arguments
|
|
|
|
|
2022-04-22 18:29:00 +02:00
|
|
|
// FIXME: The configuration should be set based on the command line arguments
|
|
|
|
let config = WrapperConfig {
|
|
|
|
input_channels: 2,
|
|
|
|
output_channels: 2,
|
|
|
|
sample_rate: 44100.0,
|
|
|
|
period_size: 512,
|
|
|
|
|
|
|
|
tempo: 120.0,
|
|
|
|
timesig_num: 4,
|
|
|
|
timesig_denom: 4,
|
|
|
|
};
|
|
|
|
|
2022-04-22 18:38:32 +02:00
|
|
|
let wrapper = match Wrapper::<P>::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;
|
|
|
|
}
|
|
|
|
};
|
2022-04-22 17:00:59 +02:00
|
|
|
|
|
|
|
// 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?)
|
2022-04-22 18:38:32 +02:00
|
|
|
|
|
|
|
true
|
2022-04-22 17:00:59 +02:00
|
|
|
}
|