|
@@ -0,0 +1,89 @@
|
|
|
|
+#include "BeatSequencePlayer.h"
|
|
|
|
+#include <iostream>
|
|
|
|
+
|
|
|
|
+namespace midi {
|
|
|
|
+
|
|
|
|
+BeatSequencePlayer::BeatSequencePlayer()
|
|
|
|
+ : BeatSequencePlayer(0)
|
|
|
|
+{
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+BeatSequencePlayer::BeatSequencePlayer(const BeatSequence* seq)
|
|
|
|
+ : looping(false), nextBeat(0),
|
|
|
|
+ clock(&beat, (void*)this), sequence(seq)
|
|
|
|
+{
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+bool BeatSequencePlayer::getLooping()
|
|
|
|
+{
|
|
|
|
+ looping_mutex.lock();
|
|
|
|
+ bool l = looping;
|
|
|
|
+ looping_mutex.unlock();
|
|
|
|
+ return l;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void BeatSequencePlayer::setLooping(bool l)
|
|
|
|
+{
|
|
|
|
+ looping_mutex.lock();
|
|
|
|
+ looping = l;
|
|
|
|
+ looping_mutex.unlock();
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+BeatSequencePlayer::BeatIndex BeatSequencePlayer::getNextBeat()
|
|
|
|
+{
|
|
|
|
+ nextBeat_mutex.lock();
|
|
|
|
+ BeatIndex n = nextBeat;
|
|
|
|
+ nextBeat_mutex.unlock();
|
|
|
|
+ return n;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+BeatSequencePlayer::Bpm BeatSequencePlayer::getBpm()
|
|
|
|
+{
|
|
|
|
+ return clock.getBpm();
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void BeatSequencePlayer::setBpm(Bpm bpm)
|
|
|
|
+{
|
|
|
|
+ clock.setBpm(bpm);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void BeatSequencePlayer::setNextBeat(BeatIndex n)
|
|
|
|
+{
|
|
|
|
+ nextBeat_mutex.lock();
|
|
|
|
+ nextBeat = n;
|
|
|
|
+ nextBeat_mutex.unlock();
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void BeatSequencePlayer::play()
|
|
|
|
+{
|
|
|
|
+ setLooping(false);
|
|
|
|
+ start();
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void BeatSequencePlayer::loop()
|
|
|
|
+{
|
|
|
|
+ setLooping(true);
|
|
|
|
+ start();
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void BeatSequencePlayer::start()
|
|
|
|
+{
|
|
|
|
+ clock.start();
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void BeatSequencePlayer::stop()
|
|
|
|
+{
|
|
|
|
+ clock.stop();
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+bool BeatSequencePlayer::isPlaying()
|
|
|
|
+{
|
|
|
|
+ return clock.isRunning();
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void BeatSequencePlayer::beat(void* data)
|
|
|
|
+{
|
|
|
|
+ std::cout << "beat" << std::endl;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+} // namespace
|