From c24dee7c3c88af35fd30b0652b3241526b208f8c Mon Sep 17 00:00:00 2001 From: Steven Atkinson Date: Sun, 9 Aug 2026 11:33:43 -0700 Subject: [PATCH 1/3] fix: surface directory scan failures --- NeuralAmpModeler/NeuralAmpModelerControls.h | 23 +++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/NeuralAmpModeler/NeuralAmpModelerControls.h b/NeuralAmpModeler/NeuralAmpModelerControls.h index cd6e5b07b..f80693cd3 100644 --- a/NeuralAmpModeler/NeuralAmpModelerControls.h +++ b/NeuralAmpModeler/NeuralAmpModelerControls.h @@ -352,7 +352,8 @@ class NAMFileBrowserControl : public IDirBrowseControlBase AddPath(path.Get(), ""); SetupMenu(); SetSelectedFile(fileName.Get()); - LoadFileAtCurrentIndex(); + if (!LoadFileAtCurrentIndex()) + ReportDirectoryScanFailure(fileName, path); } }); #endif @@ -412,7 +413,7 @@ class NAMFileBrowserControl : public IDirBrowseControlBase SetBrowserState(NAMBrowserState::Empty); } - void LoadFileAtCurrentIndex() + bool LoadFileAtCurrentIndex() { if (mSelectedItemIndex > -1 && mSelectedItemIndex < NItems()) { @@ -420,7 +421,10 @@ class NAMFileBrowserControl : public IDirBrowseControlBase GetSelectedFile(fileName); mFileNameControl->SetLabelAndTooltipEllipsizing(fileName); mCompletionHandlerFunc(fileName, path); + return true; } + + return false; } void OnMsgFromDelegate(int msgTag, int dataSize, const void* pData) override @@ -456,6 +460,21 @@ class NAMFileBrowserControl : public IDirBrowseControlBase } private: + void ReportDirectoryScanFailure(const WDL_String& fileName, const WDL_String& path) + { + mFileNameControl->SetLabelAndTooltipEllipsizing(fileName); + const std::string label = std::string("(FAILED) ") + mFileNameControl->GetLabelStr(); + + std::stringstream message; + message << "The selected file '" << fileName.Get() << "' was not found after scanning directory '" << path.Get() + << "'. The host may not have granted permission to enumerate that directory."; + + mFileNameControl->SetLabelStr(label.c_str()); + mFileNameControl->SetTooltip(message.str().c_str()); + SetBrowserState(NAMBrowserState::Empty); + std::fprintf(stderr, "NAM: %s\n", message.str().c_str()); + } + void SelectFirstFile() { mSelectedItemIndex = mFiles.GetSize() ? 0 : -1; } void GetSelectedFileDirectory(WDL_String& path) From f57c12c4d9dcc63c65214ba6f1059c8dabe1d7ed Mon Sep 17 00:00:00 2001 From: Steven Atkinson Date: Sun, 9 Aug 2026 12:16:56 -0700 Subject: [PATCH 2/3] refactor: classify file browser load failures --- NeuralAmpModeler/NeuralAmpModelerControls.h | 60 +++++++++++++++------ 1 file changed, 45 insertions(+), 15 deletions(-) diff --git a/NeuralAmpModeler/NeuralAmpModelerControls.h b/NeuralAmpModeler/NeuralAmpModelerControls.h index f80693cd3..4f8fa8cb1 100644 --- a/NeuralAmpModeler/NeuralAmpModelerControls.h +++ b/NeuralAmpModeler/NeuralAmpModelerControls.h @@ -25,6 +25,12 @@ enum class NAMBrowserState Loaded // when file loaded, show "Clear" button }; +enum class NAMFileLoadSource +{ + ExistingBrowserSelection, + FilePickerSelection +}; + // Where the corner button on the plugin (settings, close settings) goes // :param rect: Rect for the whole plugin's UI IRECT CornerButtonArea(const IRECT& rect) @@ -297,7 +303,7 @@ class NAMFileBrowserControl : public IDirBrowseControlBase if (pItem) { mSelectedItemIndex = mItems.Find(pItem); - LoadFileAtCurrentIndex(); + LoadFileAtCurrentIndex(NAMFileLoadSource::ExistingBrowserSelection); } } } @@ -313,7 +319,7 @@ class NAMFileBrowserControl : public IDirBrowseControlBase if (mSelectedItemIndex < 0) mSelectedItemIndex = nItems - 1; - LoadFileAtCurrentIndex(); + LoadFileAtCurrentIndex(NAMFileLoadSource::ExistingBrowserSelection); }; auto nextFileFunc = [&](IControl* pCaller) { @@ -325,7 +331,7 @@ class NAMFileBrowserControl : public IDirBrowseControlBase if (mSelectedItemIndex >= nItems) mSelectedItemIndex = 0; - LoadFileAtCurrentIndex(); + LoadFileAtCurrentIndex(NAMFileLoadSource::ExistingBrowserSelection); }; auto loadFileFunc = [&](IControl* pCaller) { @@ -340,7 +346,7 @@ class NAMFileBrowserControl : public IDirBrowseControlBase AddPath(path.Get(), ""); SetupMenu(); SelectFirstFile(); - LoadFileAtCurrentIndex(); + LoadFileAtCurrentIndex(NAMFileLoadSource::ExistingBrowserSelection); } }); #else @@ -352,8 +358,7 @@ class NAMFileBrowserControl : public IDirBrowseControlBase AddPath(path.Get(), ""); SetupMenu(); SetSelectedFile(fileName.Get()); - if (!LoadFileAtCurrentIndex()) - ReportDirectoryScanFailure(fileName, path); + LoadFileAtCurrentIndex(NAMFileLoadSource::FilePickerSelection, &fileName, &path); } }); #endif @@ -413,18 +418,26 @@ class NAMFileBrowserControl : public IDirBrowseControlBase SetBrowserState(NAMBrowserState::Empty); } - bool LoadFileAtCurrentIndex() + void LoadFileAtCurrentIndex(NAMFileLoadSource source, const WDL_String* filePickerFileName = nullptr, + const WDL_String* filePickerPath = nullptr) { - if (mSelectedItemIndex > -1 && mSelectedItemIndex < NItems()) + if (source == NAMFileLoadSource::FilePickerSelection && mSelectedItemIndex == -1 && + filePickerFileName != nullptr && filePickerPath != nullptr) { - WDL_String fileName, path; - GetSelectedFile(fileName); - mFileNameControl->SetLabelAndTooltipEllipsizing(fileName); - mCompletionHandlerFunc(fileName, path); - return true; + ReportDirectoryScanFailure(*filePickerFileName, *filePickerPath); + return; } - return false; + if (mSelectedItemIndex < 0 || mSelectedItemIndex >= NItems()) + { + ReportUnexpectedLoadFailure(source, filePickerFileName); + return; + } + + WDL_String fileName, path; + GetSelectedFile(fileName); + mFileNameControl->SetLabelAndTooltipEllipsizing(fileName); + mCompletionHandlerFunc(fileName, path); } void OnMsgFromDelegate(int msgTag, int dataSize, const void* pData) override @@ -472,7 +485,24 @@ class NAMFileBrowserControl : public IDirBrowseControlBase mFileNameControl->SetLabelStr(label.c_str()); mFileNameControl->SetTooltip(message.str().c_str()); SetBrowserState(NAMBrowserState::Empty); - std::fprintf(stderr, "NAM: %s\n", message.str().c_str()); + std::fprintf(stderr, "NAM: File picker selection produced index -1. %s\n", message.str().c_str()); + } + + void ReportUnexpectedLoadFailure(NAMFileLoadSource source, const WDL_String* filePickerFileName) + { + if (filePickerFileName != nullptr) + mFileNameControl->SetLabelAndTooltipEllipsizing(*filePickerFileName); + + const std::string label = std::string("(FAILED) ") + mFileNameControl->GetLabelStr(); + const std::string message = "The selected file could not be loaded because the file browser encountered an " + "unexpected selection state. Please select the file again."; + + mFileNameControl->SetLabelStr(label.c_str()); + mFileNameControl->SetTooltip(message.c_str()); + SetBrowserState(NAMBrowserState::Empty); + std::fprintf(stderr, "NAM: %s Source: %s; selected index: %d; item count: %d.\n", message.c_str(), + source == NAMFileLoadSource::FilePickerSelection ? "file picker" : "existing browser selection", + mSelectedItemIndex, NItems()); } void SelectFirstFile() { mSelectedItemIndex = mFiles.GetSize() ? 0 : -1; } From a08697f4bcd39bf24ad440da3294cd782ed6b61a Mon Sep 17 00:00:00 2001 From: Steven Atkinson Date: Sun, 9 Aug 2026 12:23:59 -0700 Subject: [PATCH 3/3] Formatting --- NeuralAmpModeler/NeuralAmpModelerControls.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/NeuralAmpModeler/NeuralAmpModelerControls.h b/NeuralAmpModeler/NeuralAmpModelerControls.h index 4f8fa8cb1..4615e2072 100644 --- a/NeuralAmpModeler/NeuralAmpModelerControls.h +++ b/NeuralAmpModeler/NeuralAmpModelerControls.h @@ -421,8 +421,8 @@ class NAMFileBrowserControl : public IDirBrowseControlBase void LoadFileAtCurrentIndex(NAMFileLoadSource source, const WDL_String* filePickerFileName = nullptr, const WDL_String* filePickerPath = nullptr) { - if (source == NAMFileLoadSource::FilePickerSelection && mSelectedItemIndex == -1 && - filePickerFileName != nullptr && filePickerPath != nullptr) + if (source == NAMFileLoadSource::FilePickerSelection && mSelectedItemIndex == -1 && filePickerFileName != nullptr + && filePickerPath != nullptr) { ReportDirectoryScanFailure(*filePickerFileName, *filePickerPath); return; @@ -494,8 +494,9 @@ class NAMFileBrowserControl : public IDirBrowseControlBase mFileNameControl->SetLabelAndTooltipEllipsizing(*filePickerFileName); const std::string label = std::string("(FAILED) ") + mFileNameControl->GetLabelStr(); - const std::string message = "The selected file could not be loaded because the file browser encountered an " - "unexpected selection state. Please select the file again."; + const std::string message = + "The selected file could not be loaded because the file browser encountered an " + "unexpected selection state. Please select the file again."; mFileNameControl->SetLabelStr(label.c_str()); mFileNameControl->SetTooltip(message.c_str());