From 9c019c9b2dc9d416abde3f521497b4c1d073c712 Mon Sep 17 00:00:00 2001 From: heck Date: Fri, 13 Sep 2024 22:21:30 +0200 Subject: [PATCH] move midiclock into own module --- src/main_perkons.cc | 58 +-------------------------------------------- src/midiclock.cc | 54 +++++++++++++++++++++++++++++++++++++++++ src/midiclock.hh | 24 +++++++++++++++++++ 3 files changed, 79 insertions(+), 57 deletions(-) create mode 100644 src/midiclock.cc create mode 100644 src/midiclock.hh diff --git a/src/main_perkons.cc b/src/main_perkons.cc index c9b600f..5e5310a 100644 --- a/src/main_perkons.cc +++ b/src/main_perkons.cc @@ -5,6 +5,7 @@ #include "globals.hh" #include "track.hh" #include "utils.hh" +#include "midiclock.hh" #include "instr_abstract.hh" #include "instr_kick.hh" #include "instr_noise.hh" @@ -33,63 +34,6 @@ namespace Heck { std::array tracks; - struct MidiClock { - public: - void tick_advance() - { - if (enabled) { - time_inf++; - } - }; - - void reset() - { - time_inf = 0; - }; - - void enable(bool enabled) - { - this->enabled = enabled; - }; - - // get time - - int tick_infinite() - { - return time_inf; - } - - int tick_4n() - { - return time_inf % PPQ; - } - - int tick_1n() - { - return time_inf % (PPQ * 4); - } - - int count_8n() - { - return std::floor(tick_1n() / 12); - } - - int count_16n() - { - return std::floor(tick_1n() / 6); - } - - int count_bar() - { - return std::floor(time_inf / 96.); - } - - private: - static constexpr int PPQ = 24; - bool enabled{ true }; - int time_inf{ 0 }; - }; - struct Sequencer { Sequencer() diff --git a/src/midiclock.cc b/src/midiclock.cc new file mode 100644 index 0000000..9d88571 --- /dev/null +++ b/src/midiclock.cc @@ -0,0 +1,54 @@ +#include "midiclock.hh" +#include + +namespace Heck { + void MidiClock::tick_advance() + { + if (enabled) { + time_inf++; + } + }; + + void MidiClock::reset() + { + time_inf = 0; + }; + + void MidiClock::enable(bool enabled) + { + this->enabled = enabled; + }; + + // get time + + int MidiClock::tick_infinite() + { + return time_inf; + } + + int MidiClock::tick_4n() + { + return time_inf % PPQ; + } + + int MidiClock::tick_1n() + { + return time_inf % (PPQ * 4); + } + + int MidiClock::count_8n() + { + return std::floor(tick_1n() / 12); + } + + int MidiClock::count_16n() + { + return std::floor(tick_1n() / 6); + } + + int MidiClock::count_bar() + { + return std::floor(time_inf / 96.); + } + +}; // namespace Heck \ No newline at end of file diff --git a/src/midiclock.hh b/src/midiclock.hh new file mode 100644 index 0000000..cf2c28c --- /dev/null +++ b/src/midiclock.hh @@ -0,0 +1,24 @@ +#ifndef HECK_PERKONS_MIDICLOCK_HH +#define HECK_PERKONS_MIDICLOCK_HH + +namespace Heck { + struct MidiClock { + public: + void tick_advance(); + void reset(); + void enable(bool enabled); + int tick_infinite(); + int tick_4n(); + int tick_1n(); + int count_8n(); + int count_16n(); + int count_bar(); + + private: + static constexpr int PPQ = 24; + bool enabled{ true }; + int time_inf{ 0 }; + }; +} // namespace Heck + +#endif \ No newline at end of file