X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fsequencer.cpp;h=25182b8ef6ee7f4e623b83cfc942f8fe17339e86;hb=cdcad43ad8b497bd73df611ae53e1dfd5257400e;hp=4acad43b2891bc9bf813bf481e75277fa0a4bf71;hpb=35332818fc6bad98fe77831de2c51a11326e31aa;p=libs%2Fdemoscene.git diff --git a/source/sequencer.cpp b/source/sequencer.cpp index 4acad43..25182b8 100644 --- a/source/sequencer.cpp +++ b/source/sequencer.cpp @@ -1,9 +1,16 @@ #include #include +#include +#include +#include "animate.h" +#include "fadeoverlay.h" #include "sequencer.h" +#include "stage.h" using namespace std; -using namespace Msp; + +namespace Msp { +namespace DemoScene { Sequencer::Sequencer(float bpm): started(false), @@ -11,6 +18,11 @@ Sequencer::Sequencer(float bpm): next_event(0) { set_beats_per_minute(bpm); + + register_action_type("animate"); + register_action_type("fade"); + register_action_type("use_stage"); + register_action_type("set_camera"); } void Sequencer::set_beats_per_minute(float bpm) @@ -28,12 +40,12 @@ void Sequencer::add_action(Action &act, float sb, float eb) if(sb<0 || sb>eb) throw invalid_argument("Sequencer::add_action"); - Segment seq_act; - seq_act.action = &act; - seq_act.start_beat = sb; - seq_act.end_beat = eb; + Segment seg; + seg.action = &act; + seg.start_beat = sb; + seg.end_beat = eb; auto i = find_if(segments, [=](const Segment &s){ return s.start_beat>sb; }); - segments.insert(i, seq_act); + segments.insert(i, seg); } void Sequencer::start() @@ -127,38 +139,78 @@ void Sequencer::update_next_event() } -Sequencer::InterpolationAction::InterpolationAction(bool h): - hermite(h), - start_beat(0), - duration(0) -{ } +Sequencer::Loader::Loader(Sequencer &s, Demo &d): + DataFile::ObjectLoader(s), + demo(d), + base_beat(0.0f) +{ + add("base", &Loader::base); + add("define_action", &Loader::define_action); + add("instant", &Loader::instant); + add("repeat", &Loader::repeat); + add("segment", &Loader::segment); +} + +void Sequencer::Loader::base(float b) +{ + SetForScope set_base(base_beat, base_beat+b); + load_sub_with(*this); +} + +void Sequencer::Loader::define_action(const string &n) +{ + ActionDefLoader ldr(obj, demo); + load_sub_with(ldr); + obj.named_actions[n] = ldr.get_action(); +} -void Sequencer::InterpolationAction::start(float b, float d) +void Sequencer::Loader::instant(float beat) { - start_beat = b; - duration = d; - interpolate(0.0f, 0.0f); + segment(beat, beat); } -void Sequencer::InterpolationAction::tick(float b, float d) +void Sequencer::Loader::repeat(float b, float d, unsigned n) { - if(duration) + for(unsigned i=0; i set_base(base_beat, base_beat+b+i*d); + load_sub_with(*this); } - else - interpolate(1.0f, 1.0f); } -void Sequencer::InterpolationAction::end(float) +void Sequencer::Loader::segment(float start, float end) +{ + SegmentLoader ldr(obj, base_beat+start, base_beat+end, demo); + load_sub_with(ldr); +} + + +Sequencer::ActionDefLoader::ActionDefLoader(Sequencer &s, Demo &d): + DataFile::ObjectLoader(s), + demo(d) +{ + obj.action_registry.add_all(*this); +} + + +Sequencer::SegmentLoader::SegmentLoader(Sequencer &s, float b, float e, Demo &d): + ActionDefLoader(s, d), + start_beat(b), + end_beat(e) +{ + add("apply", &SegmentLoader::apply); +} + +void Sequencer::SegmentLoader::action_loaded() { - interpolate(1.0f, 0.0f); + obj.add_action(*action, start_beat, end_beat); + obj.anonymous_actions.push_back(action.release()); } + +void Sequencer::SegmentLoader::apply(const string &n) +{ + obj.add_action(*get_item(obj.named_actions, n), start_beat, end_beat); +} + +} // namespace DemoScene +} // namespace Msp