
3 changed files with 79 additions and 57 deletions
@ -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
|
@ -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…
Reference in new issue