Hello, I’m having a bit of trouble understanding owned arrays. For a university assignment I’m currently making a midi sequencer.
I have a base class called Region which has two children sequenceRegion and noteRegion.
Currently if i want to add a region they are created in two different functions in two different classes (arrangeWindow and pianRoll)
ArrangeWindow deals with sequenceRegions and pianoRoll deals with noteRegions.
Because there is a lot of repeated code so I’m making a base class called Window that pianoRoll and arrangeWindow can inherit from.
Here are some examples of the code, with the most important bits left in, this is my first time posting a question and I’m fairly new to Juce so i hope I haven’t been to hard to understand.
void ArrangeWindow::addRegion()
{
sequenceRegions.add(new SequenceRegion);
sequenceRegions[createNoteRegionCounter] -> regionNumber = createNoteRegionCounter;
sequenceRegions[createNoteRegionCounter] -> setSize(80, 80);
sequenceRegions[createNoteRegionCounter] -> setTopLeftPosition(mousePositionX, mousePositionY);
addAndMakeVisible(sequenceRegions[createNoteRegionCounter]);
sequenceRegions[createNoteRegionCounter] -> setListener(this);
}
void PianoRoll::addRegion()
{
noteregions.add(new NoteRegion);
noteregions[createNoteRegionCounter] -> regionNumber = createNoteRegionCounter;
noteregions[createNoteRegionCounter] -> setSize(currentRegionSize, 14);
noteregions[createNoteRegionCounter] -> setTopLeftPosition(mousePositionX, mousePositionY);
addAndMakeVisible(noteregions[createNoteRegionCounter]);
noteregions[createNoteRegionCounter] -> setListener(this);
}
This all works perfectly but i am now trying to make my window class work for both types of region. Here is a rough attempt, which doesn’t work at all (I’m sure for obvious reasons, but as I’m fairly new to c++ and Juce I’m having a bit of trouble understanding how to achieve what i want)
void Window::addRegion(OwnedArray *region)
{
if (regionType == 0 )
{
region -> add(new SequenceRegion);
}
else if (regionType == 1)
{
region -> add(new NoteRegion);
}
region[createRegionCounter].regionNumber = createRegionCounter;
region[createRegionCounter] . setSize(80, 80);
region[createNoteRegionCounter] -> setTopLeftPosition(mousePositionX, mousePositionY);
addAndMakeVisible(region[createNoteRegionCounter]);
region[createNoteRegionCounter] -> setListener(this);
}
createRegionCounter keeps track of how many have been created/deleted.
Function call:
ArrangeWindow();
arrangeWidnow.addRegion(sequenceRegions)
Pianoroll();
pianoRoll.addRegion(noteRegions)
I’ve left out a lot of the code but that all works how i want to , my main question is how do i pass a reference to an owned array using polymorphism.
Thank you in advance for anyone that can help!

