99 lines
2.2 KiB
C++
99 lines
2.2 KiB
C++
#include "Sequencer.h"
|
|
#include <MainLoop.h>
|
|
#include "Static.h"
|
|
|
|
Sequencer::Sequencer() :
|
|
Task("SceneSequencer"),
|
|
m_idx(0)
|
|
{
|
|
}
|
|
|
|
void
|
|
Sequencer::Scene::start()
|
|
{
|
|
for(const char* pattern : patterns) {
|
|
Log.verbose("Starting pattern task %s", pattern);
|
|
MainLoop::instance()->dispatch(InputEvent{InputEvent::StartThing, pattern});
|
|
}
|
|
}
|
|
|
|
void
|
|
Sequencer::Scene::stop()
|
|
{
|
|
for(const char* pattern : patterns) {
|
|
Log.verbose("Stopping pattern task %s", pattern);
|
|
MainLoop::instance()->dispatch(InputEvent{InputEvent::StopThing, pattern});
|
|
}
|
|
}
|
|
|
|
void
|
|
Sequencer::loop() {}
|
|
|
|
const char*
|
|
Sequencer::currentSceneName()
|
|
{
|
|
return m_scenes[m_idx].name;
|
|
}
|
|
|
|
const std::vector<Sequencer::Scene>
|
|
Sequencer::scenes() const
|
|
{
|
|
return m_scenes;
|
|
}
|
|
|
|
void
|
|
Sequencer::onStart()
|
|
{
|
|
}
|
|
|
|
void
|
|
Sequencer::setScenes(std::vector<Scene> &&scenes)
|
|
{
|
|
Log.notice("Updated scenes");
|
|
m_idx = 0;
|
|
m_scenes = scenes;
|
|
}
|
|
|
|
void
|
|
Sequencer::handleEvent(const InputEvent& evt)
|
|
{
|
|
if (evt.intent == InputEvent::ReadyToRoll && !m_scenes.empty()) {
|
|
Log.notice("Starting pattern %s!", m_scenes[m_idx].name);
|
|
for(const char* pattern : m_scenes[m_idx].patterns) {
|
|
Log.verbose("Starting pattern task %s", pattern);
|
|
MainLoop::instance()->dispatch(InputEvent{InputEvent::StartThing, pattern});
|
|
}
|
|
} else if (evt.intent == InputEvent::SetPattern && evt.asString() == m_scenes[m_idx].name) {
|
|
return;
|
|
} else if (evt.intent == InputEvent::SetPattern || evt.intent == InputEvent::NextPattern || evt.intent == InputEvent::PreviousPattern) {
|
|
Log.notice("Switching pattern!");
|
|
|
|
m_scenes[m_idx].stop();
|
|
|
|
if (evt.intent == InputEvent::NextPattern) {
|
|
m_idx++;
|
|
} else if (evt.intent == InputEvent::PreviousPattern) {
|
|
m_idx--;
|
|
} else {
|
|
for(m_idx = 0; m_idx < m_scenes.size(); m_idx++) {
|
|
if (!strcmp(evt.asString(), m_scenes[m_idx].name)) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (m_idx < 0) {
|
|
m_idx = m_scenes.size() - 1;
|
|
}
|
|
|
|
if (m_idx >= m_scenes.size()) {
|
|
m_idx = 0;
|
|
}
|
|
|
|
m_scenes[m_idx].start();
|
|
}
|
|
}
|
|
|
|
STATIC_ALLOC(Sequencer);
|
|
STATIC_TASK(Sequencer);
|