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

Question/request for Example #5

Open
CD10h opened this issue May 1, 2024 · 1 comment
Open

Question/request for Example #5

CD10h opened this issue May 1, 2024 · 1 comment

Comments

@CD10h
Copy link

CD10h commented May 1, 2024

Could you provide a plugin example with dynamic creation/updates of parameters without using derive(Params)?
Let's say, for example, I get possible options from a file or another lib and would like to create/remove based on its contents or, as another example, enabling/disabling certain UI options or menus based on the state of another.

note: this is a great project, thank you for providing this. btw I have a branch on my fork with ntsc-rs as a quick and dirty plugin.

@tychedelia
Copy link
Owner

tychedelia commented May 1, 2024

@CD10h Thanks for using the project!

If you want to see what code is generated by #[derive(Params)], you might try running cargo expand on an example plugin. Basically, we implement a trait for a variety of types that know how to register themselves with the ParameterManager and fetch themselves from op inputs. If you are having issues with using the derive proc macro, please let me know, it may be the case that we can improve this for your types.

But, if you want to implement it manually, you basically just need to implement OperatorParams for your params struct. The register method will be called once on app initialization, in the setupParameters lifecycle method on the C++ side. The update method is called by the framework right before calling your execute method. ParameterManager's API basically matches the C++ version.

struct MyParams {
  my_float: f64,
}


impl OperatorParams for MyParams {
    fn register(&mut self, parameter_manager: &mut ParameterManager) {
        parameter_manager.append_float(NumericParameter {
            name: "Myfloat".to_string(),
            label: "My Float".to_string(),
            page: "Custom".to_string(),
            default_values: [0.0; 4],
            min_values: [0.0; 4],
            max_values: [1.0; 4],
            clamp_mins: [true; 4],
            clamp_maxes: [true; 4],
            min_sliders: [0.0; 4],
            max_sliders: [5.0; 4],
        });
    }

    fn update(&mut self, inputs: &ParamInputs) {
        self.my_float = inputs.get_float("Myfloat", 0);
    }
}

These should be roughly comparable to the C++ examples, and I'd look there for further documentation about how to use the parameter manager and read inputs back.

Then, if you wanted to initialize your param struct through something like reading a config, etc, just do that in impl OpNew constructor.

For enabling and disabling params, see the example here:

let params = inputs.params();
params.enable_param("Scale", self.params.apply_scale);
. It would definitely be cool to support doing this automatically in the proc macro, but right now it should be handled imperatively in your execute impl.

Please let me know if you have any other questions!

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

No branches or pull requests

2 participants