I want to write my first abstract class and thought it might be helpfull to make me an abstract AudioProcessor where my Implementations can derive from and just hand in Parameters for the underlying apvt. By changing the layout, I have the oportunity to change the view.
Note the base class is not for audioprocessing, so real time shouldn’t be a matter.
In general I have some problems to create Interfaces in the java style in C++ but it should be more or less possible I think. Correct me if I’m wrong.
class AudioProcessorBase : public AudioProcessor
{
AudioProcessorBase();
~AudioProcessorBase();
virtual APVTS::ParameterLayout createParameterLayout() = 0;
// rest of the AP code
...
}
class AudioProcessorImpl : public AudioProcessorBase
{
juce::AudioProcessorValueTreeState::ParameterLayout createParameterLayout() override
{
std::vector<std::unique_ptr<juce::RangedAudioParameter>> params;
// Add parameters (buttons, rotaries, etc.)
params.push_back(std::make_unique<juce::AudioParameterBool>("button1", "Button 1", false));
params.push_back(std::make_unique<juce::AudioParameterFloat>("rotary1", "Rotary 1", 0.0f, 1.0f, 0.5f));
return { params.begin(), params.end() };
}
juce::AudioProcessor* JUCE_CALLTYPE createPluginFilter()
{
return AudioProcessorImpl();
}
createPluginFilter gives me a little headache since it’s not possible to return just the base class, so I moved it into the implementation code.
I wrote the code out of memory but that’s more or less my plan. When I implement the code and start compiling it, I always receive a linker error that the compiler can’t find the virtual function createParameterLayout().
Since it’s a bit hard to debug this linker error, I thought it’s a good idea to ask here first if my approach is actually possible. So a yes or no is totally enough for me, just don’t want to investigate a long time to then see, that it’s the approach and not a tiping error or something.
Just want to bump this. I also asked in discord what brought me further but I’m still stuck with the apvts. Is it actually neccessary also considering future changes in juce to implement the apvts for syncing parameters?
In the Discord Channel were already suggestions to implement my own apvts which is capable of changeing while runtime. Actually I would only need a valuetree actually but then I don’t have the attachments and I don’t see a not deprecated way to attach components to my values. Since my plugins don’t do any audio processing it’s totally fine not to be realtime.
But I’m asking myself is it really the fastest approach to create an interface for my plugins? I just want a Device interface which handels connections and a deriving class which handels the view and attaches parameters. Is there really no fast approach or something what Juce offers to implement this idea?
My current approach:
DeviceInterface(juce::String deviceName)
{
this->deviceName = deviceName;
}
~DeviceInterface() override = default;
virtual juce::AudioProcessorValueTreeState::ParameterLayout createParameterLayout() = 0;
// Method to be called by derived classes to set up APVTS
void initializeAPVTS(juce::AudioProcessorValueTreeState::ParameterLayout layout)
{
mAPVTS = std::make_unique<juce::AudioProcessorValueTreeState>(*this, nullptr, deviceName, std::move(layout));
mAPVTS->state.addListener(this);
}
And the Impl:
Device::Device()
: DeviceInterface("DeviceX")
{
initializeAPVTS(createParameterLayout());
// Set up listeners for specific parameters
mAPVTS->addParameterListener("deviceX_gain", this);
gainParameter = mAPVTS->getRawParameterValue("deviceX_gain");
}
Device::~Device()
{
mAPVTS->removeParameterListener("DeviceX_gain", this);
}
juce::AudioProcessorValueTreeState::ParameterLayout Device::createParameterLayout()
{
// Define the parameters specific to Device
return {
std::make_unique<juce::AudioParameterFloat>("DeviceX_gain", "DEVICEX Gain", 0.0f, 1.0f, 0.5f),
std::make_unique<juce::AudioParameterFloat>("DeviceX_tone", "DEVICEX Tone", 0.0f, 1.0f, 0.5f)
};
}
But I have problems to change parameters from the interface. The impl is fine like this and listens to the parameters.
Ah I saw now that there is already another thread giving two really good examples for a processor base class:
My approach follows that more or less but even in this code nobody really wants to manipulate the parameters appart from the components. Is that something so rarely needed that it is not considered?
I’m already thinking of throwing out this apvts. It’s anyway too much for everything but I’m a bit afraid that all the other approaches get deprecated soon.