From 5296c1532980c5918ac91370e7dd670d673edb85 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Fri, 31 May 2019 22:27:53 +0300 Subject: [PATCH] Allow specifying one-off actions inside segments --- source/sequencer.cpp | 11 +++++++---- source/sequencer.h | 33 ++++++++++++++++++++++++++++++--- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/source/sequencer.cpp b/source/sequencer.cpp index eeb41d2..0297c43 100644 --- a/source/sequencer.cpp +++ b/source/sequencer.cpp @@ -159,7 +159,7 @@ void Sequencer::Loader::instant(float beat) void Sequencer::Loader::segment(float start, float end) { - SegmentLoader ldr(obj, start, end); + SegmentLoader ldr(obj, start, end, demo); load_sub_with(ldr); } @@ -169,7 +169,7 @@ Sequencer::ActionDefLoader::ActionDefLoader(Sequencer &s, Demo &d): demo(d) { for(const auto &t: obj.action_types) - add(t.first, t.second->get_loader_func()); + add(t.first, t.second->get_def_loader_func()); } void Sequencer::ActionDefLoader::finished() @@ -179,12 +179,15 @@ void Sequencer::ActionDefLoader::finished() } -Sequencer::SegmentLoader::SegmentLoader(Sequencer &s, float b, float e): +Sequencer::SegmentLoader::SegmentLoader(Sequencer &s, float b, float e, Demo &d): ObjectLoader(s), start_beat(b), - end_beat(e) + end_beat(e), + demo(d) { add("apply", &SegmentLoader::apply); + for(const auto &t: obj.action_types) + add(t.first, t.second->get_loader_func()); } void Sequencer::SegmentLoader::apply(const string &n) diff --git a/source/sequencer.h b/source/sequencer.h index 387cdde..f813717 100644 --- a/source/sequencer.h +++ b/source/sequencer.h @@ -31,13 +31,16 @@ public: private: class ActionDefLoader; + class SegmentLoader; class RegisteredAction { public: - typedef void (ActionDefLoader::*LoaderFunc)(); + 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; }; @@ -45,6 +48,7 @@ private: class RegisteredActionType: public RegisteredAction { public: + virtual DefLoaderFunc get_def_loader_func() const; virtual LoaderFunc get_loader_func() const; }; @@ -81,12 +85,19 @@ private: private: float start_beat; float end_beat; + Demo &demo; public: - SegmentLoader(Sequencer &, float, float); + SegmentLoader(Sequencer &, float, float, Demo &); private: + template + void action(); + void apply(const std::string &); + + template + friend class RegisteredActionType; }; public: @@ -95,6 +106,7 @@ public: private: std::map action_types; std::map named_actions; + std::vector anonymous_actions; Msp::Time::TimeDelta secs_per_beat; std::vector static_actions; @@ -136,11 +148,17 @@ inline void Sequencer::register_action_type(const std::string &n) } template -Sequencer::RegisteredAction::LoaderFunc Sequencer::RegisteredActionType::get_loader_func() const +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; +} + template void Sequencer::ActionDefLoader::action_def() { @@ -152,4 +170,13 @@ void Sequencer::ActionDefLoader::action_def() 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()); +} + #endif -- 2.45.2