-
Notifications
You must be signed in to change notification settings - Fork 24
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
Add assignment operators in parameter classes #562
base: master
Are you sure you want to change the base?
Add assignment operators in parameter classes #562
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #562 +/- ##
=======================================
Coverage 95.02% 95.02%
=======================================
Files 309 309
Lines 11675 11676 +1
Branches 1084 1084
=======================================
+ Hits 11094 11095 +1
Misses 580 580
Partials 1 1 ☔ View full report in Codecov by Sentry. |
Thanks for bringing this up! It's actually something I was thinking about the other day. At the moment, I typically use My only qualm about the operator overloading approach is that I don't really like when the assignment operator contains some "side-effects" beyond just setting a value. That would be the case here since using the assignment operator also triggers the "notifying host" behaviour. I feel like that's important here, since users might "assign" to a parameter from their audio thread, not expecting all the side-effects that follow (that's something I had trouble with when I started using JUCE). I'm not sure what the right solution is... maybe making the |
Yes, I hadn't noticed the I do see your point with the assignment operator having side-effects. Not ideal! Just for the fun of it, I played with some template magic to avoid all the boilerplate that would introduce (sorry if I'm using the mixin-term incorrectly): template<typename ParamType>
struct SetParameterValueMixin
{
virtual ~SetParameterValueMixin() = default;
void setParameterValue (ParameterTypeHelpers::ParameterElementType<ParamType> newValue)
{
ParameterTypeHelpers::setValue (newValue, static_cast<ParamType&> (*this));
}
}; obviously, that would mean moving the type helpers to the parameters module, so it's a bit bigger operation. :) |
Yeah, having a named assign function is probably the way to go. I think I'd prefer to keep |
Definitely. I'm a little unsure about putting an assertion in there. It seems that |
Yeah, I agree with your interpretations of both the docs and code... Maybe an assertion isn't necessary, but there should definitely be a comment to explain the dangers of calling the |
Yes, I agree. What do you think my latest commit? I added a comment simply referring to the docs for |
Ah sorry, I hadn't seen that you had a new commit. That looks good to me! Do you think it also makes sense to have this type of method for |
No problem!
and I guess it's definitely going to be ambigious if you're using a pure Adding it only to myEnumParam.setParameterValue (static_cast<int> (myEnumValue)); which is still pretty good. |
3541e96
to
84ebcaf
Compare
I think having the setter in I pushed a change just now... if everything looks okay to you, then we should be good to merge this PR! |
Hi!
I've found it useful to add some assignment operators in the parameter types.
As far as I know, it's the only way to avoid having to manually normalise the new value.
With the current setup I need to do this
which could just be
It seemed straightforward to do for the bool and float params, so I've just started with those.
Is this something you'd consider adding?
Or maybe I've overlooked some simpler solution..