Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing latency and parameters dynamically #3

Open
Photosounder opened this issue Feb 25, 2024 · 3 comments
Open

Changing latency and parameters dynamically #3

Photosounder opened this issue Feb 25, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@Photosounder
Copy link

Is there a way to change things that aren't typically changed dynamically? I have two things in mind:

  • I have a linear phase equaliser that changes the latency it reports dynamically based on various parameters, but the way to report plugin latency in CPLUG seems purely passive. Looking at IPlug2's code for SetLatency() it calls VST3's IComponentHandler's restartComponent().
  • I'm making a host plugin for my WebAssembly modules, it's the same logic as a bridge plugin, the problem is that until the WebAssembly module is loaded the host plugin doesn't know what parameters it's going to have, and unless the host plugin blocks until a module is selected (I'd rather not do that) I'd need a way to dynamically change how many parameters there are and everything about them. Maybe some kind of reset would do it?

Now that I think about it I also can't make CPLUG_NUM_PARAMS a global variable because different instances of the same host plugin would host different modules with different numbers of parameters, so the number of parameters would have to come from a cplug_... callback that provides the instance pointer, for instance we could replace CPLUG_NUM_PARAMS with something like cplug_getParamCount(vst3->userPlugin), which could actually even be done as a macro for each plugin format but that would be unwieldy.

@Tremus
Copy link
Owner

Tremus commented Feb 25, 2024

cplug_getParamCount

Good idea. This works well for finding the number of params on the fly.

I'm thinking in order to notify the host of a change in latency, tail time, number of busses, and number of parameters I could pass something like this into createPlugin()

...
enum // property types
{
    CPLUG_CHANGED_LATENCY,
    CPLUG_CHANGED_TAIL_TIME,
    CPLUG_CHANGED_NUM_INPUT_BUSSES,
    CPLUG_CHANGED_NUM_OUTPUT_BUSSES,
    CPLUG_CHANGED_NUM_PARAMS,
};

struct CplugHostContext
{
    void (*propertyChanged)(struct CplugHostContext* ctx, uint32_t changedProperty);
    // ...
    // some other feature?
};

void* createPlugin(struct CplugHostContext*);
...
uint32_t cplug_getParamCount();
...

For the user, they simply save the context struct somewhere in their plugin and call the function with a property type.
For the wrapper, this context struct above could be saved within the wrapper struct, and I could use offsetof to shift the pointer back to the start of the struct and recast it.

Something like this should work perfectly well in AUv2 and CLAP (so long as hosts support it)

Thoughts?

@Photosounder
Copy link
Author

Photosounder commented Feb 26, 2024

Sounds good. I think you mean that void *cplug_createPlugin() would become void *cplug_createPlugin(struct CplugHostContext *host_context) and we'd be free to store this pointer in our instance structure and then use that pointer to actively call wrapper functions such as propertyChanged(), correct? And this host context would be what is currently the VST3Plugin, AUv2Plugin, and CLAPPlugin, but with a new unified type name, right?

@Tremus
Copy link
Owner

Tremus commented Feb 26, 2024

Yep, that's right

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants