BeatSequencePlayer.h 1011 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #pragma once
  2. #include <mutex>
  3. #include "Output.h"
  4. #include "BeatSequence.h"
  5. #include "CallbackClock.h"
  6. namespace midi {
  7. class BeatSequencePlayer
  8. {
  9. public:
  10. typedef BeatSequence::BeatIndex BeatIndex;
  11. typedef CallbackClock::bpm_type Bpm;
  12. private:
  13. bool looping;
  14. std::mutex looping_mutex;
  15. BeatIndex nextBeat;
  16. std::mutex nextBeat_mutex;
  17. CallbackClock clock;
  18. Output* output;
  19. public:
  20. const BeatSequence* sequence;
  21. BeatSequencePlayer();
  22. BeatSequencePlayer(Output* output);
  23. BeatSequencePlayer(Output* output, const BeatSequence* sequence);
  24. Bpm getBpm();
  25. void setBpm(Bpm bpm);
  26. bool getLooping();
  27. void setLooping(bool looping);
  28. BeatIndex getNextBeat();
  29. void setNextBeat(BeatIndex nextBeat);
  30. void play();
  31. void loop();
  32. void start();
  33. void stop();
  34. bool isPlaying();
  35. protected:
  36. virtual void beforeBeat(BeatIndex beat);
  37. virtual void afterBeat(BeatIndex beat);
  38. private:
  39. static void beat(void* data);
  40. };
  41. } // namespace