|
@@ -2,6 +2,8 @@
|
|
|
#include <thread>
|
|
|
#include <mutex>
|
|
|
#include <chrono>
|
|
|
+#include <vector>
|
|
|
+#include "Bar.h"
|
|
|
|
|
|
class Loop
|
|
|
{
|
|
@@ -12,10 +14,16 @@ class Loop
|
|
|
bool stopNext;
|
|
|
|
|
|
public:
|
|
|
+
|
|
|
bool enabled;
|
|
|
+ unsigned short currentBarIndex;
|
|
|
+ unsigned short currentBeatIndex;
|
|
|
+ std::vector<Bar> bars;
|
|
|
|
|
|
Loop()
|
|
|
- : bpm(60), stopNext(false), enabled(false), loopThread(&Loop::loop, this)
|
|
|
+ : bpm(60), stopNext(false), enabled(false),
|
|
|
+ currentBarIndex(0), currentBeatIndex(0), lastBeatTime(0),
|
|
|
+ loopThread(&Loop::loop, this)
|
|
|
{
|
|
|
}
|
|
|
|
|
@@ -58,6 +66,7 @@ public:
|
|
|
}
|
|
|
|
|
|
private:
|
|
|
+
|
|
|
std::chrono::milliseconds getMillisecondsSinceEpoch()
|
|
|
{
|
|
|
std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
|
|
@@ -68,13 +77,23 @@ private:
|
|
|
void beat()
|
|
|
{
|
|
|
std::cout << "\a" << lastBeatTime.count() << std::endl;
|
|
|
+ if(bars.size() > 0) {
|
|
|
+ if(currentBarIndex >= bars.size()) {
|
|
|
+ currentBarIndex = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ std::cout << "trigger bar#" << currentBarIndex << std::endl;
|
|
|
+
|
|
|
+ currentBarIndex++;
|
|
|
+ }
|
|
|
+
|
|
|
+ lastBeatTime = getMillisecondsSinceEpoch();
|
|
|
}
|
|
|
|
|
|
void loop()
|
|
|
{
|
|
|
while(!stopNext) {
|
|
|
- if((getMillisecondsSinceEpoch() - lastBeatTime) >= getBeatDuration()) {
|
|
|
- lastBeatTime = getMillisecondsSinceEpoch();
|
|
|
+ if(enabled && (getMillisecondsSinceEpoch() - lastBeatTime) >= getBeatDuration()) {
|
|
|
beat();
|
|
|
}
|
|
|
}
|