Open Waveform project in Tracktion Engine

Hi everyone!

I’ve been experimenting with saving / opening edits in tracktion and I’ve been trying to open projects from Waveform in a test tracktion project. However, the source field of each of the clips seems like it needs decoding. Looks like it’s in the format projectId/clipId.

When I load a project like this:

void loadProject(const juce::File &file) {
    jassert(file.existsAsFile());
    edit = tracktion::loadEditFromFile(engine, file, tracktion::Edit::forEditing);
    jassert(edit != nullptr);
    editFileOps = std::make_unique<te::EditFileOperations>(*edit);
    edit->getTransport().setPosition(te::TimePosition::fromSeconds(0));
}

This works great if I manually change the AUDIOCLIP source to be a relative or absolute path in the edit file XML. However it won’t automatically load the encoded project file. I’ve seen in this post that you need to use the te::ProjectManager in some way but I cannot find the incantation required to get that to work.

Any feedback or pointers would be much appreciated!

Thanks,

Jamie

Ok I got this to work, but not sure if this is the most canonical or best way to do it? @dave96 @RolandMR

    void loadProject(const juce::File &file) {
        jassert(file.existsAsFile());
        auto tempProject = te::ProjectManager::TempProject{engine.getProjectManager(), projectFile, false};
        auto project = tempProject.project;
        jassert(project != nullptr);
        const auto numProjectItems = project->getNumProjectItems();
        jassert(numProjectItems > 0);
        auto projectItemId = project->getProjectItemID(0);
        const auto vt = tracktion::loadEditFromFile(engine, file, projectItemId);
        edit = std::make_unique<te::Edit>(engine, vt, te::Edit::forEditing, nullptr, te::Edit::getDefaultNumUndoLevels());
        jassert(edit != nullptr);
        editFileOps = std::make_unique<tracktion::EditFileOperations>(*edit);
        edit->getTransport().setPosition(tracktion::TimePosition::fromSeconds(0));
    }

I think that will work but you’ll need to keep the Project alive whilst using the Edit or the file resolver won’t work. It depends if you want to go back and forth between the two but you might be better off doing a conversion pass on all the audio clips getting the SourceFileReference, getting the path (via Project resolution) and then setting it to setToDirectFileReference to create a relative path.


One other small thing, EditFileOperations is lightweight so you can just create it on the stack when required, like EditFileOperations (*edit).save (...)

One final thing, TimePosition is constructible from a std::chrono so if you have a using namespace std::literals; somewhere in your headers, you can write positions like edit->getTransport().setPosition(0s) which I quite like.