From de31b73673d0829845f3b77c006eee70300837b4 Mon Sep 17 00:00:00 2001 From: HiveBeats Date: Tue, 5 Sep 2023 03:15:08 +0400 Subject: [PATCH] fix: apply format --- inc/ADSR.h | 7 ++--- inc/Adder.h | 12 ++++----- inc/Effect.h | 2 +- inc/Ramp.h | 9 +++---- inc/Renderer.h | 2 +- inc/Settings.h | 2 +- src/ADSR.cpp | 65 +++++++++++++++++++-------------------------- src/Application.cpp | 28 ++++++++++--------- src/Ramp.cpp | 10 +++---- src/Renderer.cpp | 26 +++++++++--------- src/Synth.cpp | 2 +- 11 files changed, 77 insertions(+), 88 deletions(-) diff --git a/inc/ADSR.h b/inc/ADSR.h index 77a7588..3741bb3 100644 --- a/inc/ADSR.h +++ b/inc/ADSR.h @@ -1,7 +1,7 @@ #pragma once #include "Effect.h" -#include #include "Ramp.h" +#include struct ADSRParameters { float attack_time; // Attack time in seconds @@ -16,20 +16,21 @@ class ADSR : public Effect { private: ADSRParameters m_parameters; ADSRState m_state; - Ramp *m_ramp; + Ramp* m_ramp; void process_sample(float* sample); bool is_attack_elapsed(); bool is_decay_elapsed(); bool is_release_elapsed(); void recheck_state(); + public: ADSR(/* args */); ADSR(ADSRParameters param); ~ADSR(); void OnSetNote() override; void OnUnsetNote() override; - //void RetriggerState() override; + // void RetriggerState() override; void Process(std::vector& samples) override; void Reset(); }; diff --git a/inc/Adder.h b/inc/Adder.h index e951ab8..d3bd044 100644 --- a/inc/Adder.h +++ b/inc/Adder.h @@ -6,13 +6,13 @@ #include struct Adder { - static void - SumOscillators(const std::vector& oscillators, - std::vector& signal) { - size_t sample_count = STREAM_BUFFER_SIZE;//(size_t)(1.f/FPS * SAMPLE_RATE); + static void SumOscillators(const std::vector& oscillators, + std::vector& signal) { + size_t sample_count = + STREAM_BUFFER_SIZE; //(size_t)(1.f/FPS * SAMPLE_RATE); - //std::vector* output = new std::vector(); - //output->reserve(sample_count); + // std::vector* output = new std::vector(); + // output->reserve(sample_count); for (size_t i = 0; i < sample_count; i++) { float sample = 0.0f; diff --git a/inc/Effect.h b/inc/Effect.h index 726f033..c35ce24 100644 --- a/inc/Effect.h +++ b/inc/Effect.h @@ -8,6 +8,6 @@ class Effect { ~Effect(){}; virtual void OnSetNote(){}; virtual void OnUnsetNote(){}; - //virtual void RetriggerState(){}; + // virtual void RetriggerState(){}; virtual void Process(std::vector& samples){}; }; diff --git a/inc/Ramp.h b/inc/Ramp.h index f9ace72..9a98de5 100644 --- a/inc/Ramp.h +++ b/inc/Ramp.h @@ -1,17 +1,16 @@ #pragma once -class Ramp -{ -private: +class Ramp { + private: float m_level; float m_sample_rate; float m_increment; int m_counter; -public: + + public: Ramp(float starting_level, float sample_rate); ~Ramp(); void RampTo(float value, float time); float Process(); bool IsCompleted(); }; - diff --git a/inc/Renderer.h b/inc/Renderer.h index 8140114..0b59ec7 100644 --- a/inc/Renderer.h +++ b/inc/Renderer.h @@ -8,7 +8,7 @@ class Renderer { private: void draw_main_panel(const Rectangle& panel_bounds); void draw_add_oscillator_button(Synth& synth, SynthGuiState& synth_gui, - Rectangle panel_bounds); + Rectangle panel_bounds); void draw_oscillators_panels( const std::vector& oscillators, const std::vector& gui_oscillators, diff --git a/inc/Settings.h b/inc/Settings.h index a6fc760..4d8c0ad 100644 --- a/inc/Settings.h +++ b/inc/Settings.h @@ -2,7 +2,7 @@ #define SAMPLE_RATE 44100.f #define BPM 120.f -#define BEAT_DURATION 60.f/BPM +#define BEAT_DURATION 60.f / BPM #define PITCH_STANDARD 440.f #define VOLUME 0.5f #define ATTACK_MS 100.f diff --git a/src/ADSR.cpp b/src/ADSR.cpp index 6fc3113..6a898a7 100644 --- a/src/ADSR.cpp +++ b/src/ADSR.cpp @@ -1,6 +1,6 @@ #include "ADSR.h" -#include "Settings.h" #include "Logger.h" +#include "Settings.h" ADSR::ADSR(/* args */) { m_parameters.attack_time = 1.f; @@ -10,13 +10,9 @@ ADSR::ADSR(/* args */) { m_ramp = new Ramp(0, SAMPLE_RATE); } -ADSR::ADSR(ADSRParameters param) { - m_parameters = param; -} +ADSR::ADSR(ADSRParameters param) { m_parameters = param; } -ADSR::~ADSR() { - delete m_ramp; -} +ADSR::~ADSR() { delete m_ramp; } bool ADSR::is_attack_elapsed() { return m_state == Attack && m_ramp->IsCompleted(); @@ -31,43 +27,39 @@ bool ADSR::is_release_elapsed() { } void ADSR::recheck_state() { - switch (m_state) - { - case Attack: - if (is_attack_elapsed()) { - m_state = Decay; - m_ramp->RampTo(m_parameters.sustain_level, m_parameters.decay_time); - } - break; - case Decay: - if (is_decay_elapsed()) { - m_state = Sustain; - } - break; - case Release: - if (is_release_elapsed()) { - m_state = Off; - } - break; - default: - break; + switch (m_state) { + case Attack: + if (is_attack_elapsed()) { + m_state = Decay; + m_ramp->RampTo(m_parameters.sustain_level, + m_parameters.decay_time); + } + break; + case Decay: + if (is_decay_elapsed()) { + m_state = Sustain; + } + break; + case Release: + if (is_release_elapsed()) { + m_state = Off; + } + break; + default: + break; } } void ADSR::process_sample(float* sample) { if (m_state == Off) { (*sample) = 0; - } - else if (m_state == Attack) { + } else if (m_state == Attack) { (*sample) = (*sample) * m_ramp->Process(); - } - else if (m_state == Decay) { + } else if (m_state == Decay) { (*sample) = (*sample) * m_ramp->Process(); - } - else if (m_state == Sustain) { + } else if (m_state == Sustain) { (*sample) = (*sample) * m_parameters.sustain_level; - } - else if (m_state == Release) { + } else if (m_state == Release) { (*sample) = (*sample) * m_ramp->Process(); } } @@ -76,8 +68,7 @@ void ADSR::OnSetNote() { write_log("Set ADSR\n"); if (m_state == Off) { m_state = Attack; - } - else if (m_state == Release) { + } else if (m_state == Release) { m_state = Attack; }; diff --git a/src/Application.cpp b/src/Application.cpp index 61ec30e..4936cb4 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -86,23 +86,22 @@ bool Application::detect_note_pressed(Note* note) { } bool is_note_up() { - return IsKeyReleased(KEY_A) || IsKeyReleased(KEY_B) || IsKeyReleased(KEY_C) - || IsKeyReleased(KEY_D) || IsKeyReleased(KEY_E) || IsKeyReleased(KEY_F) - || IsKeyReleased(KEY_G); + return IsKeyReleased(KEY_A) || IsKeyReleased(KEY_B) || + IsKeyReleased(KEY_C) || IsKeyReleased(KEY_D) || + IsKeyReleased(KEY_E) || IsKeyReleased(KEY_F) || IsKeyReleased(KEY_G); } // Update On Input void Application::update_on_note_input() { if (detect_note_pressed(m_current_note)) { - - if (!m_synth.GetIsNoteTriggered()){ + + if (!m_synth.GetIsNoteTriggered()) { m_synth.TriggerNote((*m_current_note)); } - - //m_sound_played_count = 0; + + // m_sound_played_count = 0; write_log("Note played: %s\n", m_current_note->name.c_str()); - } - else if (is_note_up() && m_synth.GetIsNoteTriggered()) { + } else if (is_note_up() && m_synth.GetIsNoteTriggered()) { m_synth.StopSound(); } // will produce 0 signal if ADSR is in off state @@ -112,11 +111,14 @@ void Application::update_on_note_input() { // Play ring-buffered audio void Application::play_buffered_audio() { if (IsAudioStreamProcessed(m_synth_stream)) { - //const float audio_frame_start_time = GetTime(); + // const float audio_frame_start_time = GetTime(); update_on_note_input(); - UpdateAudioStream(m_synth_stream, m_synth.GetOutSignal().data(), STREAM_BUFFER_SIZE); - //const float audio_freme_duration = GetTime() - audio_frame_start_time; - //write_log("Frame time: %.3f%% \n", 100.0f / ((1.0f / audio_freme_duration) / ((float)SAMPLE_RATE/STREAM_BUFFER_SIZE))); + UpdateAudioStream(m_synth_stream, m_synth.GetOutSignal().data(), + STREAM_BUFFER_SIZE); + // const float audio_freme_duration = GetTime() - + // audio_frame_start_time; write_log("Frame time: %.3f%% \n", 100.0f / + // ((1.0f / audio_freme_duration) / + // ((float)SAMPLE_RATE/STREAM_BUFFER_SIZE))); } } diff --git a/src/Ramp.cpp b/src/Ramp.cpp index 6c826e6..d93fb9e 100644 --- a/src/Ramp.cpp +++ b/src/Ramp.cpp @@ -6,13 +6,13 @@ Ramp::Ramp(float starting_level, float sample_rate) { m_sample_rate = sample_rate; } -Ramp::~Ramp() { -} +Ramp::~Ramp() {} void Ramp::RampTo(float val, float time) { m_increment = (val - m_level) / (m_sample_rate * time); m_counter = (int)(m_sample_rate * time); - write_log("Ramping from: %.1f to: %.1f by: %lf for: %d\n", m_level, val, m_increment, m_counter); + write_log("Ramping from: %.1f to: %.1f by: %lf for: %d\n", m_level, val, + m_increment, m_counter); } float Ramp::Process() { @@ -24,6 +24,4 @@ float Ramp::Process() { return m_level; } -bool Ramp::IsCompleted() { - return m_counter == 0; -} \ No newline at end of file +bool Ramp::IsCompleted() { return m_counter == 0; } \ No newline at end of file diff --git a/src/Renderer.cpp b/src/Renderer.cpp index 341221b..102bf9d 100644 --- a/src/Renderer.cpp +++ b/src/Renderer.cpp @@ -10,7 +10,6 @@ #include "raygui.h" #pragma clang diagnostic pop - Renderer::Renderer(/* args */) { InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "SeeSynth - v0.2"); SetTargetFPS(FPS); @@ -123,23 +122,21 @@ void Renderer::draw_oscillators_panels( // Defer shape drop-down box. ui_osc->shape_dropdown_rect = el_rect; el_rect.y += el_rect.height + el_spacing; - + Rectangle delete_button_rect = el_rect; delete_button_rect.x = osc_panel_x + 5; delete_button_rect.y -= el_rect.height + el_spacing; delete_button_rect.width = 30; bool is_delete_button_pressed = GuiButton(delete_button_rect, "X"); - if (is_delete_button_pressed) - { - // memmove( - // synth->ui_oscillator + ui_osc_i, - // synth->ui_oscillator + ui_osc_i + 1, - // (synth->ui_oscillator_count - ui_osc_i) * - // sizeof(UiOscillator) - // ); - // synth->ui_oscillator_count -= 1; + if (is_delete_button_pressed) { + // memmove( + // synth->ui_oscillator + ui_osc_i, + // synth->ui_oscillator + ui_osc_i + 1, + // (synth->ui_oscillator_count - ui_osc_i) * + // sizeof(UiOscillator) + // ); + // synth->ui_oscillator_count -= 1; } - } } @@ -149,8 +146,9 @@ void Renderer::draw_main_panel(const Rectangle& panel_bounds) { GuiPanel(panel_bounds, ""); } -void Renderer::draw_add_oscillator_button(Synth& synth, SynthGuiState& synth_gui, - Rectangle panel_bounds) { +void Renderer::draw_add_oscillator_button(Synth& synth, + SynthGuiState& synth_gui, + Rectangle panel_bounds) { //clang-format off bool click_add_oscillator = GuiButton((Rectangle){panel_bounds.x + 10, panel_bounds.y + 10, diff --git a/src/Synth.cpp b/src/Synth.cpp index 15888f2..30de536 100644 --- a/src/Synth.cpp +++ b/src/Synth.cpp @@ -1,9 +1,9 @@ #include "Synth.h" #include "ADSR.h" #include "KeyBoard.h" +#include "Logger.h" #include "OscillatorType.h" #include "Settings.h" -#include "Logger.h" Synth::Synth(/* args */) { AddOscillator();