X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fsequencer.h;h=d01ee6865da58811745c592ee17d83b2cfde007e;hb=cdcad43ad8b497bd73df611ae53e1dfd5257400e;hp=387cdde3cfbc0118047f045c37b5b8de3a198e3d;hpb=2a957e891f86cc692ddbb80f71b1478ea03d5a4f;p=libs%2Fdemoscene.git diff --git a/source/sequencer.h b/source/sequencer.h index 387cdde..d01ee68 100644 --- a/source/sequencer.h +++ b/source/sequencer.h @@ -5,11 +5,15 @@ #include #include #include +#include #include #include #include #include "action.h" +namespace Msp { +namespace DemoScene { + class Demo; class Sequencer @@ -19,38 +23,29 @@ public: { 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; - - class RegisteredAction - { - public: - typedef void (ActionDefLoader::*LoaderFunc)(); - - virtual ~RegisteredAction() { } - virtual LoaderFunc get_loader_func() const = 0; - }; - - template - class RegisteredActionType: public RegisteredAction - { - public: - virtual LoaderFunc get_loader_func() const; - }; - class ActionDefLoader: public Msp::DataFile::ObjectLoader { - private: + protected: + template + struct AddAction + { + static void add(ActionDefLoader &ldr, const std::string &kw) { ldr.add(kw, &ActionDefLoader::action_def); } + }; + Demo &demo; Msp::RefPtr action; @@ -59,14 +54,14 @@ private: Action *get_action() { return action.release(); } - private: - virtual void finished(); + protected: + virtual void action_loaded() { } + private: template void action_def(); - template - friend class RegisteredActionType; + friend class Sequencer; }; struct Segment @@ -76,16 +71,18 @@ private: float end_beat; }; - class SegmentLoader: public Msp::DataFile::ObjectLoader + class SegmentLoader: public ActionDefLoader { private: float start_beat; float end_beat; public: - SegmentLoader(Sequencer &, float, float); + SegmentLoader(Sequencer &, float, float, Demo &); private: + virtual void action_loaded(); + void apply(const std::string &); }; @@ -93,8 +90,9 @@ public: sigc::signal signal_finished; private: - std::map action_types; + DataFile::LoadableTypeRegistry action_registry; std::map named_actions; + std::vector anonymous_actions; Msp::Time::TimeDelta secs_per_beat; std::vector static_actions; @@ -129,16 +127,7 @@ public: template inline void Sequencer::register_action_type(const std::string &n) { - if(action_types.count(n)) - throw Msp::key_error(n); - - action_types[n] = new RegisteredActionType; -} - -template -Sequencer::RegisteredAction::LoaderFunc Sequencer::RegisteredActionType::get_loader_func() const -{ - return &ActionDefLoader::action_def; + action_registry.register_type(n); } template @@ -149,7 +138,12 @@ void Sequencer::ActionDefLoader::action_def() Msp::RefPtr act = new T; load_sub(*act, demo); - action = act; + act->validate(); + action = act.release(); + action_loaded(); } +} // namespace DemoScene +} // namespace Msp + #endif