commit ed20a1f08f2804c215636f843283fc2bfeefeb45
parent 458fbb70d53de80922249268abcf2114e4516ba5
Author: Keith <[email protected]>
Date: Thu, 13 Oct 2022 18:30:38 -0500
Updated error handling
Diffstat:
3 files changed, 18 insertions(+), 42 deletions(-)
diff --git a/src/PluginEditor.cpp b/src/PluginEditor.cpp
@@ -81,7 +81,7 @@ ProteusAudioProcessorEditor::ProteusAudioProcessorEditor (ProteusAudioProcessor&
odLevelKnob.setDoubleClickReturnValue(true, 0.5);
addAndMakeVisible(versionLabel);
- versionLabel.setText("v1.0", juce::NotificationType::dontSendNotification);
+ versionLabel.setText("v1.1", juce::NotificationType::dontSendNotification);
versionLabel.setJustificationType(juce::Justification::left);
versionLabel.setColour(juce::Label::textColourId, juce::Colours::white);
//auto font = versionLabel.getFont();
@@ -252,10 +252,17 @@ void ProteusAudioProcessorEditor::loadFromFolder()
processor.num_models += 1;
}
}
+ // Try to load model from saved_model, if it doesnt exist and jsonFiles is not empty, load the first model (if it exists and is valid format)
if (!processor.jsonFiles.empty()) {
- processor.loadConfig(processor.saved_model);
- modelSelect.setText(processor.saved_model.getFileNameWithoutExtension(), juce::NotificationType::dontSendNotification);
-
+ if (processor.saved_model.existsAsFile() && isValidFormat(processor.saved_model)) {
+ processor.loadConfig(processor.saved_model);
+ modelSelect.setText(processor.saved_model.getFileNameWithoutExtension(), juce::NotificationType::dontSendNotification);
+ } else {
+ if (processor.jsonFiles[0].existsAsFile() && isValidFormat(processor.jsonFiles[0])) {
+ processor.loadConfig(processor.jsonFiles[0]);
+ modelSelect.setText(processor.jsonFiles[0].getFileNameWithoutExtension(), juce::NotificationType::dontSendNotification);
+ }
+ }
//processor.loadConfig(processor.jsonFiles[processor.current_model_index]);
//modelSelect.setText(processor.jsonFiles[processor.current_model_index].getFileNameWithoutExtension(), juce::NotificationType::dontSendNotification);
}
@@ -289,9 +296,11 @@ void ProteusAudioProcessorEditor::modelSelectChanged()
{
const int selectedFileIndex = modelSelect.getSelectedItemIndex();
if (selectedFileIndex >= 0 && selectedFileIndex < processor.jsonFiles.size() && processor.jsonFiles.empty() == false) { //check if correct
- processor.loadConfig(processor.jsonFiles[selectedFileIndex]);
- processor.current_model_index = selectedFileIndex;
- processor.saved_model = processor.jsonFiles[selectedFileIndex];
+ if (processor.jsonFiles[selectedFileIndex].existsAsFile() && isValidFormat(processor.jsonFiles[selectedFileIndex])) {
+ processor.loadConfig(processor.jsonFiles[selectedFileIndex]);
+ processor.current_model_index = selectedFileIndex;
+ processor.saved_model = processor.jsonFiles[selectedFileIndex];
+ }
}
repaint();
}
diff --git a/src/PluginProcessor.cpp b/src/PluginProcessor.cpp
@@ -297,7 +297,8 @@ void ProteusAudioProcessor::setStateInformation (const void* data, int sizeInByt
//if (auto* editor = dynamic_cast<ProteusAudioProcessorEditor*> (getActiveEditor()))
// editor->loadFromFolder();
- if (isValidFormat(saved_model)) {
+ //if (isValidFormat(saved_model)) {
+ if (saved_model.existsAsFile()) {
loadConfig(saved_model);
}
@@ -305,39 +306,6 @@ void ProteusAudioProcessor::setStateInformation (const void* data, int sizeInByt
}
}
-bool ProteusAudioProcessor::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 ProteusAudioProcessor::loadConfig(File configFile)
{
diff --git a/src/PluginProcessor.h b/src/PluginProcessor.h
@@ -65,7 +65,6 @@ public:
void setStateInformation (const void* data, int sizeInBytes) override;
// Files and configuration
- bool isValidFormat(File configFile);
void loadConfig(File configFile);
// Pedal/amp states