Skip to content

Commit eafde66

Browse files
committed
Add warning messages in FileReader
1 parent 7321cd1 commit eafde66

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

Source/Processors/FileReader/FileReader.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ void FileReader::parameterValueChanged (Parameter* p)
103103
{
104104
if (p->getName() == "selected_file")
105105
{
106+
LOGC ("FileReader::parameterValueChanged - selected_file changed to: ", p->getValue().toString());
106107
setFile (p->getValue(), false);
107108
}
108109
else if (p->getName() == "active_stream")
@@ -239,6 +240,8 @@ bool FileReader::setFile (String fullpath, bool shouldUpdateSignalChain)
239240
}
240241
}
241242

243+
LOGC ("[FileReader] set file: ", fullpath);
244+
242245
//Open file
243246
File file (fullpath);
244247

@@ -262,28 +265,31 @@ bool FileReader::setFile (String fullpath, bool shouldUpdateSignalChain)
262265
if (! input)
263266
{
264267
LOGE ("Error creating file source for extension ", ext);
268+
showWarningAsync ("Failed to open file", "Error creating file source for extension " + ext);
265269
return false;
266270
}
267271
}
268272
else
269273
{
270274
input = nullptr;
275+
showWarningAsync ("Failed to open file", "File type \"" + ext + "\" not supported");
271276
CoreServices::sendStatusMessage ("File type not supported");
272277
return false;
273278
}
274279

275280
if (! input->openFile (file))
276281
{
277282
input = nullptr;
283+
showWarningAsync ("Invalid file", "The selected file is invalid. Please make sure the file is not corrupted and has valid format.");
278284
CoreServices::sendStatusMessage ("Invalid file");
279-
280285
return false;
281286
}
282287

283288
const bool isEmptyFile = input->getNumRecords() <= 0;
284289
if (isEmptyFile)
285290
{
286291
input = nullptr;
292+
showWarningAsync ("Failed to open file", "Continuous data file is missing or empty.");
287293
CoreServices::sendStatusMessage ("Empty file. Ignoring open operation");
288294

289295
return false;
@@ -318,6 +324,17 @@ bool FileReader::setFile (String fullpath, bool shouldUpdateSignalChain)
318324
return true;
319325
}
320326

327+
void FileReader::showWarningAsync (const String& title, const String& message) const
328+
{
329+
if (headlessMode)
330+
return;
331+
332+
MessageManager::callAsync ([title, message]()
333+
{ AlertWindow::showMessageBoxAsync (AlertWindow::WarningIcon,
334+
title,
335+
message); });
336+
}
337+
321338
void FileReader::setActiveStream (int index, bool reset)
322339
{
323340
//Resets the stream to the beginning if reset flag is true

Source/Processors/FileReader/FileReader.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,9 @@ class FileReader : public GenericProcessor,
242242
/** Returns a new FileSource object for a given file source */
243243
FileSource* createBuiltInFileSource (int index) const;
244244

245+
/** Shows a warning message asynchronously */
246+
void showWarningAsync (const String& title, const String& message) const;
247+
245248
/** Holds a path to the default file */
246249
File defaultFile;
247250

Source/Processors/FileReader/FileReaderActions.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,9 @@ bool SelectFile::perform()
4747
// Set the new path - this will trigger the linked parameter changes
4848
pathParam->setNextValue (newPath, false);
4949

50-
// Load the new file
51-
bool success = processor->setFile (newPath, false);
52-
53-
if (!success)
50+
// Check if the file was loaded successfully
51+
if (processor->getFile().isEmpty()
52+
|| ! processor->getFile().equalsIgnoreCase (newPath.toString()))
5453
{
5554
// If loading the file failed, revert the path parameter to the original path
5655
pathParam->setNextValue (originalPath, false);

0 commit comments

Comments
 (0)