feat: add oscillator button
This commit is contained in:
@@ -8,17 +8,18 @@ class Renderer
|
||||
{
|
||||
private:
|
||||
void DrawMainPanel(const Rectangle& panel_bounds);
|
||||
void DrawAddOscillatorButton(Synth & synth, SynthGuiState & synthGui, Rectangle panel_bounds);
|
||||
void DrawOscillatorsPanels(const std::vector<Oscillator*>& oscillators,
|
||||
const std::vector<OscillatorGuiState*>& guiOscillators,
|
||||
const Rectangle& panel_bounds);
|
||||
void DrawOscillatorsShapeInputs(const std::vector<Oscillator*>& oscillators,
|
||||
const std::vector<OscillatorGuiState*>& guiOscillators);
|
||||
void DrawUi(Synth & synth, const SynthGuiState & synthGui);
|
||||
void DrawSignal(Synth & synth, const SynthGuiState & synthGui);
|
||||
void DrawUi(Synth & synth, SynthGuiState & synthGui);
|
||||
void DrawSignal(Synth & synth, SynthGuiState & synthGui);
|
||||
public:
|
||||
Renderer(/* args */);
|
||||
~Renderer();
|
||||
void Draw(Synth& synth, const SynthGuiState & synthGui);
|
||||
void Draw(Synth& synth, SynthGuiState & synthGui);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ public:
|
||||
Synth(/* args */);
|
||||
~Synth();
|
||||
void ProduceNoteSound(Note input);
|
||||
void AddOscillator();
|
||||
const std::vector<float> & GetOutSignal() { return m_out_signal; }
|
||||
const std::vector<Oscillator*>& GetOscillators() { return m_oscillators; }
|
||||
};
|
||||
@@ -14,7 +14,7 @@ Renderer::~Renderer()
|
||||
{
|
||||
}
|
||||
|
||||
void Renderer::Draw(Synth& synth, const SynthGuiState& synthGui)
|
||||
void Renderer::Draw(Synth& synth, SynthGuiState& synthGui)
|
||||
{
|
||||
BeginDrawing();
|
||||
|
||||
@@ -28,7 +28,7 @@ void Renderer::Draw(Synth& synth, const SynthGuiState& synthGui)
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
void Renderer::DrawSignal(Synth & synth, const SynthGuiState & synthGui)
|
||||
void Renderer::DrawSignal(Synth & synth, SynthGuiState & synthGui)
|
||||
{
|
||||
GuiGrid((Rectangle){0, 0, WINDOW_WIDTH, WINDOW_HEIGHT}, "", WINDOW_HEIGHT / 8, 2);
|
||||
auto signal = synth.GetOutSignal();
|
||||
@@ -158,8 +158,10 @@ void Renderer::DrawMainPanel(const Rectangle& panel_bounds)
|
||||
bool is_shape_dropdown_open = false;
|
||||
int shape_index = 0;
|
||||
GuiPanel(panel_bounds, "");
|
||||
}
|
||||
|
||||
/**/
|
||||
void Renderer::DrawAddOscillatorButton(Synth & synth, SynthGuiState & synthGui, Rectangle panel_bounds)
|
||||
{
|
||||
bool click_add_oscillator = GuiButton((Rectangle){
|
||||
panel_bounds.x + 10,
|
||||
panel_bounds.y + 10,
|
||||
@@ -168,24 +170,27 @@ void Renderer::DrawMainPanel(const Rectangle& panel_bounds)
|
||||
}, "Add Oscillator");
|
||||
if (click_add_oscillator)
|
||||
{
|
||||
// synth->ui_oscillator_count += 1;
|
||||
// // Set defaults:
|
||||
// UiOscillator *ui_osc = synth->ui_oscillator + (synth->ui_oscillator_count - 1);
|
||||
// ui_osc->shape = WaveShape_SINE;
|
||||
// ui_osc->freq = BASE_NOTE_FREQ;
|
||||
// ui_osc->amplitude_ratio = 0.1f;
|
||||
// ui_osc->shape_parameter_0 = 0.5f;
|
||||
synth.AddOscillator();
|
||||
Oscillator* osc = synth.GetOscillators().back();
|
||||
|
||||
OscillatorGuiState* ui = new OscillatorGuiState {
|
||||
.freq = osc->GetFreq(),
|
||||
.waveshape = osc->GetType(),
|
||||
.volume = osc->GetVolume()
|
||||
};
|
||||
synthGui.oscillators.push_back(ui);
|
||||
}
|
||||
}
|
||||
|
||||
void Renderer::DrawUi(Synth & synth, const SynthGuiState & synthGui)
|
||||
void Renderer::DrawUi(Synth & synth, SynthGuiState & synthGui)
|
||||
{
|
||||
Rectangle panel_bounds = {.x = 0, .y = 0, .width = OSCILLATOR_PANEL_WIDTH, .height = WINDOW_HEIGHT };
|
||||
DrawMainPanel(panel_bounds);
|
||||
|
||||
DrawAddOscillatorButton(synth, synthGui, panel_bounds);
|
||||
// Draw Oscillators
|
||||
std::vector<Oscillator*> oscillators = synth.GetOscillators();
|
||||
std::vector<OscillatorGuiState*> guiOscillators = synthGui.oscillators;
|
||||
|
||||
DrawOscillatorsPanels(oscillators, guiOscillators, panel_bounds);
|
||||
DrawOscillatorsShapeInputs(oscillators, guiOscillators);
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
Synth::Synth(/* args */)
|
||||
{
|
||||
m_oscillators.push_back(new Oscillator(OscillatorType::Sine, 440.f, VOLUME));
|
||||
AddOscillator();
|
||||
}
|
||||
|
||||
Synth::~Synth()
|
||||
@@ -26,8 +26,14 @@ std::vector<float> & Synth::get_note(int semitone, float beats)
|
||||
return m_adder.SumOscillators(m_oscillators, duration); //todo: add other pipeline steps (e.g ADSR, Filters, FX);
|
||||
}
|
||||
|
||||
void Synth::ProduceNoteSound(Note input) {
|
||||
void Synth::ProduceNoteSound(Note input)
|
||||
{
|
||||
float length = 1.f / input.length;
|
||||
int semitone_shift = KeyBoard::GetSemitoneShift(input.name);
|
||||
m_out_signal = get_note(semitone_shift, length);
|
||||
}
|
||||
|
||||
void Synth::AddOscillator()
|
||||
{
|
||||
m_oscillators.push_back(new Oscillator(OscillatorType::Sine, 440.f, VOLUME));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user