Can anyone help me troubleshoot this code?

Thanks Anthony. Removing the * from:

	for (auto* slider : sliders)
	{
		addAndMakeVisible(slider);
	}

Did not get rid of the error, but removing the * from:

private:
	OwnedArray<LabeledSlider*> sliders;
	OwnedArray<LabeledSlider> knobs;

Did get rid of the error. I don’t know if that was correct though. Changing the other part to const Array&<LabeledSlider*>& sliderArray just added a new warning so for simplicity I left that out.

It will now compile but it just makes a blank screen. Ie. None of the knobs or groups are showing up. Any ideas for why? The only warning I get now is: “declaration of ‘group1’ hides class member”, referring to I believe that I declared ‘group1’ in two different ways:

LabeledGroup group1("My Group", group1array);

std::unique_ptr<LabeledGroup> group1;

Commenting out the unique_ptr definition gets rid of that warning, and now I have no warnings nor errors but no knobs or groups either being made.

Any thoughts?

As for the use of GroupComponent to label the knobs and groups, this was daniel’s suggested way to do it. In the long run, I think I would aim to rename the “LabeledSlider” class to “LabeledGUIElement” and have it create sliders, combo boxes, or buttons as needed. Then I can still do the automatic arraying based on class and FlexBoxing of anything from this class within each LabeledGroup.

I’m not sure if attachToComponent() will really help improve things, as I will still need all the arrays and GroupComponent for defining groups, etc. Correct me if I’m wrong. I just want this to work.

/*
==============================================================================

This file was auto-generated and contains the startup code for a PIP.

==============================================================================
*/

#include "../JuceLibraryCode/JuceHeader.h"

//===========================
//USUAL PROJECT HEADER
//===========================

#pragma once

//===LABELEDSLIDER===//

class LabeledSlider : public GroupComponent
{
public:
	LabeledSlider(const String& name, Slider::SliderStyle style, Slider::TextEntryBoxPosition textPos)
	{
		setText(name);
		setTextLabelPosition(Justification::centredTop);
		slider.reset(new Slider(style, textPos));

		addAndMakeVisible(slider.get());
	}

	/*
	void setSliderRange(Range<float> r) 
	{
		slider->setRange(r);
		void setSliderDecimal(int num) { slider->setNumDecimalPlacesToDisplay(num); }
		void setOnValueChange(std::function<void()> func) { slider->onValueChange = std::move(func); }
	}
	*/

	void resized() override
	{
		slider.get()->setBounds(getLocalBounds().reduced(10));
	}

private:
	std::unique_ptr<Slider> slider;
	
};

//===LABELEDGROUP===//

class LabeledGroup : public GroupComponent
{
public:
	LabeledGroup(const String& name, Array<LabeledSlider*> sliderArray) //: sliders(sliderArray)
	{

	std::unique_ptr<LabeledGroup> group;
	
		setText(name);
		setTextLabelPosition(Justification::centredTop);

		for (auto* slider : sliders)
		{
			addAndMakeVisible(slider);
		}

	}

	void resized() override
	{
		setBounds(getLocalBounds().reduced(10));

		FlexBox knobBox;
		knobBox.flexWrap = FlexBox::Wrap::wrap;
		knobBox.justifyContent = FlexBox::JustifyContent::flexStart;
		knobBox.alignContent = FlexBox::AlignContent::flexStart;
			
		for (auto *k : knobs)
			knobBox.items.add(FlexItem(*k).withMinHeight(80.0f).withMinWidth(80.0f).withFlex(1));

		FlexBox fb1;
		fb1.flexDirection = FlexBox::Direction::column;
		fb1.items.add(FlexItem(knobBox).withFlex(2.5));
		fb1.performLayout(getLocalBounds().reduced(15).toFloat());

	}

private:
	OwnedArray<LabeledSlider> sliders;
	OwnedArray<LabeledSlider> knobs;

};


//====================
//MAINCONTENTCOMPONENT
//====================

class MainContentComponent : public Component

{
public:
	MainContentComponent()

	{
		/*
		auto* attackLS = sliderObjects.add(new LabeledSlider("Attack", Slider::RotaryHorizontalVerticalDrag, Slider::TextBoxBelow));
		slider->setRange(0, 3);
		slider->setNumDecimal(1);
		slider->setOnValueChange(5);

		auto* decayLS = sliderObjects.add(new LabeledSlider("Decay", Slider::RotaryHorizontalVerticalDrag, Slider::TextBoxBelow));
		slider->setRange(0, 3);
		slider->setNumDecimal(1);
		slider->setOnValueChange(5);
		
		auto* releaseLS = sliderObjects.add(new LabeledSlider("Release", Slider::RotaryHorizontalVerticalDrag, Slider::TextBoxBelow));
		slider->setRange(0, 3);
		slider->setNumDecimal(1);
		slider->setOnValueChange(5);

		Array<LabeledSlider*> envelope = { attackLS, decayLS, releaseLS };
		*/

		Array<LabeledSlider*> group1array =
		{
			sliderObjects.add(new LabeledSlider("attack",Slider::RotaryHorizontalVerticalDrag, Slider::TextBoxBelow)),
			sliderObjects.add(new LabeledSlider("decay", Slider::RotaryHorizontalVerticalDrag, Slider::TextBoxBelow)),
			sliderObjects.add(new LabeledSlider("sustain", Slider::RotaryHorizontalVerticalDrag, Slider::TextBoxBelow)),
			sliderObjects.add(new LabeledSlider("release", Slider::RotaryHorizontalVerticalDrag, Slider::TextBoxBelow))
		};

		LabeledGroup group1("My Group", group1array);

		//auto group1 = std::make_unique<LabeledGroup>("Group1", {});

		
		setSize(600, 600);
	}
	

	void resized() override
	{
	    //group1.setBounds(getLocalBounds().expanded(10));
		//group2.setBounds(getLocalBounds().expanded(10));
		
		FlexBox groupBox;
		groupBox.flexWrap = FlexBox::Wrap::wrap;
		groupBox.justifyContent = FlexBox::JustifyContent::flexStart;
		groupBox.alignContent = FlexBox::AlignContent::flexStart;
		
		for (auto *g : groups)
		groupBox.items.add(FlexItem(*g).withMinHeight(100.0f).withMinWidth(350.0f).withFlex(3).withMargin(5));

		FlexBox fb1;
		fb1.flexDirection = FlexBox::Direction::column;
		fb1.items.add(FlexItem(groupBox).withFlex(3));
		fb1.performLayout(getLocalBounds().toFloat());
	
	}

	~MainContentComponent()
	{
		//		shutdownAudio();
	}

private:

	OwnedArray < LabeledGroup > groups;
	OwnedArray<LabeledSlider> sliderObjects;
	std::unique_ptr<LabeledGroup> group1;
	std::unique_ptr<LabeledGroup> group2;
};


//=====================
//USUAL MAIN.CPP
//=====================

class Application : public JUCEApplication
{
public:

	Application() {}

	const String getApplicationName() override { return "SineSynthTutorial"; }
	const String getApplicationVersion() override { return "3.0.0"; }

	void initialise(const String&) override { mainWindow.reset(new MainWindow("SineSynthTutorial", new MainContentComponent(), *this)); }
	void shutdown() override { mainWindow = nullptr; }

private:
	class MainWindow : public DocumentWindow
	{
	public:
		MainWindow(const String& name, Component* c, JUCEApplication& a)
			: DocumentWindow(name, Desktop::getInstance().getDefaultLookAndFeel()
				.findColour(ResizableWindow::backgroundColourId),
				DocumentWindow::allButtons),
			app(a)
		{
			setUsingNativeTitleBar(true);
			setContentOwned(c, true);

#if JUCE_ANDROID || JUCE_IOS
			setFullScreen(true);
#else
			setResizable(true, false);
			setResizeLimits(300, 250, 10000, 10000);
			centreWithSize(getWidth(), getHeight());
#endif

			setVisible(true);
		}

		void closeButtonPressed() override
		{
			app.systemRequestedQuit();
		}

	private:
		JUCEApplication & app;

		//==============================================================================
		JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(MainWindow)
	};

	std::unique_ptr<MainWindow> mainWindow;
};

//==============================================================================
START_JUCE_APPLICATION(Application)