Read/Write params on plugin

PHOTO EMBED

Sun Aug 08 2021 12:26:45 GMT+0000 (UTC)

Saved by @jakobhautop

extern crate vst;

use std::path::Path;
use std::sync::{Arc, Mutex};

use vst::host::{Host, PluginLoader};
use vst::plugin::Plugin;

struct SampleHost;

impl Host for SampleHost {
    fn automate(&self, index: i32, value: f32) {
        println!("Parameter {} had its value changed to {}", index, value);
    }
}

fn main() {
    let host = Arc::new(Mutex::new(SampleHost));
    let path = Path::new("./Serum.vst/Contents/MacOs/Serum");

    let mut loader = PluginLoader::load(path, host.clone()).unwrap();
    let mut instance = loader.instance().unwrap();

    println!("Loaded {}", instance.get_info().name);

    for i in 0..5 {
        println!(
            "Can we get parameter values?: {:?} ",
            instance.get_parameter_object().get_parameter(i)
        );
        println!(
            "Can we get parameter names?: {:?} ",
            instance.get_parameter_object().get_parameter_name(i)
        );
    }
    for i in 0..5 {
        instance.get_parameter_object().set_parameter(i, 0.6)
    }

    for i in 0..5 {
        println!(
            "Can we get parameter values?: {:?} ",
            instance.get_parameter_object().get_parameter(i)
        );
        println!(
            "Can we get parameter names?: {:?} ",
            instance.get_parameter_object().get_parameter_name(i)
        );
    }

    println!("Can we see info?: {:?} ", instance.get_info());

    instance.init();
    println!("Initialized instance!");

    println!("Closing instance...");
    // Not necessary as the instance is shut down when it goes out of scope anyway.
    // drop(instance);
}
content_copyCOPY

https://rustaudio.github.io/vst-rs/vst/