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

I’m running into same problems. Is there any news?

Currently I have to do following steps for a clean “SaveAs” operation to move / copy all files:

  • Copy all files from old temporary folder to —NewFolder—
  • Update manually the paths of all things (like the audio files of the built in sampler) that have access to files
  • setTempDirectory(---NewFolder---)
  • EditFileOperations::saveAs(---NewFile---)

Is that the right solution?

Sorry, I would like to improve this but I’m really slammed for time. If you want to help expedite this, if you can write a failing test and post it, it would give me a good starting point to create a fix.
A test would need to be self contained so I imagine it will do something like:

  1. Create an Edit in a folder in the temp dir
  2. Create a temp sin file in the same dir
  3. Add an audio clip for this sin file on a track
  4. Save the edit to a new dir
  5. Fail a test that checks if the audio file for the clip exists (as it will now be at the wrong path)
  6. Clean up all the temp files

With that, I can just write the bits that will update all the relative paths and the test should pass. That would be a huge help.