[refactor]: c++ implementation #13
@@ -4,10 +4,13 @@
|
|||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
#include "RingBuffer.h"
|
#include "RingBuffer.h"
|
||||||
#include "Renderer.h"
|
#include "Renderer.h"
|
||||||
|
#include "SynthGuiState.h"
|
||||||
|
|
||||||
class Application
|
class Application
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
Synth m_synth;
|
Synth m_synth;
|
||||||
|
SynthGuiState m_synth_gui_state;
|
||||||
RingBuffer<float>* m_ring_buffer;
|
RingBuffer<float>* m_ring_buffer;
|
||||||
AudioStream m_synth_stream;
|
AudioStream m_synth_stream;
|
||||||
int m_sound_played_count;
|
int m_sound_played_count;
|
||||||
|
|||||||
@@ -1,13 +1,15 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include "Synth.h"
|
||||||
|
#include "SynthGuiState.h"
|
||||||
class Renderer
|
class Renderer
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
/* data */
|
void DrawUi(Synth & synth, const SynthGuiState & synthGui);
|
||||||
|
void DrawSignal(Synth & synth, const SynthGuiState & synthGui);
|
||||||
public:
|
public:
|
||||||
Renderer(/* args */);
|
Renderer(/* args */);
|
||||||
~Renderer();
|
~Renderer();
|
||||||
void Draw();
|
void Draw(Synth& synth, const SynthGuiState & synthGui);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -21,4 +21,5 @@ public:
|
|||||||
~Synth();
|
~Synth();
|
||||||
void ProduceNoteSound(Note input);
|
void ProduceNoteSound(Note input);
|
||||||
const std::vector<float> & GetOutSignal() { return m_out_signal; }
|
const std::vector<float> & GetOutSignal() { return m_out_signal; }
|
||||||
|
const std::vector<Oscillator*>& GetOscillators() { return m_oscillators; }
|
||||||
};
|
};
|
||||||
16
inc/SynthGuiState.h
Normal file
16
inc/SynthGuiState.h
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "OscillatorType.h"
|
||||||
|
#include "raygui.h"
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
struct OscillatorGuiState {
|
||||||
|
float volume;
|
||||||
|
float freq;//todo: remove or change to pitch shift
|
||||||
|
OscillatorType waveshape;
|
||||||
|
bool is_dropdown_open;
|
||||||
|
Rectangle shape_dropdown_rect;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SynthGuiState {
|
||||||
|
std::vector<OscillatorGuiState> oscillators;
|
||||||
|
};
|
||||||
@@ -45,16 +45,20 @@ void Application::init_synth()
|
|||||||
};
|
};
|
||||||
|
|
||||||
//todo: move somewhere in initialization
|
//todo: move somewhere in initialization
|
||||||
// synth.ui_oscillators = malloc(sizeof(OscillatorUI) * synth.oscillators.count);
|
std::vector<Oscillator*> oscillators = m_synth.GetOscillators();
|
||||||
// for (size_t i = 0; i < synth.oscillators.count; i++)
|
m_synth_gui_state.oscillators.reserve(oscillators.size());
|
||||||
// {
|
for (size_t i = 0; i < oscillators.size(); i++)
|
||||||
// OscillatorUI* ui = &synth.ui_oscillators[i];
|
{
|
||||||
// assert(ui);
|
Oscillator* osc = oscillators[i];
|
||||||
|
assert(osc);
|
||||||
|
|
||||||
// ui->freq = synth.oscillators.array[i].freq;
|
OscillatorGuiState ui = {
|
||||||
// ui->waveshape = synth.oscillators.array[i].osc;
|
.freq = osc->GetFreq(),
|
||||||
// ui->volume = synth.oscillators.array[i].volume;
|
.waveshape = osc->GetType(),
|
||||||
// }
|
.volume = osc->GetVolume()
|
||||||
|
};
|
||||||
|
m_synth_gui_state.oscillators.push_back(ui);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::size_t Application::detect_note_pressed(Note* note)
|
std::size_t Application::detect_note_pressed(Note* note)
|
||||||
@@ -171,6 +175,6 @@ void Application::Run()
|
|||||||
play_buffered_audio();
|
play_buffered_audio();
|
||||||
update_on_note_input();
|
update_on_note_input();
|
||||||
|
|
||||||
m_renderer.Draw();
|
m_renderer.Draw(m_synth, m_synth_gui_state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include "Renderer.h"
|
#include "Renderer.h"
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
|
#define RAYGUI_IMPLEMENTATION
|
||||||
#include "raygui.h"
|
#include "raygui.h"
|
||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
|
|
||||||
@@ -13,16 +14,36 @@ Renderer::~Renderer()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::Draw()
|
void Renderer::Draw(Synth& synth, const SynthGuiState& synthGui)
|
||||||
{
|
{
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
|
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
//todo: implement renderer
|
//todo: implement renderer
|
||||||
//DrawUi(&synth);
|
DrawUi(synth, synthGui);
|
||||||
//DrawSignal(&synth);
|
DrawSignal(synth, synthGui);
|
||||||
//DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);
|
//DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);
|
||||||
//DrawFPS(0,0);
|
//DrawFPS(0,0);
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Renderer::DrawSignal(Synth & synth, const SynthGuiState & synthGui)
|
||||||
|
{
|
||||||
|
GuiGrid((Rectangle){0, 0, WINDOW_WIDTH, WINDOW_HEIGHT}, "", WINDOW_HEIGHT / 8, 2);
|
||||||
|
auto signal = synth.GetOutSignal();
|
||||||
|
Vector2* signal_points = new Vector2[signal.size()];
|
||||||
|
const float screen_vertical_midpoint = (WINDOW_HEIGHT/2);
|
||||||
|
for (int point_idx = 0; point_idx < signal.size(); point_idx++)
|
||||||
|
{
|
||||||
|
signal_points[point_idx].x = (float)point_idx + OSCILLATOR_PANEL_WIDTH;
|
||||||
|
signal_points[point_idx].y = screen_vertical_midpoint + (int)(signal[point_idx] * 300);
|
||||||
|
}
|
||||||
|
DrawLineStrip(signal_points, signal.size(), RED);
|
||||||
|
delete[] signal_points;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Renderer::DrawUi(Synth & synth, const SynthGuiState & synthGui)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user