You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
1.8KB

  1. #pragma once
  2. //#include "MidiEvent.h"
  3. //#include "MidiSong.h"
  4. #include "MidiTrack.h"
  5. #include <memory>
  6. class MidiSong;
  7. class MidiSequencer;
  8. /**
  9. * Abstract out the player host so that we can more
  10. * easily test the player.
  11. */
  12. class IPlayerHost
  13. {
  14. public:
  15. virtual void setGate(bool) = 0;
  16. virtual void setCV(float) = 0;
  17. virtual void onLockFailed() = 0;
  18. };
  19. class TrackPlayer
  20. {
  21. public:
  22. TrackPlayer(std::shared_ptr<MidiTrack> track);
  23. ~TrackPlayer();
  24. void reset()
  25. {
  26. isReset = true;
  27. }
  28. // void timeElapsed(float seconds);
  29. void updateToMetricTime(double seconds, IPlayerHost*);
  30. // void seekTo(MidiSong*, float time, IPlayerHost* host);
  31. private:
  32. double noteOffTime = -1;
  33. MidiTrack::const_iterator curEvent;
  34. bool isReset = true;
  35. std::shared_ptr<MidiTrack> track;
  36. double loopStart = 0;
  37. /**
  38. * process the next ready event that is after metricTime
  39. * returns true is something was found
  40. */
  41. bool playOnce(double metricTime, IPlayerHost* host);
  42. };
  43. /**
  44. * Need to decide on some units:
  45. *
  46. * Pitch = float volts (VCV standard).
  47. * Metric Time = float, quarter notes.
  48. * Tempo = float, BPM
  49. */
  50. class MidiPlayer
  51. {
  52. public:
  53. MidiPlayer(std::shared_ptr<IPlayerHost> host, std::shared_ptr<MidiSong> song);
  54. ~MidiPlayer()
  55. {
  56. --_mdb;
  57. }
  58. void timeElapsed(float seconds);
  59. std::shared_ptr<MidiSong> getSong()
  60. {
  61. return song;
  62. }
  63. void stop()
  64. {
  65. isPlaying = false;
  66. }
  67. private:
  68. std::shared_ptr<IPlayerHost> host;
  69. std::shared_ptr<MidiSong> song;
  70. /*
  71. float curMetricTime = 0;
  72. float noteOffTime = -1;
  73. MidiTrack::const_iterator curEvent;
  74. */
  75. double curMetricTime = 0;
  76. bool isPlaying = true;
  77. TrackPlayer trackPlayer;
  78. // bool playOnce();
  79. };