diff --git a/src/BlockFile.cpp b/src/BlockFile.cpp index 10fd14263..2a3598f07 100644 --- a/src/BlockFile.cpp +++ b/src/BlockFile.cpp @@ -53,7 +53,6 @@ out. #include "sndfile.h" #include "FileException.h" #include "FileFormats.h" -#include "MissingAliasFileDialog.h" // msmeyer: Define this to add debug output via wxPrintf() //#define DEBUG_BLOCKFILE @@ -479,6 +478,23 @@ bool BlockFile::Read64K(float *buffer, return result; } +namespace { + BlockFile::MissingAliasFileFoundHook &GetMissingAliasFileFound() + { + static BlockFile::MissingAliasFileFoundHook theHook; + return theHook; + } +} + +auto BlockFile::SetMissingAliasFileFound( MissingAliasFileFoundHook hook ) + -> MissingAliasFileFoundHook +{ + auto &theHook = GetMissingAliasFileFound(); + auto result = theHook; + theHook = hook; + return result; +} + size_t BlockFile::CommonReadData( bool mayThrow, const wxFileName &fileName, bool &mSilentLog, @@ -537,8 +553,9 @@ size_t BlockFile::CommonReadData( if (pAliasFile) { // Set a marker to display an error message for the silence - if (!MissingAliasFilesDialog::ShouldShow()) - MissingAliasFilesDialog::Mark(pAliasFile); + auto hook = GetMissingAliasFileFound(); + if (hook) + hook( pAliasFile ); } } } diff --git a/src/BlockFile.h b/src/BlockFile.h index cab8b5f20..baa0b247a 100644 --- a/src/BlockFile.h +++ b/src/BlockFile.h @@ -18,6 +18,8 @@ #include "ondemand/ODTaskThread.h" +#include + class XMLWriter; class SummaryInfo { @@ -49,6 +51,14 @@ inline std::shared_ptr< Result > make_blockfile (Args && ... args) class PROFILE_DLL_API BlockFile /* not final, abstract */ { public: + // Type of function to be called when opening of an alias block file for read + // discovers that the other audio file it depends on is absent + using MissingAliasFileFoundHook = + std::function< void(const AliasBlockFile*) >; + // Install a hook, and return the previous hook + static MissingAliasFileFoundHook + SetMissingAliasFileFound( MissingAliasFileFoundHook hook ); + // Constructor / Destructor /// Construct a BlockFile. diff --git a/src/MissingAliasFileDialog.cpp b/src/MissingAliasFileDialog.cpp index ee895ad5d..d0f00ddb9 100644 --- a/src/MissingAliasFileDialog.cpp +++ b/src/MissingAliasFileDialog.cpp @@ -131,3 +131,12 @@ namespace MissingAliasFilesDialog { } } + +// Arrange callback from low levels of block file I/O to detect missing files +static struct InstallHook{ InstallHook() { + auto hook = [](const AliasBlockFile *pAliasFile){ + if (!MissingAliasFilesDialog::ShouldShow()) + MissingAliasFilesDialog::Mark(pAliasFile); + }; + BlockFile::SetMissingAliasFileFound( hook ); +} } installHook;