### Build and Run Binary Source: https://github.com/geom3trik/vizia-vst-demo/blob/main/guide/part1.md Builds and runs the binary executable. This command compiles and executes the `src/bin.rs` file. ```bash cargo run --bin vizia_vst_demo ``` -------------------------------- ### Rust Binary Entry Point Source: https://github.com/geom3trik/vizia-vst-demo/blob/main/guide/part1.md A simple `main` function for the binary executable. This serves as the entry point for the standalone application. ```rust fn main() { println!("Hello World"); } ``` -------------------------------- ### Build VST Library Source: https://github.com/geom3trik/vizia-vst-demo/blob/main/guide/part1.md Builds the Rust project as a dynamic library (VST). This command compiles the library crate. ```bash cargo build --lib ``` -------------------------------- ### Create Rust Library Project Source: https://github.com/geom3trik/vizia-vst-demo/blob/main/guide/part1.md Initializes a new Rust library project using Cargo. This command sets up the basic directory structure and `Cargo.toml` for a library. ```bash cargo new --lib vizia_vst_demo ``` -------------------------------- ### Cargo.toml Configuration for VST and Binary Source: https://github.com/geom3trik/vizia-vst-demo/blob/main/guide/part1.md Configures the `cargo.toml` file to define the library as a dynamic library (`cdylib`) and specify the binary target. ```toml [lib] name = "vizia_vst_demo" path = "src/lib.rs" crate-type = ["cdylib"] [[bin]] name = "vizia_vst_demo" path = "src/bin.rs" ``` -------------------------------- ### VIZIA VST Demo: `bin.rs` Setup Source: https://github.com/geom3trik/vizia-vst-demo/blob/main/guide/part4.md This Rust code snippet is for the `bin.rs` file, allowing the VIZIA VST demo application to be run directly. It initializes the application with a specified window description and the plugin's GUI. ```rust use std::sync::Arc; use vizia::{WindowDescription, Application}; mod dsp; use dsp::*; mod ui; use ui::*; fn main() { let params = Arc::new(GainEffectParameters::default()); let window_description = WindowDescription::new() .with_inner_size(300, 300) .with_title("Hello Plugin"); Application::new(window_description, move |cx|{ plugin_gui(cx, Arc::clone(¶ms)); }).run(); } ``` -------------------------------- ### Cargo.toml Dependencies for VST Source: https://github.com/geom3trik/vizia-vst-demo/blob/main/guide/part1.md Adds necessary dependencies to `cargo.toml` for VST development, including `vst`, `vizia` with `baseview` features, and utilities like `dirs` and logging. ```toml raw-window-handle = "0.3" vst = "0.2.1" vizia = {git = "https://github.com/geom3trik/VIZIA", branch = "main", features = ["baseview"], default-features = false} dirs = "3" log = "0.4" log-panics = "2" simplelog = "0.8" ``` -------------------------------- ### Run VIZIA VST Demo Application Source: https://github.com/geom3trik/vizia-vst-demo/blob/main/guide/part4.md This command compiles and runs the VIZIA VST demo application using Cargo. It executes the `bin.rs` file to launch the standalone VIZIA GUI. ```bash cargo run --bin vizia_vst_demo ``` -------------------------------- ### Build and Run Standalone Application (Rust) Source: https://github.com/geom3trik/vizia-vst-demo/blob/main/README.md Builds and runs the VST demo project as a standalone application in release mode using Cargo. This command compiles and executes the main binary. ```Rust cargo run --release --bin vizia_vst_demo ``` -------------------------------- ### VIZIA VST Demo: `lib.rs` Editor Trait Integration Source: https://github.com/geom3trik/vizia-vst-demo/blob/main/guide/part4.md This Rust code snippet is added to the `open` method within the `Editor` trait implementation in `lib.rs`. It initializes the VIZIA application and opens the plugin's GUI, parented to the host window. ```rust let params = self.params.clone(); let window_description = WindowDescription::new() .with_inner_size(300, 300) .with_title("Hello Plugin"); Application::new(window_description, move |cx| { plugin_gui(cx, params.clone()); }).open_parented(&ParentWindow(parent)); ``` -------------------------------- ### Instantiate VIZIA Data and Build UI (Rust) Source: https://github.com/geom3trik/vizia-vst-demo/blob/main/guide/part4.md Shows how to instantiate the `Params` data wrapper and call its `build` method within a VIZIA GUI function. ```rust Params { gain: params.clone(), }.build(cx); ``` -------------------------------- ### VIZIA GUI Function Signature (Rust) Source: https://github.com/geom3trik/vizia-vst-demo/blob/main/guide/part4.md Defines the entry point function `plugin_gui` in Rust for VIZIA, which takes a VIZIA `Context` and plugin parameters to build the GUI. ```rust pub fn plugin_gui(cx: &mut Context, params: Arc) { } ``` -------------------------------- ### Build VST Plugin Library (Rust) Source: https://github.com/geom3trik/vizia-vst-demo/blob/main/README.md Builds the VST plugin library in release mode using Cargo. This command compiles the Rust code for the plugin. ```Rust cargo build --release --lib ``` -------------------------------- ### Rust VST Plugin Struct Source: https://github.com/geom3trik/vizia-vst-demo/blob/main/guide/part3.md Defines the main plugin structure, containing parameters and an optional editor instance. ```rust struct GainPlugin { params: Arc, editor: Option, } ``` -------------------------------- ### Build VST Plugin with Cargo Source: https://github.com/geom3trik/vizia-vst-demo/blob/main/guide/part3.md This command uses the Rust package manager, Cargo, to build the VST plugin. The `--lib` flag indicates that the crate should be compiled as a library, which is standard for VST plugins. ```bash cargo build --lib ``` -------------------------------- ### Apply VIZIA Widget Styling (Rust) Source: https://github.com/geom3trik/vizia-vst-demo/blob/main/guide/part4.md Demonstrates applying direct styling properties to a VIZIA `VStack` widget, such as background color and child spacing. ```rust VStack::new(cx, |cx|{ Label::new(cx, "GAIN"); let map = GenericMap::new(0.0, 1.0, ValueScaling::Linear, DisplayDecimals::Two, None); Knob::new(cx, map.clone(), 1.0).on_changing(cx, |knob, cx|{ cx.emit(ParamChangeEvent::SetGain(knob.normalized_value)); }); Binding::new(cx, Params::gain, move |cx, gain|{ let amplitude = gain.get(cx).amplitude.get(); Label::new(cx, &map.normalized_to_display(amplitude)); }); }).background_color(Color::rgb(80, 80, 80)).child_space(Stretch(1.0)).row_between(Pixels(10.0)); ``` -------------------------------- ### Create VIZIA Knob with Event Emission (Rust) Source: https://github.com/geom3trik/vizia-vst-demo/blob/main/guide/part4.md Illustrates creating a VIZIA `Knob` widget, configuring its mapping, and using the `on_changing` callback to emit a `ParamChangeEvent` with the knob's value. ```rust let map = GenericMap::new(0.0, 1.0, ValueScaling::Linear, DisplayDecimals::Two, None); Knob::new(cx, map.clone(), 1.0).on_changing(cx, |knob, cx|{ cx.emit(ParamChangeEvent::SetGain(knob.normalized_value)); }); ``` -------------------------------- ### Create VIZIA Label with Data Binding (Rust) Source: https://github.com/geom3trik/vizia-vst-demo/blob/main/guide/part4.md Shows how to create a VIZIA `Label` widget bound to data using `Binding` and a lens, displaying the current amplitude value from the plugin parameters. ```rust Binding::new(cx, Params::gain, move |cx, gain|{ let amplitude = gain.get(cx).amplitude.get(); Label::new(cx, &map.normalized_to_display(amplitude)); }); ``` -------------------------------- ### Create VIZIA VStack Widget (Rust) Source: https://github.com/geom3trik/vizia-vst-demo/blob/main/guide/part4.md Demonstrates creating a `VStack` widget in VIZIA, which arranges its children vertically, using a closure for its content. ```rust VStack::new(cx, |cx|{ ... }) ``` -------------------------------- ### Build VIZIA VST Plugin Source: https://github.com/geom3trik/vizia-vst-demo/blob/main/guide/part4.md This command builds the VIZIA VST plugin library using Cargo. It compiles the Rust code into a shared library format suitable for VST hosts. ```bash cargo build --lib ``` -------------------------------- ### Rust VST Plugin Imports Source: https://github.com/geom3trik/vizia-vst-demo/blob/main/guide/part3.md Imports necessary types from the vst crate for audio buffer, editor, plugin, and utility functionalities. ```rust use vst::buffer::AudioBuffer; use vst::editor::Editor; use vst::plugin::{Category, Info, Plugin, PluginParameters}; use vst::util::AtomicFloat; ``` -------------------------------- ### Rust VST Plugin Trait Implementation Source: https://github.com/geom3trik/vizia-vst-demo/blob/main/guide/part3.md Implements the Plugin trait for the GainPlugin, defining plugin metadata, initialization, editor retrieval, and audio processing logic. ```rust impl Plugin for GainPlugin { fn get_info(&self) -> Info { Info { name: "Vizia Gain Effect in Rust".to_string(), vendor: "Geom3trik".to_string(), unique_id: 243213073, version: 1, inputs: 2, outputs: 2, // This `parameters` bit is important; without it, none of our // parameters will be shown! parameters: 1, category: Category::Effect, ..Default::default() } } // This is called once when the plugin instance is created by the host // and is used here to setup some logging fn init(&mut self) { let log_folder = ::dirs::home_dir().unwrap().join("tmp"); let _ = ::std::fs::create_dir(log_folder.clone()); let log_file = ::std::fs::File::create(log_folder.join("vizia_vst_demo.log")).unwrap(); let log_config = ::simplelog::ConfigBuilder::new() .set_time_to_local(true) .build(); let _ = ::simplelog::WriteLogger::init(simplelog::LevelFilter::Info, log_config, log_file); ::log_panics::init(); ::log::info!("init"); } fn get_editor(&mut self) -> Option> { if let Some(editor) = self.editor.take() { Some(Box::new(editor) as Box) } else { None } } // This is where the audio processing code will go fn process(&mut self, buffer: &mut AudioBuffer) { // Read the amplitude from the parameter object let amplitude = self.params.amplitude.get(); // First, we destructure our audio buffer into an arbitrary number of // input and output buffers. Usually, we'll be dealing with stereo (2 of each) // but that might change. for (input_buffer, output_buffer) in buffer.zip() { // Loop through each sample and apply the amplitude value to it for (input_sample, output_sample) in input_buffer.iter().zip(output_buffer) { *output_sample = *input_sample * amplitude; } } } } ``` -------------------------------- ### VIZIA VST Demo: `lib.rs` UI Module Source: https://github.com/geom3trik/vizia-vst-demo/blob/main/guide/part4.md This Rust code snippet adds the `ui` module to the plugin's `lib.rs` file. This is necessary for the plugin to recognize and use the UI components defined in the `ui` module. ```rust mod ui; use ui::*; ``` -------------------------------- ### Rust VST Plugin Editor Struct Source: https://github.com/geom3trik/vizia-vst-demo/blob/main/guide/part3.md Defines the structure for the plugin's editor, holding parameters and state for the UI window. ```rust struct GainPluginEditor { params: Arc, is_open: bool, } ``` -------------------------------- ### Define VIZIA Data Wrapper (Rust) Source: https://github.com/geom3trik/vizia-vst-demo/blob/main/guide/part4.md Defines a Rust struct `Params` to wrap plugin parameters for VIZIA, enabling reactive data binding with the `#[derive(Lens)]` macro. ```rust #[derive(Lens)] pub struct Params { gain: Arc } ``` -------------------------------- ### VIZIA CSS Styling (CSS) Source: https://github.com/geom3trik/vizia-vst-demo/blob/main/guide/part4.md Provides a CSS stylesheet for VIZIA to apply global styles to labels and knobs, including font size, color, and dimensions. ```css const STYLE: &str = r#"\n\n label {\n font-size: 20;\n color: #C2C2C2;\n }\n\n knob {\n width: 70px;\n height: 70px;\n }\n \n knob .track {\n background-color: #ffb74d;\n }\n\n"#; ``` -------------------------------- ### Rust VST Plugin Default Implementation Source: https://github.com/geom3trik/vizia-vst-demo/blob/main/guide/part3.md Implements the Default trait for the GainPlugin, initializing parameters and the editor. ```rust impl Default for GainPlugin { fn default() -> Self { let params = Arc::new(GainEffectParameters::default()); Self { params: params.clone(), editor: Some(GainPluginEditor { params: params.clone(), is_open: false, }), } } } ``` -------------------------------- ### Rust VST Plugin Implementation Source: https://github.com/geom3trik/vizia-vst-demo/blob/main/guide/part3.md This Rust code defines a VST plugin, likely named GainPlugin, and includes a method to retrieve its parameter object. It's part of a larger VST audio plugin development context. ```rust } } // Return the parameter object fn get_parameter_object(&mut self) -> Arc { Arc::clone(&self.params) as Arc } ``` Finally, add the following to the end of the file: ```rust plugin_main!(GainPlugin); ``` -------------------------------- ### Rust VST Editor Trait Implementation Source: https://github.com/geom3trik/vizia-vst-demo/blob/main/guide/part3.md Implements the Editor trait for the plugin editor struct, defining window position, size, and lifecycle methods like open, is_open, and close. ```rust impl Editor for GainPluginEditor { // Determines the initial position of the plugin editor window fn position(&self) -> (i32, i32) { (0, 0) } // Determines the initial size of the plugin editor window fn size(&self) -> (i32, i32) { (300, 300) } // Called by the host to open the plugin editor window fn open(&mut self, parent: *mut ::std::ffi::c_void) -> bool { if self.is_open { return false; } self.is_open = true; true } fn is_open(&mut self) -> bool { self.is_open } // Called by the host to close the plugin editor window fn close(&mut self) { self.is_open = false; } } ``` -------------------------------- ### Implement VIZIA Model for Data Handling (Rust) Source: https://github.com/geom3trik/vizia-vst-demo/blob/main/guide/part4.md Implements the `Model` trait for the `Params` struct in Rust, defining an `event` method to handle `ParamChangeEvent` and update plugin parameters. ```rust impl Model for Params { fn event(&mut self, cx: &mut Context, event: &mut Event) { if let Some(param_change_event) = event.message.downcast() { match param_change_event { ParamChangeEvent::SetGain(new_gain) => { self.gain.amplitude.set(*new_gain); } } } } } ``` -------------------------------- ### Rust VST Plugin Imports (Arc and DSP) Source: https://github.com/geom3trik/vizia-vst-demo/blob/main/guide/part3.md Imports the Arc type for shared ownership and the local dsp module for custom DSP logic. ```rust use std::sync::Arc; mod dsp; use dsp::*; ``` -------------------------------- ### Define VST Plugin Parameters in Rust Source: https://github.com/geom3trik/vizia-vst-demo/blob/main/guide/part2.md This Rust code defines the `GainEffectParameters` struct to hold VST plugin parameters, specifically an `amplitude` using `AtomicFloat` for thread-safe access. It implements the `Default` trait to set an initial amplitude of 1.0 and the `PluginParameters` trait to handle parameter retrieval, setting, text display, and naming for the VST host. ```Rust use vst::{util::AtomicFloat, plugin::PluginParameters}; // The parameters of the plugin pub struct GainEffectParameters { pub amplitude: AtomicFloat, } impl Default for GainEffectParameters { fn default() -> GainEffectParameters { GainEffectParameters { amplitude: AtomicFloat::new(1.0), } } } impl PluginParameters for GainEffectParameters { // the `get_parameter` function reads the value of a parameter. fn get_parameter(&self, index: i32) -> f32 { match index { 0 => self.amplitude.get(), _ => 0.0, } } // the `set_parameter` function sets the value of a parameter. fn set_parameter(&self, index: i32, val: f32) { match index { 0 => self.amplitude.set(val), _ => (), } } // This is what will display underneath the control produced by the host fn get_parameter_text(&self, index: i32) -> String { match index { 0 => format!("{:.2}", (self.amplitude.get() - 0.5) * 2f32), _ => "".to_string(), } } // This shows the control's name fn get_parameter_name(&self, index: i32) -> String { match index { 0 => "Amplitude", _ => "", } .to_string() } } ``` -------------------------------- ### Define VIZIA Event Type (Rust) Source: https://github.com/geom3trik/vizia-vst-demo/blob/main/guide/part4.md Defines a Rust enum `ParamChangeEvent` to represent custom events for mutating plugin parameters from the VIZIA GUI, such as setting gain. ```rust #[derive(Debug)] pub enum ParamChangeEvent { SetGain(f32), } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.