Save/load edit - waves not found

The edit saves the paths to the wave files as relative paths. It seems that I’m doing something wrong. When I reload the edit, it can no longer find the wave files. Do I have to set any standard path so that it can find the files? How are the relative paths calculated, which are then saved in the edit? Can I determine whether the waves are saved in a specific folder? I guess I messed up something.

In the Edit::Options struct you pass to the Edit constructor you’ll see editFileRetriever and filePathResolver members.

The simplest way is to specify a editFileRetriever that returns the File of the Edit. This will then be used to resolve the file paths relative to that.

For more complex cases, like if you wanted your paths to be relative to a different folder, you can specify your own filePathResolver.

1 Like

I don’t really get how this could work. On load I set:

m_edit->editFileRetriever = [editFile] { return editFile; };

Now, when I add a new wave clip, the path would be stored relativ to the edit file. But when I save this edit to an other folder, the path doesn’t change. Even if I reset the fileRetriever to the new edit file. Is there any function that recalculate the relative paths and changes the edit?

Thanks for your help.

I’m not sure I fully understand the problem but it sounds like you’re storing relative paths and then moving the Edit that everything is relative to? That’s never going to work.

You could assign a custom filePathResolver that resolves your relative path to wherever they are on disk but why would you want to move the Edit file away from the recorded files?

Okay, maybe I’m missing something here. If the user wants to save the edit in a different location (save as …) then the relative paths of the wave files are no longer correct. Even if I use: te :: EditFileOperations (m_edit) .saveAs ();
I’ve written a little function that rewrites these paths which I call before I save:

void refreshRelativePathstoNewEditFile(EditViewState & evs
                                                    , juce::File newEditFile)
    {
        for (auto t : te::getAudioTracks (evs.m_edit))
        {
            for (auto c : t->getClips ())
            {
                if (c->state.getProperty (te::IDs::source) != "")
                {
                    auto source = evs.m_edit.filePathResolver(
                                c->state.getProperty (te::IDs::source));
                    c->state.setProperty (
                          te::IDs::source
                        , source.getRelativePathFrom (
                                    newEditFile.getParentDirectory ())
                        , nullptr);
                }
            }
        }
        evs.m_edit.editFileRetriever = [newEditFile] {return newEditFile;};
    }

But I’m not sure if I’m thinking anything too complicated here. Or whether this breaks something.

I see what you mean. In Waveform because all assets (including Edits) are resolved through the Project we haven’t run in to this. But you are correct, if a save-as operation creates an Edit in a new directory, the relative paths will need to be updated.

I think your method will do for now, I’ll have a think but it’s probably likely I’ll add something similar to the EditFileOperations::saveAs operation in the Engine. I’ve created an Issue on GitHub to remind me of this.

Thanks.

1 Like