So, I’ve extended the Synthesizer class and added a function called ‘setAttack’. This function sets the attack parameter of an ADSR-envelope I’ve added.
But, the parameter change is handled by PluginProcessor.cpp, so I’ve added the following functions below. But, somehow the compiler thinks there is no function called ‘setAttack’ inside the Synthesizer class… What’s going on? I’m using XCode in this case.
Compiler error in JuceAudioPluginDemo.cpp:
No member named ‘setAttack’ in ‘juce::SynthesiserVoice’.
SynthesiserVoice has NO setAttack call as it also seems you’ve already understood with you casting.
However you’re calling setAttack prior to casting it…
Right, but how would one to add such functionality without modifying the juce library files? Or is there no way around it and just make a local copy and edit the juce files?
cpp has learning curve if you’re not coming from it and it’s only getting worse since c++17 and future standards reshape the syntax…
You’re not providing enough code snippets to actually understand what you’re trying to do.
And as with code there are many ways to do the same thing. each one would do it different.
you can always keep your own voice pointers in a vector / juce::Array / etc…
you can change your code to (I didn’t test it since I’m also not a fluent cpp dev. but if this not working simply set it to a pointer variable first).
I will look into the various options you mentioned.
And yes, I’m very new to c++, coming from c#/java. So some things confuse the hell out of me. But, taking babysteps and looking at references helps a lot. And also the help from the responsive Juce community
..instead, always prefer to write it like this, which reduces the scope of the pointer, making it impossible to write code that accidentally uses a null pointer:
if(Foo* f = getFoo())
f->doSomethingElse();
// f is out-of-scope here, so a null-pointer dereference is impossible.
(This also results in more compact, cleaner code).
Thanks for pointing me to the style guide. It is always a good read.
With respect to the current problem I don’t think that the rule you cited should be applied here. After all a named pointer variable isn’t even required. The chances of unadvertedly using a dangling pointer are thus zero.
Note that the Idiom that I proposed is also present in the juce source code.
(like here: AudioProcessorValueTreeState::updateParameterConnectionsToChildTrees)
sure. the method I proposed is also all over the place in Juce code. The folks who write/wrote juce definitely didn’t stick to their style guide 100% haha