]> git.tdb.fi Git - libs/demoscene.git/blob - source/sequencer.h
028c5d5161d5094ffb92bbd0f59b333ecfbabd6b
[libs/demoscene.git] / source / sequencer.h
1 #ifndef MSP_DEMOSCENE_SEQUENCER_H_
2 #define MSP_DEMOSCENE_SEQUENCER_H_
3
4 #include <vector>
5 #include <sigc++/signal.h>
6 #include <msp/time/timedelta.h>
7 #include <msp/time/timestamp.h>
8
9 class Sequencer
10 {
11 public:
12         class Action
13         {
14         protected:
15                 Action() { }
16         public:
17                 virtual ~Action() { }
18
19                 virtual void start(float, float) { }
20                 virtual void beat(int) { }
21                 virtual void tick(float, float) { }
22                 virtual void end(float) { }
23         };
24
25         class InterpolationAction: public Action
26         {
27         protected:
28                 bool hermite;
29                 float start_beat;
30                 float duration;
31
32                 InterpolationAction(bool = false);
33
34         public:
35                 virtual void start(float, float);
36                 virtual void tick(float, float);
37                 virtual void end(float);
38                 virtual void interpolate(float, float) { }
39         };
40
41 private:
42         struct Segment
43         {
44                 Action *action;
45                 float start_beat;
46                 float end_beat;
47         };
48
49 public:
50         sigc::signal<void> signal_finished;
51
52 private:
53         Msp::Time::TimeDelta secs_per_beat;
54         std::vector<Action *> static_actions;
55         std::vector<Segment> segments;
56         std::vector<Segment>::const_iterator begin;
57         std::vector<Segment>::const_iterator end;
58         bool started;
59         float beat;
60         float next_event;
61
62 public:
63         Sequencer(float = 120.0f);
64
65         void set_beats_per_minute(float);
66         float get_beats_per_minute() const { return Msp::Time::min/secs_per_beat; }
67         void add_static_action(Action &);
68         void add_action(Action &, float, float);
69
70         void start();
71         void seek(float);
72         void tick(const Msp::Time::TimeDelta &);
73 private:
74         void advance_to(float);
75         void update_next_event();
76 public:
77         float get_current_beat() const { return beat; }
78 };
79
80 #endif