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

can getParameterProperties be static? #35

Closed
wtholliday opened this issue Aug 14, 2020 · 5 comments
Closed

can getParameterProperties be static? #35

wtholliday opened this issue Aug 14, 2020 · 5 comments

Comments

@wtholliday
Copy link

I'm doing some initial integration of SOUL into AudioKit via soul generate --cpp

PR here if curious: AudioKit/AudioKit#2225

It would be helpful to be able to query as much information as possible without having to instantiate the DSP object. This would assist us in populating things on the Swift side.

To be specific, it seems getParameterProperties could be declared static except for applyValue. Suggest that applyValue be moved to a separate array (perhaps returned by getApplyValueFunctions).

I can't seem to find the code that generates getParameterProperties in this repo. Perhaps it's in the closed-source backend.

Let me know if/how I can help 😀

@wtholliday
Copy link
Author

Actually, never mind... It's easy enough to just instantiate a throw-away DSP object.

@julianstorer
Copy link
Contributor

Yeah, the code that generates c++ is in our internal codebase. But actually, not a bad idea for us to mark it static, and even constexpr probably, as I think it's all just compile-time constants in there. I'll take a look when I get a second!

@julianstorer
Copy link
Contributor

ah no - just had a look and noticed that actually it does some lambda capture in there, so can't be static, I'm afraid..

@wtholliday
Copy link
Author

@julianstorer Yeah, I was suggesting moving the lambda capture to a separate struct. So you'd have something like:

struct ParameterProperties
{
        const char* UID;
        const char* name;
        const char* unit;
        float minValue, maxValue, step, initialValue;
        bool isAutomatable, isBoolean, isHidden;
        const char* group;
        const char* textValues;
};

static std::vector<ParameterProperties> getParameterProperties() { ... }

struct Parameter
{
        float minValue, maxValue;
        float currentValue;
        std::function<void(float)> applyValue;

        void setValue (float f)
        {
            currentValue = snapToLegalValue (f);
            applyValue (f);
        }

        float getValue() const
        {
            return currentValue;
        }

    private:
        float snapToLegalValue (float v) const
        {
            if (step > 0)
                v = minValue + step * std::floor ((v - minValue) / step + 0.5f);

            return v < minValue ? minValue : (v > maxValue ? maxValue : v);
        }
    };

std::vector<Parameter> getParameters() { ... }

Could also put a ParameterProperties in Parameter if you want.

@julianstorer
Copy link
Contributor

Yep, sensible request, I'll have a look when I get a moment!

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