I tried running your code, but my Tracktion code was out of date, I tried updating it and it’s giving me all sorts of errors… a project to worry about later, I guess!
It’s possible that the jassert
is being called because some listeners haven’t been detached yet. Definitely a warning that something wasn’t ready to be deleted. Could also maybe the way the std::unique_ptr stepSequencer
is being handled? Idk.
Here’s the way I implemented it while I was testing a while ago. It opens the mainWindow
with a new project, or can open it with a project file:
StepSequencerDemo.h
//constructor for opening a project file
StepSequencerDemo(File editFile, std::function<void(File, bool)> reopenRequest) :
edit(te::Edit::Options{
engine,
te::loadEditFromFile(engine, editFile, {}),
te::ProjectItemID::createNewID(0),
te::Edit::forEditing,
nullptr,
te::Edit::getDefaultNumUndoLevels(),
[=] { return editFile; }
})
{
//other start up code here...
}
//constructor for creating a new project
StepSequencerDemo(std::function<void(File, bool)> reopenRequest) :
edit{ engine, te::createEmptyEdit(engine), te::Edit::forEditing, nullptr, 0 }
{
//other start up code here...
}
...
te::Edit edit; // this doesn't need to be an std::unique_ptr
Main.cpp
void initialise (const juce::String&) override
{
open(File(), true);
}
void open(File file, bool newProject)
{
auto reopenRequest = [=](File differentFile, bool newProjectWanted)
{
open(differentFile, newProjectWanted);
});
if (newProject)
{
mainWindow.reset(new MainWindow("StepSequencerDemo", new StepSequencerDemo(reopenRequest), *this));
}
else
{
mainWindow.reset(new MainWindow("StepSequencerDemo", new StepSequencerDemo(file, reopenRequest), *this));
}
}
Then, when your load project button is pressed, simply call reopenRequest(projectFile)
. Or if the new project button is pressed, call reopenRequest(File(), true)
.
Also, side note: I’d recommend moving te::Engine
from StepSequencerDemo.h
to Main.cpp
and passing it in to the StepSequencerDemo
class. Creating the engine is a memory/CPU intensive process and can cause lag. Also, there’s no need to delete it and remake it every time a project is opened/created!