cross-platform / dspatch

The Refreshingly Simple Cross-Platform C++ Dataflow / Patching / Pipelining / Graph Processing / Stream Processing / Reactive Programming Framework
https://flowbasedprogramming.com/
BSD 2-Clause "Simplified" License
216 stars 44 forks source link

is there a way to define parameters for a component? #45

Closed zanazakaryaie closed 1 year ago

zanazakaryaie commented 1 year ago

Let's say I want to implement a subtractor component that gets two numbers as inputs, subtracts them, and outputs the result. Now I want to have a boolean parameter, named "absolute value", for this component. When the value is true, the absolute difference is sent to the output, and when the value is false, the normal difference is sent to the output. I know I can do this by adding a third input but this does not feel good. A subtractor is expected to get two inputs. The behavior should be controlled using parameters.

MarcusTomlinson commented 1 year ago

Hey @zanazakaryaie, is a method on the class not sufficient? SetAbs(bool) or whatever

MarcusTomlinson commented 1 year ago

There was a built-in parameter system in DSPatch for a short time. Decided that it was out of scope for the project.

You can use methods, additional inputs, or even a base class between DSPatch::Component and your own to do parameterisation pretty easily.

zanazakaryaie commented 1 year ago

Thanks for the reply @MarcusTomlinson

Actually, I was looking for a way to define parameters for each component and then be able to set them using the GUI. For example, when I left-click on a component, a box will be opened showing all the parameters that I can set for that particular component. These parameters can be of different types: string, bool, float, int, enum, etc.

It would be ideal if these parameters have a flag named "visibility". This way, I can hide a parameter during rendering if the user set a specific value for another parameter. For example, let's say we have a component named "ImageSmoother" which uses low-pass filtering to smooth an image. One parameter can be "Algorithm" with these options: "Median", "Average", and "Gaussian". Let's say I choose "Gaussian". I expect two other parameters for more control of the "Gaussian" algorithm: "window size", and "sigma". But "Sigma" should be shown only when I select "Gaussian". It is not applicable for "Median" or "Average" option.

MarcusTomlinson commented 1 year ago

Yeah, you can do this with a base class between DSPatch::Component and your own. Provide a method in your base like “RegisterParam()” that child components can call in their constructor or wherever. Then “Get/SetParams()” on the base to retrieve and set them from the outside world.

zanazakaryaie commented 1 year ago

Ok. Thank you very much @MarcusTomlinson