sequence.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. //PORTABLE
  2. #ifndef _SEQUENCE_H
  3. #define _SEQUENCE_H
  4. #include <bfc/dispatch.h>
  5. #include <bfc/depend.h>
  6. // abstracted version of a playback order
  7. class ItemSequencer : public Dispatchable {
  8. public:
  9. api_dependent *getDependencyPtr();
  10. const char *getNextPlayItem();
  11. int getCurrentPlaybackNumber(); // 0-based, -1 if you don't know
  12. int getNumItems(); // -1 if you don't know
  13. int rewind();
  14. int forward();
  15. int onNotify(int msg, int param1=0, int param2=0);
  16. protected:
  17. enum {
  18. GETNEXTPLAYITEM=100,
  19. GETCURRENTPLAYBACKNUMBER=101,
  20. GETNUMITEMS=102,
  21. REWIND=200,
  22. FORWARD=210,
  23. ONNOTIFY=300,
  24. GETDEPENDENCYPTR=400,
  25. };
  26. };
  27. inline api_dependent *ItemSequencer::getDependencyPtr() {
  28. return _call(GETDEPENDENCYPTR, (api_dependent*)NULL);
  29. }
  30. inline const char *ItemSequencer::getNextPlayItem() {
  31. return _call(GETNEXTPLAYITEM, (const char *)NULL);
  32. }
  33. inline
  34. int ItemSequencer::getCurrentPlaybackNumber() {
  35. return _call(GETCURRENTPLAYBACKNUMBER, -1);
  36. }
  37. inline
  38. int ItemSequencer::getNumItems() {
  39. return _call(GETNUMITEMS, -1);
  40. }
  41. inline int ItemSequencer::rewind() {
  42. return _call(REWIND, 0);
  43. }
  44. inline int ItemSequencer::forward() {
  45. return _call(FORWARD, 0);
  46. }
  47. inline int ItemSequencer::onNotify(int msg, int param1, int param2) {
  48. return _call(ONNOTIFY, 0, msg, param1, param2);
  49. }
  50. #define SEQNOTIFY_ONREGISTER 10
  51. #define SEQNOTIFY_ONDEREGISTER 20
  52. #define SEQNOTIFY_ONNEXTFILE 30
  53. #define SEQNOTIFY_ONTITLECHANGE 40
  54. #define SEQNOTIFY_ONSTARTED 50
  55. #define SEQNOTIFY_ONSTOPPED 60
  56. #define SEQNOTIFY_ONPAUSED 70
  57. #define SEQNOTIFY_ONUNPAUSED 80
  58. // override this one
  59. class ItemSequencerI : public ItemSequencer, public DependentI {
  60. public:
  61. api_dependent *getDependencyPtr() { return this; }
  62. virtual int rewind()=0;
  63. virtual int forward()=0;
  64. virtual const char *getNextPlayItem()=0;
  65. virtual int getCurrentPlaybackNumber() { return -1; }
  66. virtual int getNumItems() { return -1; }
  67. // these are optional callbacks
  68. virtual int onRegister() { return 0; };
  69. virtual int onDeregister() { return 0; };
  70. virtual int onNextFile() { return 0; }// on transition
  71. virtual int onTitleChange() { return 0; }
  72. virtual int onStarted() { return 0; }
  73. virtual int onStopped() { return 0; }
  74. virtual int onPaused() { return 0; }
  75. virtual int onUnpaused() { return 0; }
  76. protected:
  77. // default implementation calls above callback methods based on msg
  78. virtual int onNotify(int msg, int param1, int param2);
  79. RECVS_DISPATCH;
  80. };
  81. // also somewhat abstract, but implements playing through some arbitrary
  82. // list. just override the protected stuff
  83. class ListSequencer : public ItemSequencerI {
  84. public:
  85. virtual const char *getNextPlayItem();
  86. virtual int rewind();
  87. virtual int forward();
  88. protected:
  89. // override these 4 only
  90. virtual int getNumEntries()=0;
  91. virtual const char *enumItem(int pos)=0;
  92. virtual int getCurrent()=0;
  93. virtual int setCurrent(int cur)=0;
  94. protected:
  95. virtual int loop() { return 0; } // override as necessary
  96. private:
  97. virtual int getNumItems(); // calls getNumEntries()
  98. };
  99. #endif