Hello im creating a basic audio plugin, im trying to pass my keyboardState object from PluginEditor to PluginProcessor. Im trying to do it without having these 2 headers include each other, which would be a bad idea. Anytime I add a PluginEditor object as a member to my PluginProcessor class, I include the PluginEditor.h, which causes nasty errors. I need my PluginProcessor to use the keyboardState: Below is a snippet of what im trying to accomplish
// PluginProcessor.cpp
void CustomAudioProcessor::processBlock (juce::AudioBuffer<float>& buffer,
juce::MidiBuffer& midiMessages)
{
juce::ScopedNoDenormals noDenormals;
auto totalNumInputChannels = getTotalNumInputChannels();
auto totalNumOutputChannels = getTotalNumOutputChannels();
for (auto i = totalNumInputChannels; i < totalNumOutputChannels; ++i)
buffer.clear (i, 0, buffer.getNumSamples());
pluginEditorObject.keyboardState.processNextMidiBuffer (midiMessages, 0, numSamples, true);
}
//PluginProcessor.h
#include "PluginEditor.h"
class CustomAudioProcessor : public juce::AudioProcessor
{
public:
TrapBoxPluginAudioProcessor();
~TrapBoxPluginAudioProcessor() override;
private:
PluginEditor pluginEditorObject;
};
//PluginEditor.cpp
CustomAudioProcessorEditor::CustomAudioProcessorEditor(CustomnAudioProcessor& p)
: AudioProcessorEditor(&p), audioProcessor(p),
keyboardComponent(keyboardState, MidiKeyboardComponent::horizontalKeyboard)
{
...
}
//PluginEditor.h
#include "PluginProcessor.h"
class CustomAudioProcessorEditor : public AudioProcessorEditor
{
public:
CustomAudioProcessorEditor(CustomAudioProcessor&);
private:
MidiKeyboardState keyboardState;
}
Is there a quick way for me to pass my PluginEditor object to PluginProcessor without both headers including each other ?
It works the other way round. The separation of MidiKeyboardState and MidiKeyboardComponent is because the state is needed all the time, while the component is only needed while the editor is open.
The solution is to put the MidiKeyboardState in the processor and connect the MidiKeyboardComponent from the editor. Either make the state a public variable or add an accessor method to your processor like MidiKeybardState& getKeyboardState();
Got it, thanks so much Daniel,…so pretty much if i need any other objects from the Processor I would need to create a accessor method and use it the other Class or vice versa. sweet!