#include <cmath>
#include <msp/core/algorithm.h>
+#include <msp/core/maputils.h>
#include "sequencer.h"
using namespace std;
}
-Sequencer::InterpolationAction::InterpolationAction(bool h):
- hermite(h),
- start_beat(0),
- duration(0)
-{ }
+Sequencer::Loader::Loader(Sequencer &s, Demo &d):
+ DataFile::ObjectLoader<Sequencer>(s),
+ demo(d)
+{
+ add("define_action", &Loader::define_action);
+ add("instant", &Loader::instant);
+ add("segment", &Loader::segment);
+}
-void Sequencer::InterpolationAction::start(float b, float d)
+void Sequencer::Loader::define_action(const string &n)
{
- start_beat = b;
- duration = d;
- interpolate(0.0f, 0.0f);
+ ActionDefLoader ldr(obj, demo);
+ load_sub_with(ldr);
+ obj.named_actions[n] = ldr.get_action();
}
-void Sequencer::InterpolationAction::tick(float b, float d)
+void Sequencer::Loader::instant(float beat)
{
- if(duration)
- {
- float t = (b-start_beat)/duration;
- float dt = d/duration;
- if(hermite)
- {
- dt = t-dt;
- t = (3-2*t)*t*t;
- dt = t-(3-2*dt)*dt*dt;
- }
- interpolate(t, dt);
- }
- else
- interpolate(1.0f, 1.0f);
+ segment(beat, beat);
+}
+
+void Sequencer::Loader::segment(float start, float end)
+{
+ SegmentLoader ldr(obj, start, end);
+ load_sub_with(ldr);
+}
+
+
+Sequencer::ActionDefLoader::ActionDefLoader(Sequencer &s, Demo &d):
+ DataFile::ObjectLoader<Sequencer>(s),
+ demo(d)
+{
+ for(const auto &t: obj.action_types)
+ add(t.first, t.second->get_loader_func());
+}
+
+void Sequencer::ActionDefLoader::finished()
+{
+ if(action)
+ action->validate();
+}
+
+
+Sequencer::SegmentLoader::SegmentLoader(Sequencer &s, float b, float e):
+ ObjectLoader<Sequencer>(s),
+ start_beat(b),
+ end_beat(e)
+{
+ add("apply", &SegmentLoader::apply);
}
-void Sequencer::InterpolationAction::end(float)
+void Sequencer::SegmentLoader::apply(const string &n)
{
- interpolate(1.0f, 0.0f);
+ obj.add_action(*get_item(obj.named_actions, n), start_beat, end_beat);
}