[LV2] LV2 Question

Harry van Haaren harryhaaren at gmail.com
Thu Nov 21 06:51:43 PST 2013

On Thu, Nov 21, 2013 at 2:44 PM, Warren Koontz <profwub at gmail.com> wrote:

>  it appears that I should instantiate a Multiverb object in "activate",
> apply it in "run" and delete it in "deactivate".
Not exactly:
-instantiate is where you instantiate (malloc / new) your plugin

-activate is called *before* processing starts
-deactivate is called when processing is stopping.

Activate & deactivate might be useful to clear your reverb delay lines etc:
its primary use is for transport relocation in a DAW & similar use cases
where state like delay lines become invalidated.

-run is the "process" function yes, where the actual DSP code goes.

> So the object needs to be accessible in all three functions. I see two
> ways to do this:
>    1. Declare a pointer to a Multiverb object as a static variatle (static
>    Multiverb *revMono) near the top of the file containing the LV2
>    functions.
>    2. Declare a pointer to a Multiverb object as a member of the same
>    structure that contains the port variables.
> Option 2 is correct.

Option 1 is horrible. Static state in a plugin means that only one instance
of that plugin can be loaded: your plugin will crash the host if two are
used. Never use static variables*.

I also need to have access to the sampling rate, which I can get when
> "instantiate" is called. I can also save this as a static or a member of
> the above mentioned structure.

Since you're now creating (new / malloc) in instantiate(), you can keep the
SR in the struct with the ports too.

Good luck! -Harry

*Ok, there are exceptional circumstances where this might OK, but this
isn't one of them.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lv2plug.in/pipermail/devel-lv2plug.in/attachments/20131121/8d6638bf/attachment-0002.htm>

More information about the Devel mailing list