Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow sharing of a document and its audio file without consolidating tracks #69

Merged
merged 1 commit into from
Jan 15, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 33 additions & 4 deletions Source/Document/AnlDocumentDirector.cpp
Original file line number Diff line number Diff line change
@@ -18,20 +18,44 @@ Document::Director::Director(Accessor& accessor, juce::AudioFormatManager& audio
{
FileWatcher::clearAllFiles();
auto const reader = mAccessor.getAttr<AttrType::reader>();
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<AttrType::reader>(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<void(bool)> showHideFn)
{
mPluginTable = table;
2 changes: 2 additions & 0 deletions Source/Document/AnlDocumentDirector.h
Original file line number Diff line number Diff line change
@@ -43,6 +43,7 @@ namespace Document
std::optional<juce::String> 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<void(bool)> showHideFn);
void setLoaderSelector(Track::Loader::ArgumentSelector* selector, std::function<void(bool)> showHideFn);
void setBackupDirectory(juce::File const& directory);
@@ -77,6 +78,7 @@ namespace Document
std::unique_ptr<juce::FileChooser> mFileChooser;
juce::File mBackupDirectory;
bool mSilentResultsFileManagement{false};
std::pair<juce::File, juce::File> mFileMapper;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Director)
JUCE_DECLARE_WEAK_REFERENCEABLE(Director)
1 change: 1 addition & 0 deletions Source/Document/AnlDocumentFileBased.cpp
Original file line number Diff line number Diff line change
@@ -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);