dyne / frei0r

A large collection of free and portable video plugins
https://frei0r.dyne.org/
GNU General Public License v2.0
437 stars 91 forks source link

plugins registering wrong datatype for boolean params #48

Closed rrrapha closed 6 years ago

rrrapha commented 6 years ago

For example, tutorial.cpp has this code:

public:
    Tutorial(unsigned int width, unsigned int height)
    {
        register_param(m_barSize, "barSize", "Size of the black bar");
        register_param(m_pointerMethod, "pointerMethod", "Pointer Method (internal)");
...

private:
    f0r_param_double m_barSize;
    f0r_param_bool m_pointerMethod;
...

Because f0r_param_bool is of type 'double', the wrong register_param function is called for m_pointerMethod.

I see two ways of fixing this without breaking external API/ABI compatibility.

  1. change the param datatypes in tutorial.cpp:
    f0r_param_double m_barSize;
    bool m_pointerMethod;
  1. change the register_param function (in frei0r.hpp) to something like this:
    void register_param(f0r_param_t p_loc,
                        int type,
                        const std::string& name,
                        const std::string& desc)
    {
      param_ptrs.push_back(p_loc);
      s_params.push_back(param_info(name,desc,type));
    }

and change the calls in tutorial.cpp:

    register_param(&m_barSize, F0R_PARAM_DOUBLE, "barSize", "Size of the black bar");
    register_param(&m_pointerMethod, F0R_PARAM_BOOL, "pointerMethod", "Pointer Method (internal)");

I prefer the second version because most plugins already use f0r_param_bool for the boolean params and the calls to register_param could be changed mechanically.

rrrapha commented 6 years ago

After thinking about it some more, I now prefer the first version. It seems better to just use bool instead of f0r_param_bool in the c++ plugins.