Browse Source

move midiclock into own module

main
heck 7 months ago
parent
commit
9c019c9b2d
  1. 58
      src/main_perkons.cc
  2. 54
      src/midiclock.cc
  3. 24
      src/midiclock.hh

58
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<Track, Constants::TRACK_COUNT> 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()

54
src/midiclock.cc

@ -0,0 +1,54 @@
#include "midiclock.hh"
#include <cmath>
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

24
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
Loading…
Cancel
Save