X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fsequencer.h;h=d01ee6865da58811745c592ee17d83b2cfde007e;hb=cdcad43ad8b497bd73df611ae53e1dfd5257400e;hp=6e984025a0f27d21405185332c550952fe9ffd25;hpb=462cb9fc40ae7fec26615c652e95991be89ea8ae;p=libs%2Fdemoscene.git diff --git a/source/sequencer.h b/source/sequencer.h index 6e98402..d01ee68 100644 --- a/source/sequencer.h +++ b/source/sequencer.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -22,42 +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 SegmentLoader; - - class RegisteredAction - { - public: - typedef void (ActionDefLoader::*DefLoaderFunc)(); - typedef void (SegmentLoader::*LoaderFunc)(); - - virtual ~RegisteredAction() { } - virtual DefLoaderFunc get_def_loader_func() const = 0; - virtual LoaderFunc get_loader_func() const = 0; - }; - - template - class RegisteredActionType: public RegisteredAction - { - public: - virtual DefLoaderFunc get_def_loader_func() const; - 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; @@ -66,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 @@ -83,31 +71,26 @@ private: float end_beat; }; - class SegmentLoader: public Msp::DataFile::ObjectLoader + class SegmentLoader: public ActionDefLoader { private: float start_beat; float end_beat; - Demo &demo; public: SegmentLoader(Sequencer &, float, float, Demo &); private: - template - void action(); + virtual void action_loaded(); void apply(const std::string &); - - template - friend class RegisteredActionType; }; public: sigc::signal signal_finished; private: - std::map action_types; + DataFile::LoadableTypeRegistry action_registry; std::map named_actions; std::vector anonymous_actions; @@ -144,22 +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::DefLoaderFunc Sequencer::RegisteredActionType::get_def_loader_func() const -{ - return &ActionDefLoader::action_def; -} - -template -Sequencer::RegisteredAction::LoaderFunc Sequencer::RegisteredActionType::get_loader_func() const -{ - return &SegmentLoader::action; + action_registry.register_type(n); } template @@ -170,16 +138,9 @@ void Sequencer::ActionDefLoader::action_def() Msp::RefPtr act = new T; load_sub(*act, demo); - action = act; -} - -template -void Sequencer::SegmentLoader::action() -{ - Msp::RefPtr act = new T; - load_sub(*act, demo); - obj.add_action(*act, start_beat, end_beat); - obj.anonymous_actions.push_back(act.release()); + act->validate(); + action = act.release(); + action_loaded(); } } // namespace DemoScene