Macro rsynth::vst_init [−][src]
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).
The plugin is typically a custom data type and should implement
the following traits:
Traits for meta-data (Note: you can use the Meta
trait for this.
CommonPluginMeta
(name of the plugin etc),AudioHandlerMeta
(number of audio ports),CommonAudioPortMeta
(names of the audio in and out ports) andVstPluginMeta
, (VST-specific meta-data)
Traits for rendering audio
AudioHandler
,ContextualAudioRenderer
<f32,
HostCallback
>
andContextualAudioRenderer
<f64,
HostCallback
>
Traits for handling midi events
ContextualEventHandler
<
Timed
<
RawMidiEvent
>,
HostCallback
>
andContextualEventHandler
<
Timed
<
SysExEvent
>,
HostCallback
>
.
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 num_traits::Float; impl AudioHandler for MyPlugin { // Implementation omitted for brevity. } impl<S, H> ContextualAudioRenderer<S, H> for MyPlugin where S: Float, 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 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, { 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![], }, } } } );