macro_rules! vst_init { (fn $function_name:ident() -> $return_type:ty $body:block ) => { ... }; }
Expand description
A wrapper around the plugin_main!
macro from the vst
crate.
You call this with one parameter, which is the function declaration of a function
that creates your plugin.
This function may also do some setup (e.g. initialize logging).
Example using generic code
use rsynth::{
meta::{Meta, MetaData, Port, MidiPort, AudioPort, InOut},
event::{
ContextualEventHandler,
Timed,
RawMidiEvent,
SysExEvent
},
backend::{
HostInterface,
vst_backend::VstPluginMeta
},
ContextualAudioRenderer,
AudioHandler
};
struct MyPlugin {
meta: MetaData<&'static str, &'static str, &'static str>
// Define other fields here
}
impl Meta for MyPlugin {
type MetaData = MetaData<&'static str, &'static str, &'static str>;
fn meta(&self) -> &Self::MetaData {
&self.meta
}
}
// Use the re-exports from `rsynth` so that your code doesn't break when `rsynth` upgrades
// its dependency on `vst-rs`
use rsynth::backend::vst_backend::vst::plugin::Category;
impl VstPluginMeta for MyPlugin {
fn plugin_id(&self) -> i32 { 123 }
fn category(&self) -> Category { Category::Synth }
}
use asprim::AsPrim;
use num_traits::Float;
impl AudioHandler for MyPlugin {
// Implementation omitted for brevity.
}
impl<S, H> ContextualAudioRenderer<S, H> for MyPlugin
where
S: Float + AsPrim,
H: HostInterface,
{
// Implementation omitted for brevity.
}
impl<H> ContextualEventHandler<Timed<RawMidiEvent>, H> for MyPlugin
where
H: HostInterface,
{
// Implementation omitted for brevity.
}
impl<'a, H> ContextualEventHandler<Timed<SysExEvent<'a>>, H> for MyPlugin
where
H: HostInterface,
{
// Implementation omitted for brevity.
}
vst_init!(
fn init() -> MyPlugin {
MyPlugin {
meta: MetaData {
general_meta: "my_plugin",
audio_port_meta: InOut {
inputs: vec!["audio in 1", "audio in 2"],
outputs: vec!["audio out 1", "audio out 2"],
},
midi_port_meta: InOut {
inputs: vec!["midi in 1"],
outputs: vec![],
},
}
}
}
);
Example using VST-specific code
use rsynth::{
meta::{Meta, MetaData, Port, MidiPort, AudioPort, InOut},
event::{
ContextualEventHandler,
Timed,
RawMidiEvent,
SysExEvent
},
backend::{
HostInterface,
vst_backend::VstPluginMeta
},
ContextualAudioRenderer,
AudioHandler
};
struct MyPlugin {
meta: MetaData<&'static str, &'static str, &'static str>
// Define other fields here
}
impl Meta for MyPlugin {
type MetaData = MetaData<&'static str, &'static str, &'static str>;
fn meta(&self) -> &Self::MetaData {
&self.meta
}
}
// Use the re-exports from `rsynth` so that your code doesn't break when `rsynth` upgrades
// its dependency on `vst-rs`
use rsynth::backend::vst_backend::vst::plugin::Category;
impl VstPluginMeta for MyPlugin {
fn plugin_id(&self) -> i32 { 123 }
fn category(&self) -> Category { Category::Synth }
}
use asprim::AsPrim;
use num_traits::Float;
impl AudioHandler for MyPlugin {
// Implementation omitted for brevity.
}
// Use the re-exports from `rsynth` so that your code doesn't break when `rsynth` upgrades
// its dependency on `vst-rs`
use rsynth::backend::vst_backend::vst::plugin::HostCallback;
impl<S> ContextualAudioRenderer<S, HostCallback> for MyPlugin
where
S: Float + AsPrim,
{
fn render_buffer(&mut self, buffer: &mut AudioBufferInOut<S>, context: &mut HostCallback)
{
// Here you can call functions on the context if you want.
}
}
impl ContextualEventHandler<Timed<RawMidiEvent>, HostCallback> for MyPlugin
{
fn handle_event(&mut self, event: Timed<RawMidiEvent>, context: &mut HostCallback) {
// Here you can call functions on the context if you want.
}
}
impl<'a> ContextualEventHandler<Timed<SysExEvent<'a>>, HostCallback> for MyPlugin
{
fn handle_event(&mut self, event: Timed<SysExEvent<'a>>, context: &mut HostCallback) {
// Here you can call functions on the context if you want.
}
}
vst_init!(
fn init() -> MyPlugin {
MyPlugin {
meta: MetaData {
general_meta: "my_plugin",
audio_port_meta: InOut {
inputs: vec!["audio in 1", "audio in 2"],
outputs: vec!["audio out 1", "audio out 2"],
},
midi_port_meta: InOut {
inputs: vec!["midi in 1"],
outputs: vec![],
},
}
}
}
);