X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fsequencer.h;h=d2a786987e8d58cd43a6d2b1b1bc83e2f7132884;hb=eab0e547df149ba6972ee2a2b3435e37a4fc0a0c;hp=e6eb2b7849381a4f4ad2f4a6196c71610040d186;hpb=8ffa42fba0e6a13286b465473fd399cac7c77dcf;p=libs%2Fdemoscene.git diff --git a/source/sequencer.h b/source/sequencer.h index e6eb2b7..d2a7869 100644 --- a/source/sequencer.h +++ b/source/sequencer.h @@ -3,14 +3,67 @@ #include #include +#include +#include +#include +#include #include #include +#include "action.h" -class Action; +namespace Msp { +namespace DemoScene { + +class Demo; class Sequencer { +public: + class Loader: public Msp::DataFile::ObjectLoader + { + private: + Demo &demo; + float base_beat; + + public: + Loader(Sequencer &, Demo &); + + private: + void base(float); + void define_action(const std::string &); + void instant(float); + void repeat(float, float, unsigned); + void segment(float, float); + }; + private: + class ActionDefLoader: public Msp::DataFile::ObjectLoader + { + protected: + template + struct AddAction + { + static void add(ActionDefLoader &ldr, const std::string &kw) { ldr.add(kw, &ActionDefLoader::action_def); } + }; + + Demo &demo; + Msp::RefPtr action; + + public: + ActionDefLoader(Sequencer &, Demo &); + + Action *get_action() { return action.release(); } + + protected: + virtual void action_loaded() { } + + private: + template + void action_def(); + + friend class Sequencer; + }; + struct Segment { Action *action; @@ -18,10 +71,29 @@ private: float end_beat; }; + class SegmentLoader: public ActionDefLoader + { + private: + float start_beat; + float end_beat; + + public: + SegmentLoader(Sequencer &, float, float, Demo &); + + private: + virtual void action_loaded(); + + void apply(const std::string &); + }; + public: sigc::signal signal_finished; private: + DataFile::LoadableTypeRegistry action_registry; + std::map named_actions; + std::vector anonymous_actions; + Msp::Time::TimeDelta secs_per_beat; std::vector static_actions; std::vector segments; @@ -34,6 +106,10 @@ private: public: Sequencer(float = 120.0f); + template + void register_action_type(const std::string &); + void define_action(const std::string &, Action &); + void set_beats_per_minute(float); float get_beats_per_minute() const { return Msp::Time::min/secs_per_beat; } void add_static_action(Action &); @@ -49,4 +125,26 @@ public: float get_current_beat() const { return beat; } }; +template +inline void Sequencer::register_action_type(const std::string &n) +{ + action_registry.register_type(n); +} + +template +void Sequencer::ActionDefLoader::action_def() +{ + if(action) + throw std::runtime_error("Only one action per definition is allowed"); + + Msp::RefPtr act = new T; + load_sub(*act, demo); + act->validate(); + action = act.release(); + action_loaded(); +} + +} // namespace DemoScene +} // namespace Msp + #endif