EventList.h 866 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #ifndef SEKAI_EVENTLIST_H
  2. #define SEKAI_EVENTLIST_H
  3. #include <math.h>
  4. class VoiceDef;
  5. #define MAX_POINTS 64
  6. struct PhoEvent {
  7. struct PhoEvent* next;
  8. VoiceDef* voice;
  9. int points;
  10. float x[MAX_POINTS];
  11. float y[MAX_POINTS];
  12. // needed for eventList
  13. inline float start() { return x[0]; }
  14. inline float end() { return x[points - 1]; }
  15. };
  16. template <typename T>
  17. class EventList {
  18. public:
  19. void addEvent(T* n) {
  20. n->next = nullptr;
  21. if (_head == nullptr) {
  22. _head = n;
  23. _root = n;
  24. }
  25. if (_tail) {
  26. _tail->next = n;
  27. }
  28. _tail = n;
  29. }
  30. T* current() { return _head; }
  31. T* next() { return _head ? _head->next : nullptr; }
  32. void selectNext(float currentTime) {
  33. if (_head && currentTime >= _head->end()) _head = _head->next;
  34. }
  35. private:
  36. T* _head = nullptr;
  37. T* _root = nullptr;
  38. T* _tail = nullptr;
  39. };
  40. #endif