Ive just found this post Creating and removing components on the fly
(Maybe more appropriately named as a post) and in the answer a user suggests to use an OwnedArray.
So i have tried this and i am still having no luck:
void
PianoRoll::initialiseNotes()
{
for (auto& gui_note: m_gui_notes)
{
removeChildComponent(gui_note);
gui_note->setVisible(false);
}
m_gui_notes.clearQuick(true);
for (std::size_t index = 0; index < m_current_sequence.size(); index++)
{
m_gui_notes.add(std::make_unique<GuiNote>());
int x_pos = static_cast<int>(m_current_sequence[index].note_on)/4;
int width = (static_cast<int>(m_current_sequence[index].note_off)/4) - x_pos;
int y_pos = (grid_line_height*number_of_midi_note_values) -
(grid_line_height * m_current_sequence[index].note_value);
m_gui_notes[static_cast<int>(index)]->setBounds(x_pos + keyboard_width, y_pos ,width, grid_line_height);
addAndMakeVisible(m_gui_notes[static_cast<int>(index)]);
}
}
