I know, another noob who cannot do C++ ![]()
I have a Component that sits on a Class that sits on a Tab that sits on the PluginEditor.
The Class that the Component sits on has access to the AudioProcessor variables via a reference passed in, Header File below:
class LibrarianPage : public juce::Component,
public juce::Button::Listener,
public juce::Timer
{
public:
LibrarianPage(KorgRadiasAudioProcessor&);
~LibrarianPage() override;
void paint (juce::Graphics&) override;
void resized() override;
private:
KorgRadiasAudioProcessor& audioProcessor;
Then in the .cpp File:
#include <JuceHeader.h>
#include "LibrarianPage.h"
//#include "PluginEditor.h"
//==============================================================================
LibrarianPage::LibrarianPage(KorgRadiasAudioProcessor& p) : audioProcessor(p)
{
// Librarian Components
// --------------------
addAndMakeVisible(librarianComponent);
//addAndMakeVisible(librarianComponent(audioProcessor));
addAndMakeVisible(librarianPatchHeaderComponent);
addAndMakeVisible(librarianBankHeaderComponent);
And I will admit that I do not fully know how this works but it does!
But the librarianComponent that gets constructed on the LibrarianPage (above) has no access to variables in the AudioProcessor, I tried to copy the way that the LibrarianPage does it but it won’t work!
The LibrarianComponent is all in one header file, like:
#pragma once
#include <JuceHeader.h>
//#include "PluginEditor.h"
//==============================================================================
/*
*/
class LibrarianComponent : public juce::Component
{
public:
LibrarianComponent()//(KorgRadiasAudioProcessor& p) : audioProcessor(p)
{
}
~LibrarianComponent() override
{
}
int startX;
int startY;
int dragX;
int dragY;
int endX;
int endY;
int mouse_down;
int mouse_up;
int mouse_drag;
//KorgRadiasAudioProcessor& audioProcessor;
void mouseDown(const juce::MouseEvent &event)
{
startX = event.getMouseDownX();
startY = event.getMouseDownY();
//DBG("Mouse Down X " << startX);
//DBG("Mouse Down Y " << startY);
mouse_down = 1;
mouse_up = 0;
repaint();
}
void mouseDrag(const juce::MouseEvent &event)
{
mouse_drag = 1;
mouse_up = 0;
dragX = startX + event.getDistanceFromDragStartX();
dragY = startY + event.getDistanceFromDragStartY();
repaint();
}
void mouseUp(const juce::MouseEvent& event)
{
endX = startX + event.getDistanceFromDragStartX();
endY= startY + event.getDistanceFromDragStartY();
//DBG("Mouse Up X " << endX);
//DBG("Mouse Up Y " << endY);
mouse_down = 0;
mouse_drag = 0;
mouse_up = 1;
repaint();
}
void paint(juce::Graphics& g) override
{
int comp_height = getHeight();
int comp_width = getWidth();
int margin = 10;
int no_of_banks = 16;
int no_of_patches = 16;
int slot_width = comp_width / no_of_patches;
int slot_height = comp_height / no_of_banks;
int mem_width = (comp_width - (no_of_patches * margin)) / no_of_patches;
int mem_height = (comp_height - (no_of_banks * margin)) / no_of_banks;
// Draw the Background
// -------------------
g.fillAll(getLookAndFeel().findColour(juce::ResizableWindow::backgroundColourId));
g.setColour(juce::Colours::black);
juce::Rectangle <float> area = getLocalBounds().toFloat();
g.fillRoundedRectangle(area, 8.0f);
// Draw the Memory Slots & Patch Names
// -----------------------------------
for (int i = 0; i <= (no_of_patches - 1); i++)
{
for (int j = 0; j <= (no_of_banks - 1); j++)
{
g.setColour(juce::Colours::silver);
juce::Rectangle <float> rect1(margin + ((mem_width * j) + (margin * j)), margin + ((mem_height * i) + (margin * i)), mem_width, mem_height);
g.fillRoundedRectangle(rect1, 4.0f);
g.setColour(juce::Colours::black);
g.setFont(14.0);
g.drawText(audioProcessor.librarianPatchNames_SA[1 + i + (j * 16)], margin + ((mem_width * j) + (margin * j)), margin + ((mem_height * i) + (margin * i)), mem_width, mem_height, juce::Justification::centred, true);
}
}
The reference to audioProcessor.librarianPatchNames_SA (just above) which is declared in the PluginProcessor is what I need to get access to!
You can see the commented out bits where I tried the same approach to try and pass a reference to the AudioProcessor in but just got ‘no default constructor exists’ type errors!
I know I’m doing something dumb, but could someone be so kind as to explain my error please?
