commit 8f464b737916f842f2c7a3b8ca4324ae29b9847e
parent 71eff1bad5ee47edc2f12d854fee77c0df77334a
Author: Keith <smartguitarml@gmail.com>
Date: Fri, 7 Oct 2022 17:24:05 -0500
Updated error handling
Diffstat:
3 files changed, 40 insertions(+), 54 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
@@ -9,7 +9,7 @@ include_directories(modules)
#juce_set_aax_sdk_path(C:/SDKs/AAX_SDK/)
-set(JUCE_FORMATS AU VST3)
+set(JUCE_FORMATS AU VST3 Standalone)
# Build LV2 only on Linux
if(UNIX AND NOT APPLE)
diff --git a/src/PluginEditor.cpp b/src/PluginEditor.cpp
@@ -143,6 +143,37 @@ void ProteusAudioProcessorEditor::resized()
odFootSw.setBounds(185, 416, 175, 160);
}
+bool ProteusAudioProcessorEditor::isValidFormat(File configFile)
+{
+ // Read in the JSON file
+ String path = configFile.getFullPathName();
+ const char* char_filename = path.toUTF8();
+
+ std::ifstream i2(char_filename);
+ nlohmann::json weights_json;
+ i2 >> weights_json;
+
+ int hidden_size_temp = 0;
+ std::string network = "";
+
+ // Check that the hidden_size and unit_type fields exist and are correct
+ if (weights_json.contains("/model_data/unit_type"_json_pointer) == true && weights_json.contains("/model_data/hidden_size"_json_pointer) == true) {
+ // Get the input size of the JSON file
+ int input_size_json = weights_json["/model_data/hidden_size"_json_pointer];
+ std::string network_temp = weights_json["/model_data/unit_type"_json_pointer];
+
+ network = network_temp;
+ hidden_size_temp = input_size_json;
+ } else {
+ return false;
+ }
+
+ if (hidden_size_temp == 40 && network == "LSTM") {
+ return true;
+ } else {
+ return false;
+ }
+}
void ProteusAudioProcessorEditor::loadButtonClicked()
{
@@ -160,15 +191,7 @@ void ProteusAudioProcessorEditor::loadButtonClicked()
Array<File> files;
if (chooser.getResult().existsAsFile()) { // If a file is selected
- // Read in the JSON file
- String path = chooser.getResult().getFullPathName();
- const char* char_filename = path.toUTF8();
-
- std::ifstream i2(char_filename);
- nlohmann::json weights_json;
- i2 >> weights_json;
-
- if (weights_json.contains("/model_data/unit_type"_json_pointer) == true) {
+ if (isValidFormat(chooser.getResult())) {
processor.saved_model = chooser.getResult();
}
@@ -186,36 +209,22 @@ void ProteusAudioProcessorEditor::loadButtonClicked()
if (files.size() > 0) {
for (auto file : files) {
- // Read in the JSON file
- String path = file.getFullPathName();
- const char* char_filename = path.toUTF8();
- std::ifstream i2(char_filename);
- nlohmann::json weights_json;
- i2 >> weights_json;
-
- if (weights_json.contains("/model_data/unit_type"_json_pointer) == true) {
+ if (isValidFormat(file)) {
modelSelect.addItem(file.getFileNameWithoutExtension(), processor.jsonFiles.size() + 1);
processor.jsonFiles.push_back(file);
processor.num_models += 1;
}
}
if (chooser.getResult().existsAsFile()) {
- // Read in the JSON file
- String path = chooser.getResult().getFullPathName();
- const char* char_filename = path.toUTF8();
-
- std::ifstream i2(char_filename);
- nlohmann::json weights_json;
- i2 >> weights_json;
-
- if (weights_json.contains("/model_data/unit_type"_json_pointer) == true) {
+
+ if (isValidFormat(chooser.getResult()) == true) {
modelSelect.setText(processor.saved_model.getFileNameWithoutExtension());
processor.loadConfig(processor.saved_model);
}
}
else {
- if (processor.jsonFiles.empty() == false) {
+ if (!processor.jsonFiles.empty()) {
modelSelect.setSelectedItemIndex(0, juce::NotificationType::dontSendNotification);
modelSelectChanged();
}
@@ -237,32 +246,7 @@ void ProteusAudioProcessorEditor::loadFromFolder()
if (files.size() > 0) {
for (auto file : files) {
- // Read in the JSON file
- String path = file.getFullPathName();
- const char* char_filename = path.toUTF8();
-
- std::ifstream i2(char_filename);
- nlohmann::json weights_json;
- i2 >> weights_json;
-
- // Check that format is correct
- /*
- int hidden_size_temp = 0;
- std::string network;
- bool error = false;
- try {
- int input_size_json2 = weights_json["/model_data/input_size"_json_pointer];
- hidden_size_temp = input_size_json2;
-
- //std::string network2 = weights_json["/model_data/unit_type"_json_pointer];
- //network = network2;
- throw(hidden_size_temp);
- }
- catch (int hidden_size_temp) {
- error = true;
- }
- */
- if (weights_json.contains("/model_data/unit_type"_json_pointer) == true) {
+ if (isValidFormat(file)) {
modelSelect.addItem(file.getFileNameWithoutExtension(), processor.jsonFiles.size() + 1);
processor.jsonFiles.push_back(file);
processor.num_models += 1;
diff --git a/src/PluginEditor.h b/src/PluginEditor.h
@@ -41,6 +41,8 @@ private:
TextButton loadButton;
virtual void buttonClicked(Button* button) override;
+
+ bool isValidFormat(File configFile);
void loadButtonClicked();
//Image background = ImageCache::getFromMemory(BinaryData::smart_pedal_jpg, BinaryData::smart_pedal_jpgSize);