diff --git a/config/profiles/default.yaml b/config/profiles/default.yaml index 19fe404..7fa4d50 100644 --- a/config/profiles/default.yaml +++ b/config/profiles/default.yaml @@ -4,7 +4,7 @@ # sequences in the form [x, x, x] denote [setValue, sliderMinimum, sliderMaximum] -version: 00001 +version: 0x0002 # deprecated, useless Osc1Freq: [100, 20, 600] diff --git a/src/ParameterStore.cpp b/src/ParameterStore.cpp index 0262b20..a58a14e 100644 --- a/src/ParameterStore.cpp +++ b/src/ParameterStore.cpp @@ -2,6 +2,8 @@ #include "ParameterStore.h" #include +#include "yaml-cpp/yaml.h" // TODO: using yaml.h outside of ConfigInterface feels spaghetti to me +#include ParameterStore::ParameterStore(ConfigInterface* config) : config_(config) { resetToDefaults(); @@ -33,14 +35,41 @@ void ParameterStore::resetToDefaults() { values_[i].store(PARAM_DEFS[i].def, std::memory_order_relaxed); } - if(config_) { - int x = config_->getValue(ConfigFile::Audio, "sampleRate", 0); - std::cout << "test: " << x << std::endl; - } else { - std::cout << "pointer null" << std::endl; - } - + loadParameterProfile("config/profiles/default.yaml"); } -// TODO: applying parameter profiles will work similarly to above function +void ParameterStore::loadParameterProfile(std::string filepath) { + + // TODO: abstract the actual yaml interfacing to the ConfigInterface instead of here + // TODO: update ui based on changes that happen not in the ui + // it will require some architecture rework :( + + // load file + filepath = std::filesystem::absolute(filepath).string(); + YAML::Node config; + try { + config = YAML::LoadFile(filepath); + } catch(const std::exception& e) { + std::cerr << e.what() << std::endl; + return; + } + + // check version + int version = config["version"].as(); // yaml-cpp parses unquoted hex as integers + if(version < CONFIG_VERSION) { + std::cout << "Parameter profile version " << version << "is outdated below the compatible version " << CONFIG_VERSION << std::endl; + return; + } else { + //std::cout << version << std::endl; + } + + // start setting some values + YAML::Node osc1Volume = config["Osc1Volume"]; + YAML::Node fCutoff = config["FilterCutoff"]; + YAML::Node fResonance = config["FilterResonance"]; + set(EnvelopeId::Osc1Volume, osc1Volume[0][0].as(), osc1Volume[1][0].as(), osc1Volume[2][0].as(), osc1Volume[3][0].as(), osc1Volume[4][0].as()); + set(EnvelopeId::FilterCutoff, fCutoff[0][0].as(), fCutoff[1][0].as(), fCutoff[2][0].as(), fCutoff[3][0].as(), fCutoff[4][0].as()); + set(EnvelopeId::FilterResonance, fResonance[0][0].as(), fResonance[1][0].as(), fResonance[2][0].as(), fResonance[3][0].as(), fResonance[4][0].as()); + +} diff --git a/src/ParameterStore.h b/src/ParameterStore.h index 9b2493a..cf3b696 100644 --- a/src/ParameterStore.h +++ b/src/ParameterStore.h @@ -7,6 +7,8 @@ #include #include +#define CONFIG_VERSION 0x0001 + enum class ParamId : uint16_t { Osc1Frequency, Osc1WaveSelector1, @@ -121,6 +123,8 @@ public: private: + void loadParameterProfile(std::string filepath); + std::array, PARAM_COUNT> values_; ConfigInterface* config_;