wip: apply gui states

This commit is contained in:
2024-01-19 01:55:51 +07:00
parent b996685fe6
commit 19c90b0434
2 changed files with 64 additions and 29 deletions

View File

@@ -1,10 +1,11 @@
#include "Application.h" #include "Application.h"
#include "Logger.h" #include "Logger.h"
#include "Settings.h" #include "Settings.h"
#include <string>
#include <fstream> //read file
#include <cmath> // log10f #include <cmath> // log10f
#include <fstream> // read file
#include <iostream> // log error
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <string>
using json = nlohmann::json; using json = nlohmann::json;
Application::Application(/* args */) { Application::Application(/* args */) {
@@ -125,30 +126,64 @@ void Application::Run() {
void Application::ParsePatch(std::string file_path) { void Application::ParsePatch(std::string file_path) {
std::ifstream f(file_path); std::ifstream f(file_path);
if (!f.is_open()) {
std::cerr << "[ERR] failed to open " << file_path << '\n';
} else {
json data = json::parse(f); json data = json::parse(f);
auto oscillators = m_synth.GetOscillators(); auto oscillators = m_synth.GetOscillators();
for (int i = 0; i < oscillators.size(); i++) { for (int i = 0; i < oscillators.size(); i++) {
auto osc = oscillators[i]; auto osc = oscillators[i];
osc->SetType(data["Oscillators"][i]["Wave"].template get<std::string>()); auto gui_osc = m_synth_gui_state.oscillators[i];
osc->SetVolume(data["Oscillators"][i]["Volume"].template get<float>());
osc->SetFine(data["Oscillators"][i]["Tune"].template get<float>()); std::string type =
data["Oscillators"][i]["Wave"].template get<std::string>();
float fine = data["Oscillators"][i]["Tune"].template get<float>();
float volume =
data["Oscillators"][i]["Volume"].template get<float>();
osc->SetType(type);
osc->SetFine(fine);
osc->SetVolume(volume);
gui_osc->waveshape = osc->GetType();
gui_osc->fine = fine;
gui_osc->volume = volume;
} }
auto adsr = m_synth.GetADSR(); auto adsr = m_synth.GetADSR();
auto gui_adsr = m_synth_gui_state.adsr;
auto adsr_params = data["ADSR"]; auto adsr_params = data["ADSR"];
adsr->SetParameters(adsr_params["Attack"].template get<float>(), float attack = adsr_params["Attack"].template get<float>();
adsr_params["Decay"].template get<float>(), float decay = adsr_params["Decay"].template get<float>();
adsr_params["Sustain"].template get<float>(), float sustain = adsr_params["Sustain"].template get<float>();
adsr_params["Release"].template get<float>()); float release = adsr_params["Release"].template get<float>();
adsr->SetParameters(attack, decay, sustain, release);
gui_adsr.attack = attack;
gui_adsr.decay = decay;
gui_adsr.sustain = sustain;
gui_adsr.release = release;
auto lfo = m_synth.GetLFO(); auto lfo = m_synth.GetLFO();
lfo->SetFreq(data["LFO"]["Freq"].template get<float>()); lfo->SetFreq(data["LFO"]["Freq"].template get<float>());
m_synth.SetLFOLevel(data["LFO"]["Level"].template get<float>()); m_synth.SetLFOLevel(data["LFO"]["Level"].template get<float>());
m_synth.SetFilter((FilterType)data["Filter"]["Cutoff"].template get<int>()); auto filter_type =
(FilterType)data["Filter"]["Type"].template get<int>();
m_synth.SetFilter(filter_type);
auto filter = m_synth.GetFilter(); auto filter = m_synth.GetFilter();
filter->SetParameters(std::log10f(data["Filter"]["Cutoff"].template get<float>()), auto gui_filter = m_synth_gui_state.filter;
data["Filter"]["Res"].template get<float>(),
data["Filter"]["Drive"].template get<float>()); float filter_freq =
std::log10f(data["Filter"]["Cutoff"].template get<float>());
float filter_res = data["Filter"]["Res"].template get<float>();
float filter_drive = data["Filter"]["Drive"].template get<float>();
filter->SetParameters(filter_freq, filter_res, filter_drive);
gui_filter.freq = filter_freq;
gui_filter.type = filter_type;
}
} }