juce::OwnedArray isn't visible in addAndMakeVisible except for one element

Im making a mixer which is added to a window, the window runs off of a component called MixerComponent and the mixer component takes an array of ChannelComponents which is a custom Component for one individual channel. The juce::OwnedArray channels is declared globally in the MixerComponent.h file. I then initialize the array with a set of Channel Components in a void method in the MixerComponent called setDefaultConfiguration which is supposed to initialize the array with 9 channels by default with zero being the master channel. However upon observation in the output ONLY the zero channel is seen not the rest of the nine. Any attempt to shift the channels down automatically makes them invisible despite setting the addAndMakeVisible calls and I even tried a pure setVisible(true) which didn’t work either. the code is as follows…

MixerComponent::MixerComponent(juce::Colour colour)
{
setDefaultConfig();
resized();

for(int k = 0; k < channels.size(); k++)
{
    addAndMakeVisible(channels[k]);
    channels[k]->setVisible(true);
    DBG(channels[k]->getChannelNumber());
}

}

MixerComponent::~MixerComponent()
{

}
void MixerComponent::setDefaultConfig()
{
for(int k = 0; k < 9; k++)
{
ChannelComponent* comp = new ChannelComponent(k,juce::Colours::red);
channels.add(comp);
}
}
void MixerComponent::paint (juce::Graphics& g)
{
g.setColour(juce::Colours::aquamarine);

for(int k = 0; k<channels.size();k++)
{
    g.drawRect(2+(k*75), 0, 75, 400);
}
for(int k = 0; k<channels.size(); k++)
{
    channels[k]->paint(g);
}

}

void MixerComponent::resized()
{
for(int k = 0; k < channels.size(); k++)
{
channels[k]->setBounds(channels[k]->getChannelNumber()*75, 0, 75, 450);
}

}

ChannelComponent::ChannelComponent(int channelNumber, juce::Colour colour) : panWindow("Pan Window " + juce::String(channelNumber), juce::Colours::darkslategrey, juce::DocumentWindow::TitleBarButtons::closeButton+juce::DocumentWindow::TitleBarButtons::minimiseButton), panComponent(myColour), myChannelNumber(channelNumber)
{
myChannelNumber = channelNumber;
myColour = colour;

panComponent.setColour(myColour);

channelButton.setButtonText(juce::String(channelNumber));
addAndMakeVisible(channelButton);

mySlider.setSliderStyle(juce::Slider::SliderStyle::LinearVertical);
mySlider.setColour(juce::Slider::ColourIds::backgroundColourId, juce::Colours::darkslategrey);
mySlider.setColour(juce::Slider::ColourIds::trackColourId, myColour);
mySlider.setColour(juce::Slider::thumbColourId, juce::Colours::aquamarine);
addAndMakeVisible(mySlider);

panButton.setToggleState(false, juce::NotificationType::dontSendNotification);
panButton.onClick = [this] () {
    panButtonClicked();
};

channelButton.setColour(juce::TextButton::ColourIds::buttonOnColourId, myColour);
channelButton.setToggleState(false, juce::NotificationType::dontSendNotification);
channelButton.onClick = [this](){channelButton.setToggleState(true, juce::NotificationType::dontSendNotification);};

EQButton.setColour(juce::TextButton::ColourIds::buttonOnColourId, myColour);
EQButton.setToggleState(false, juce::NotificationType::dontSendNotification);
EQButton.onClick = [this](){EQButton.setToggleState(true, juce::NotificationType::dontSendNotification);};


interpolateButton.setColour(juce::TextButton::ColourIds::buttonOnColourId, myColour);
interpolateButton.setToggleState(false, juce::NotificationType::dontSendNotification);
interpolateButton.onClick = [this](){interpolateButton.setToggleState(true, juce::NotificationType::dontSendNotification);};


latencyButton.setColour(juce::TextButton::ColourIds::buttonOnColourId, myColour);
latencyButton.setToggleState(false, juce::NotificationType::dontSendNotification);
latencyButton.onClick = [this](){latencyButton.setToggleState(true, juce::NotificationType::dontSendNotification);};


panButton.setColour(juce::TextButton::ColourIds::buttonOnColourId, myColour);
panButton.setToggleState(false, juce::NotificationType::dontSendNotification);
panButton.onClick = [this] () {
    panButtonClicked();
};


fxButton.setColour(juce::TextButton::ColourIds::buttonOnColourId, myColour);
fxButton.setToggleState(false, juce::NotificationType::dontSendNotification);
fxButton.onClick = [this](){fxButton.setToggleState(true, juce::NotificationType::dontSendNotification);};


muteButton.setColour(juce::TextButton::ColourIds::buttonOnColourId, myColour);
muteButton.setToggleState(false, juce::NotificationType::dontSendNotification);
muteButton.onClick = [this](){muteButton.setToggleState(true, juce::NotificationType::dontSendNotification);};


linkButton.setColour(juce::TextButton::ColourIds::buttonOnColourId, myColour);
linkButton.setToggleState(false, juce::NotificationType::dontSendNotification);
linkButton.onClick = [this](){linkButton.setToggleState(true, juce::NotificationType::dontSendNotification);};


playButton.setColour(juce::TextButton::ColourIds::buttonOnColourId, myColour);
playButton.setToggleState(false, juce::NotificationType::dontSendNotification);
playButton.onClick = [this](){playButton.setToggleState(true, juce::NotificationType::dontSendNotification);};


recButton.setColour(juce::TextButton::ColourIds::buttonOnColourId, myColour);
recButton.setToggleState(false, juce::NotificationType::dontSendNotification);
recButton.onClick = [this](){recButton.setToggleState(true, juce::NotificationType::dontSendNotification);};


ffButton.setColour(juce::TextButton::ColourIds::buttonOnColourId, myColour);
ffButton.setToggleState(false, juce::NotificationType::dontSendNotification);
ffButton.onClick = [this](){ffButton.setToggleState(true, juce::NotificationType::dontSendNotification);};


rvButton.setColour(juce::TextButton::ColourIds::buttonOnColourId, myColour);
rvButton.setToggleState(false, juce::NotificationType::dontSendNotification);
rvButton.onClick = [this](){rvButton.setToggleState(true, juce::NotificationType::dontSendNotification);};


addAndMakeVisible(EQButton);
addAndMakeVisible(interpolateButton);
addAndMakeVisible(latencyButton);
addAndMakeVisible(panButton);
addAndMakeVisible(fxButton);
addAndMakeVisible(muteButton);
addAndMakeVisible(linkButton);
addAndMakeVisible(playButton);
addAndMakeVisible(recButton);
addAndMakeVisible(ffButton);
addAndMakeVisible(rvButton);

}

ChannelComponent::~ChannelComponent()
{
}
int ChannelComponent::getChannelNumber()
{
return myChannelNumber;
}
void ChannelComponent::panButtonClicked()
{
if(!panButton.getToggleState())
{
panWindow.setUsingNativeTitleBar(true);
panWindow.setAlwaysOnTop(true);
panWindow.setResizable (true, true);
panWindow.setContentOwned(&panComponent, false);
panWindow.setFullScreen(false);
panWindow.setVisible(true);
panButton.setToggleState(true, juce::NotificationType::dontSendNotification);
}
else
{
panButton.setToggleState(false, juce::NotificationType::dontSendNotification);
panWindow.setVisible(false);
}

}

void ChannelComponent::paint (juce::Graphics& g)
{
panComponent.repaint();
}

void ChannelComponent::resized()
{
channelButton.setBounds(3+(myChannelNumber75), 2, 35, 30);
EQButton.setBounds(40+(myChannelNumber
75), 2, 35, 30);
interpolateButton.setBounds(2+(myChannelNumber75), 35, 35, 30);
latencyButton.setBounds(40+(myChannelNumber
75), 35, 35, 30);
panButton.setBounds(2+(myChannelNumber75), 270, 35, 30);
fxButton.setBounds(40+(myChannelNumber
75), 270, 35, 30);
muteButton.setBounds(2+(myChannelNumber75), 302, 35, 30);
linkButton.setBounds(35+(myChannelNumber
75), 302, 40, 30);
playButton.setBounds(2+(myChannelNumber75), 334, 35, 30);
recButton.setBounds(40+(myChannelNumber
75), 334, 35, 30);
ffButton.setBounds(2+(myChannelNumber75), 364, 35, 30);
rvButton.setBounds(40+(myChannelNumber
75), 364, 35, 30);

mySlider.setBounds(myChannelNumber*75, 70, 30, 200);



panComponent.setBounds(0, 420, 690, 250);
panWindow.setBounds(0, 420, 690, 250);
panWindow.setContentComponentSize(690, 250);

}

only Zero pops out and im not sure why but its able to draw rectangles in the paint method past 75 on the x increment…

any help would be appreciated. Thanks.

also the DBG is able to perfectly print each incremental value / channelNumber

NVM fixed it.

To make your code more readable, please indent every line with 4 spaces, or surround the whole code with three backticks before and after, like this:

```
void your_code_here ()
{
}
``` 

The same is obtained by selecting the code in your post while editing, then pressing the button that has this symbol on it: </>

1 Like

ok thanks for the tip ill be sure to format it better using your remarks in future forum posts.