Create audio buffer and process midi

PHOTO EMBED

Sun Aug 08 2021 13:39:32 GMT+0000 (Coordinated Universal Time)

Saved by @jakobhautop

fn can_play_midi(instance: &mut PluginInstance) {
    // We need a events object..
    let events = get_midi_events();
    instance.process_events(&events);

    // We also need a AudioBuffer
    const LENGTH: usize = 1_000_000;
    let mut host_buffer: HostBuffer<f32> = HostBuffer::new(2, 2);
    let input_left = vec![1.0; LENGTH];
    let input_right = vec![1.0; LENGTH];
    let mut output_left = vec![0.0; LENGTH];
    let mut output_right = vec![0.0; LENGTH];

    let output_clone = output_left.clone();

    if output_clone.len() > 10 {
        for i in 0..10 {
            println!("Before: {:?}", output_clone.get(i));
        }
    }

    let mut audio_buffer = {
        // Slices given to `bind` need not persist, but the sample arrays do.
        let inputs = [&input_left, &input_right];
        let mut outputs = [&mut output_left, &mut output_right];
        host_buffer.bind(&inputs, &mut outputs)
    };

    instance.process(&mut audio_buffer);
    if output_left.len() > 10 {
        for i in 0..10 {
            println!("After: {:?}", output_left.get(i));
        }
    }
}
content_copyCOPY