Closed hughfdjackson closed 7 years ago
What's the error?
I think you have to drop buffer
to be able to access out1
and out2
afterwards.
Because it holds references to them.
Maybe do this instead:
let mut in1 = vec![0.0; 1024]; // just to make the frame length right
let mut out1 = in1.clone();
let mut out2 = in1.clone();
{
let buffer = AudioBuffer::new(vec![&mut in1], vec![&mut out1, &mut out2]);
instance.process(buffer);
} // buffer gets dropped here
// read from out1, out2
And I think you should tell the plugin the sample rate and block size before you process()
.
https://github.com/overdrivenpotato/rust-vst2/blob/master/src/plugin.rs#L546
https://github.com/overdrivenpotato/rust-vst2/blob/master/src/plugin.rs#L549
And everytime you change the buffer size or sample rate, call suspend()
on the plugin, then change them, then resume()
.
If you want to know exactly what you should do on a plugin before processing, see what other hosts do: Write a plugin that just logs the calls that the host does, to a file using log4rs, and then do the same. I did that a while ago but I don't remember everything they do, but they usually call can_do()
, e.g. with CanDo::ReceiveEvents
if they want to send midi to it.
@Boscop : thanks a lot for that. I was getting errors like:
error[E0499]: cannot borrow `out1` as mutable more than once at a time
--> src/main.rs:85:28
|
80 | let buffer = AudioBuffer::new(vec![&mut in1], vec![&mut out1, &mut out2]);
| ---- first mutable borrow occurs here
...
85 | println!("{:#?}", &mut out1);
| ^^^^ second mutable borrow occurs here
...
92 | }
| - first borrow ends here
As you explained, it was because the buffer had not yet been dropped. Once I limited the scope of the buffer, and only accessed out1
, out2
or in1
after that, the borrower was happy again :)
I've also taken your advice about setting up the plugin with the sample rate and block size - will take a look at loading a 'debugging-based' plugin for use in other hosts. I think that will help me also know what midi events I need to send to my current plugin to get it to work :)
Hi - I'm afraid I'm very new to rust, so this problem is almost certainly with my understanding rather than the library. But just in case I have identified a genuine issue, here's a ticket.
I'm attempting to pass a midi note to an instrument VST, and get the audio out of that VST (with the hopes of eventually playing it ;))
The way I think rust-vst2 wants me to do this is to process the buffer using the plugin instance, and then at some later point to inspect the AudioBuffer I sent into it. However, if I attempt to access the AudioBuffer (
buffer
) or the one mutable vectors (in1
,out1
orout2
) that make it up afterinstance.process(buffer);
, I get a borrower check error.I can understand from the rust docs that this is expected behaviour, but does that then render it impossible to get audio data out of the VST?