refactor: formatting
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include "ADSR.h"
|
||||||
#include "Synth.h"
|
#include "Synth.h"
|
||||||
#include "SynthGuiState.h"
|
#include "SynthGuiState.h"
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "ADSR.h"
|
|
||||||
|
|
||||||
class Renderer {
|
class Renderer {
|
||||||
private:
|
private:
|
||||||
@@ -19,7 +19,9 @@ class Renderer {
|
|||||||
const std::vector<OscillatorGuiState*>& guiOscillators);
|
const std::vector<OscillatorGuiState*>& guiOscillators);
|
||||||
void draw_ui(Synth& synth, SynthGuiState& synth_gui);
|
void draw_ui(Synth& synth, SynthGuiState& synth_gui);
|
||||||
void draw_signal(Synth& synth, SynthGuiState& synth_gui);
|
void draw_signal(Synth& synth, SynthGuiState& synth_gui);
|
||||||
void draw_adsr_panel(ADSR* adsr, ADSRGuiState& gui_adsr, const Rectangle& panel_bounds, float panel_y_offset);
|
void draw_adsr_panel(ADSR* adsr, ADSRGuiState& gui_adsr,
|
||||||
|
const Rectangle& panel_bounds, float panel_y_offset);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Renderer(/* args */);
|
Renderer(/* args */);
|
||||||
~Renderer();
|
~Renderer();
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "ADSR.h"
|
||||||
#include "Adder.h"
|
#include "Adder.h"
|
||||||
#include "Effect.h"
|
#include "Effect.h"
|
||||||
#include "Note.h"
|
#include "Note.h"
|
||||||
#include "Oscillator.h"
|
#include "Oscillator.h"
|
||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "ADSR.h"
|
|
||||||
|
|
||||||
class Synth {
|
class Synth {
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -88,7 +88,8 @@ void ADSR::Process(std::vector<float>& samples) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ADSR::SetParameters(float attack, float decay, float sustain, float release) {
|
void ADSR::SetParameters(float attack, float decay, float sustain,
|
||||||
|
float release) {
|
||||||
m_parameters.attack_time = attack;
|
m_parameters.attack_time = attack;
|
||||||
m_parameters.decay_time = decay;
|
m_parameters.decay_time = decay;
|
||||||
m_parameters.sustain_level = sustain;
|
m_parameters.sustain_level = sustain;
|
||||||
|
|||||||
107
src/Renderer.cpp
107
src/Renderer.cpp
@@ -179,68 +179,67 @@ void Renderer::draw_ui(Synth& synth, SynthGuiState& synth_gui) {
|
|||||||
std::vector<Oscillator*> oscillators = synth.GetOscillators();
|
std::vector<Oscillator*> oscillators = synth.GetOscillators();
|
||||||
std::vector<OscillatorGuiState*> gui_oscillators = synth_gui.oscillators;
|
std::vector<OscillatorGuiState*> gui_oscillators = synth_gui.oscillators;
|
||||||
|
|
||||||
float panel_y_offset = draw_oscillators_panels(oscillators, gui_oscillators, panel_bounds);
|
float panel_y_offset =
|
||||||
|
draw_oscillators_panels(oscillators, gui_oscillators, panel_bounds);
|
||||||
draw_oscillators_shape_inputs(oscillators, gui_oscillators);
|
draw_oscillators_shape_inputs(oscillators, gui_oscillators);
|
||||||
|
|
||||||
draw_adsr_panel(synth.GetADSR(), synth_gui.adsr, panel_bounds, panel_y_offset);
|
draw_adsr_panel(synth.GetADSR(), synth_gui.adsr, panel_bounds,
|
||||||
|
panel_y_offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::draw_adsr_panel(ADSR* adsr, ADSRGuiState& gui_adsr, const Rectangle& panel_bounds, float panel_y_offset) {
|
void Renderer::draw_adsr_panel(ADSR* adsr, ADSRGuiState& gui_adsr,
|
||||||
// Draw ADSR Panel
|
const Rectangle& panel_bounds,
|
||||||
const int osc_panel_width = panel_bounds.width - 20;
|
float panel_y_offset) {
|
||||||
const int osc_panel_height = 120;
|
// Draw ADSR Panel
|
||||||
const int osc_panel_x = panel_bounds.x + 10;
|
const int osc_panel_width = panel_bounds.width - 20;
|
||||||
const int osc_panel_y = panel_bounds.y + 50 + panel_y_offset;
|
const int osc_panel_height = 120;
|
||||||
panel_y_offset += osc_panel_height + 5;
|
const int osc_panel_x = panel_bounds.x + 10;
|
||||||
GuiPanel((Rectangle){(float)osc_panel_x, (float)osc_panel_y,
|
const int osc_panel_y = panel_bounds.y + 50 + panel_y_offset;
|
||||||
(float)osc_panel_width, (float)osc_panel_height},
|
panel_y_offset += osc_panel_height + 5;
|
||||||
"ADSR");
|
GuiPanel((Rectangle){(float)osc_panel_x, (float)osc_panel_y,
|
||||||
|
(float)osc_panel_width, (float)osc_panel_height},
|
||||||
|
"ADSR");
|
||||||
|
|
||||||
const float slider_padding = 50.f;
|
const float slider_padding = 50.f;
|
||||||
const float el_spacing = 5.f;
|
const float el_spacing = 5.f;
|
||||||
Rectangle el_rect = {.x = (float)osc_panel_x + slider_padding + 30,
|
Rectangle el_rect = {.x = (float)osc_panel_x + slider_padding + 30,
|
||||||
.y = (float)osc_panel_y + 10,
|
.y = (float)osc_panel_y + 10,
|
||||||
.width =
|
.width = (float)osc_panel_width - (slider_padding * 2),
|
||||||
(float)osc_panel_width - (slider_padding * 2),
|
.height = 25.f};
|
||||||
.height = 25.f};
|
|
||||||
|
|
||||||
// Attack slider
|
// Attack slider
|
||||||
float attack = gui_adsr.attack;
|
float attack = gui_adsr.attack;
|
||||||
char attack_slider_label[32];
|
char attack_slider_label[32];
|
||||||
snprintf(attack_slider_label, 7, "%.1f s", attack);
|
snprintf(attack_slider_label, 7, "%.1f s", attack);
|
||||||
attack =
|
attack = GuiSlider(el_rect, attack_slider_label, "", attack, 0.0f, 2.0f);
|
||||||
GuiSlider(el_rect, attack_slider_label, "", attack, 0.0f, 2.0f);
|
gui_adsr.attack = attack;
|
||||||
gui_adsr.attack = attack;
|
el_rect.y += el_rect.height + el_spacing;
|
||||||
el_rect.y += el_rect.height + el_spacing;
|
|
||||||
|
|
||||||
//Decay slider
|
// Decay slider
|
||||||
float decay = gui_adsr.decay;
|
float decay = gui_adsr.decay;
|
||||||
char decay_slider_label[32];
|
char decay_slider_label[32];
|
||||||
snprintf(decay_slider_label, 7, "%.1f s", decay);
|
snprintf(decay_slider_label, 7, "%.1f s", decay);
|
||||||
decay =
|
decay = GuiSlider(el_rect, decay_slider_label, "", decay, 0.0f, 1.0f);
|
||||||
GuiSlider(el_rect, decay_slider_label, "", decay, 0.0f, 1.0f);
|
gui_adsr.decay = decay;
|
||||||
gui_adsr.decay = decay;
|
el_rect.y += el_rect.height + el_spacing;
|
||||||
el_rect.y += el_rect.height + el_spacing;
|
|
||||||
|
|
||||||
//Sustain slider
|
// Sustain slider
|
||||||
float sustain = gui_adsr.sustain;
|
float sustain = gui_adsr.sustain;
|
||||||
char sustain_slider_label[32];
|
char sustain_slider_label[32];
|
||||||
snprintf(sustain_slider_label, 7, "%.1f u", sustain);
|
snprintf(sustain_slider_label, 7, "%.1f u", sustain);
|
||||||
sustain =
|
sustain = GuiSlider(el_rect, sustain_slider_label, "", sustain, 0.0f, 1.0f);
|
||||||
GuiSlider(el_rect, sustain_slider_label, "", sustain, 0.0f, 1.0f);
|
gui_adsr.sustain = sustain;
|
||||||
gui_adsr.sustain = sustain;
|
el_rect.y += el_rect.height + el_spacing;
|
||||||
el_rect.y += el_rect.height + el_spacing;
|
|
||||||
|
|
||||||
|
// Release slider
|
||||||
|
float release = gui_adsr.release;
|
||||||
|
char release_slider_label[32];
|
||||||
|
snprintf(release_slider_label, 7, "%.1f s", release);
|
||||||
|
release = GuiSlider(el_rect, release_slider_label, "", release, 0.0f, 5.0f);
|
||||||
|
gui_adsr.release = release;
|
||||||
|
el_rect.y += el_rect.height + el_spacing;
|
||||||
|
|
||||||
//Release slider
|
// apply values to real one
|
||||||
float release = gui_adsr.release;
|
adsr->SetParameters(gui_adsr.attack, gui_adsr.decay, gui_adsr.sustain,
|
||||||
char release_slider_label[32];
|
gui_adsr.release);
|
||||||
snprintf(release_slider_label, 7, "%.1f s", release);
|
|
||||||
release =
|
|
||||||
GuiSlider(el_rect, release_slider_label, "", release, 0.0f, 5.0f);
|
|
||||||
gui_adsr.release = release;
|
|
||||||
el_rect.y += el_rect.height + el_spacing;
|
|
||||||
|
|
||||||
//apply values to real one
|
|
||||||
adsr->SetParameters(gui_adsr.attack, gui_adsr.decay, gui_adsr.sustain, gui_adsr.release);
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user