1 #ifndef MSP_DEMOSCENE_SEQUENCER_H_
2 #define MSP_DEMOSCENE_SEQUENCER_H_
5 #include <sigc++/signal.h>
6 #include <msp/core/maputils.h>
7 #include <msp/core/refptr.h>
8 #include <msp/datafile/objectloader.h>
9 #include <msp/time/timedelta.h>
10 #include <msp/time/timestamp.h>
18 class Loader: public Msp::DataFile::ObjectLoader<Sequencer>
24 Loader(Sequencer &, Demo &);
27 void define_action(const std::string &);
29 void segment(float, float);
33 class ActionDefLoader;
35 class RegisteredAction
38 typedef void (ActionDefLoader::*LoaderFunc)();
40 virtual ~RegisteredAction() { }
41 virtual LoaderFunc get_loader_func() const = 0;
45 class RegisteredActionType: public RegisteredAction
48 virtual LoaderFunc get_loader_func() const;
51 class ActionDefLoader: public Msp::DataFile::ObjectLoader<Sequencer>
55 Msp::RefPtr<Action> action;
58 ActionDefLoader(Sequencer &, Demo &);
60 Action *get_action() { return action.release(); }
63 virtual void finished();
69 friend class RegisteredActionType;
79 class SegmentLoader: public Msp::DataFile::ObjectLoader<Sequencer>
86 SegmentLoader(Sequencer &, float, float);
89 void apply(const std::string &);
93 sigc::signal<void> signal_finished;
96 std::map<std::string, RegisteredAction *> action_types;
97 std::map<std::string, Action *> named_actions;
99 Msp::Time::TimeDelta secs_per_beat;
100 std::vector<Action *> static_actions;
101 std::vector<Segment> segments;
102 std::vector<Segment>::const_iterator begin;
103 std::vector<Segment>::const_iterator end;
109 Sequencer(float = 120.0f);
112 void register_action_type(const std::string &);
114 void set_beats_per_minute(float);
115 float get_beats_per_minute() const { return Msp::Time::min/secs_per_beat; }
116 void add_static_action(Action &);
117 void add_action(Action &, float, float);
121 void tick(const Msp::Time::TimeDelta &);
123 void advance_to(float);
124 void update_next_event();
126 float get_current_beat() const { return beat; }
130 inline void Sequencer::register_action_type(const std::string &n)
132 if(action_types.count(n))
133 throw Msp::key_error(n);
135 action_types[n] = new RegisteredActionType<T>;
139 Sequencer::RegisteredAction::LoaderFunc Sequencer::RegisteredActionType<T>::get_loader_func() const
141 return &ActionDefLoader::action_def<T>;
145 void Sequencer::ActionDefLoader::action_def()
148 throw std::runtime_error("Only one action per definition is allowed");
150 Msp::RefPtr<T> act = new T;
151 load_sub(*act, demo);