From 2314664f3c6486231d96e4d8c2b32c5b8eab1c21 Mon Sep 17 00:00:00 2001 From: Pierre Guillot Date: Wed, 15 Jan 2025 11:32:12 +0100 Subject: [PATCH] Document::Director: Share a document and its audio file without consolidating tracks --- Source/Document/AnlDocumentDirector.cpp | 37 +++++++++++++++++++++--- Source/Document/AnlDocumentDirector.h | 2 ++ Source/Document/AnlDocumentFileBased.cpp | 1 + 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/Source/Document/AnlDocumentDirector.cpp b/Source/Document/AnlDocumentDirector.cpp index 048cf413..ccf48ccb 100644 --- a/Source/Document/AnlDocumentDirector.cpp +++ b/Source/Document/AnlDocumentDirector.cpp @@ -18,20 +18,44 @@ Document::Director::Director(Accessor& accessor, juce::AudioFormatManager& audio { FileWatcher::clearAllFiles(); auto const reader = mAccessor.getAttr(); - for(auto const& channelLayout : reader) - { - FileWatcher::addFile(channelLayout.file); - } if(std::none_of(reader.cbegin(), reader.cend(), [](auto const& channelLayout) { auto const file = channelLayout.file; return file != juce::File{} && !file.existsAsFile(); })) { + for(auto const& channelLayout : reader) + { + FileWatcher::addFile(channelLayout.file); + } initializeAudioReaders(notification); } else { + auto newReader = reader; + if(mFileMapper.first != juce::File() && mFileMapper.second != juce::File()) + { + for(auto& channelLayout : newReader) + { + if(!channelLayout.file.existsAsFile()) + { + auto const relativePath = channelLayout.file.getRelativePathFrom(mFileMapper.first); + auto const newPath = mFileMapper.second.getSiblingFile(relativePath); + if(newPath.existsAsFile()) + { + channelLayout.file = newPath; + } + } + } + } + mFileMapper.first = juce::File{}; + mFileMapper.second = juce::File{}; + if(newReader != reader) + { + mAccessor.setAttr(newReader, notification); + return; + } + auto const options = juce::MessageBoxOptions() .withIconType(juce::AlertWindow::WarningIcon) .withTitle(juce::translate("Audio(s) files cannot be found!")) @@ -424,6 +448,11 @@ void Document::Director::setAlertCatcher(AlertWindow::Catcher* catcher) } } +void Document::Director::setFileMapper(juce::File const& saved, juce::File const& current) +{ + mFileMapper = std::make_pair(saved, current); +} + void Document::Director::setPluginTable(PluginList::Table* table, std::function showHideFn) { mPluginTable = table; diff --git a/Source/Document/AnlDocumentDirector.h b/Source/Document/AnlDocumentDirector.h index 55995816..e4fd43e0 100644 --- a/Source/Document/AnlDocumentDirector.h +++ b/Source/Document/AnlDocumentDirector.h @@ -43,6 +43,7 @@ namespace Document std::optional copyTrack(juce::String const groupIdentifier, size_t index, juce::String const trackIdentifier, NotificationType const notification); void setAlertCatcher(AlertWindow::Catcher* catcher); + void setFileMapper(juce::File const& saved, juce::File const& current); void setPluginTable(PluginList::Table* table, std::function showHideFn); void setLoaderSelector(Track::Loader::ArgumentSelector* selector, std::function showHideFn); void setBackupDirectory(juce::File const& directory); @@ -77,6 +78,7 @@ namespace Document std::unique_ptr mFileChooser; juce::File mBackupDirectory; bool mSilentResultsFileManagement{false}; + std::pair mFileMapper; JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Director) JUCE_DECLARE_WEAK_REFERENCEABLE(Director) diff --git a/Source/Document/AnlDocumentFileBased.cpp b/Source/Document/AnlDocumentFileBased.cpp index f79e9e95..38708750 100644 --- a/Source/Document/AnlDocumentFileBased.cpp +++ b/Source/Document/AnlDocumentFileBased.cpp @@ -127,6 +127,7 @@ juce::Result Document::FileBased::loadDocument(juce::File const& file) AlertWindow::Catcher catcher; mDirector.setAlertCatcher(&catcher); + mDirector.setFileMapper(original, file); mAccessor.sendSignal(SignalType::isLoading, {true}, NotificationType::synchronous); mAccessor.fromXml(*xml.get(), {"document"}, NotificationType::synchronous); [[maybe_unused]] auto const references = mDirector.sanitize(NotificationType::synchronous);