2021-03-28 01:19:55 +00:00
|
|
|
#include "Sequencer.h"
|
2021-03-29 08:10:55 +00:00
|
|
|
#include <MainLoop.h>
|
2021-03-28 01:19:55 +00:00
|
|
|
|
|
|
|
Sequencer::Sequencer(std::vector<Sequencer::Scene> &&scenes) :
|
|
|
|
Task("SceneSequencer"),
|
2022-06-11 09:02:27 +00:00
|
|
|
m_idx(0),
|
|
|
|
m_scenes(std::move(scenes))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Sequencer::Sequencer(std::vector<Sequencer::Scene> &&scenes, int startIndex) :
|
|
|
|
Task("SceneSequencer"),
|
|
|
|
m_idx(startIndex),
|
2021-03-28 01:19:55 +00:00
|
|
|
m_scenes(std::move(scenes))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Sequencer::loop() {}
|
|
|
|
|
|
|
|
const char*
|
|
|
|
Sequencer::currentSceneName()
|
|
|
|
{
|
|
|
|
return m_scenes[m_idx].name;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::vector<Sequencer::Scene>
|
|
|
|
Sequencer::scenes() const
|
|
|
|
{
|
|
|
|
return m_scenes;
|
|
|
|
}
|
|
|
|
|
2022-06-11 09:02:27 +00:00
|
|
|
void
|
|
|
|
Sequencer::onStart()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-03-28 01:19:55 +00:00
|
|
|
void
|
|
|
|
Sequencer::handleEvent(const InputEvent& evt)
|
|
|
|
{
|
2022-06-11 09:02:27 +00:00
|
|
|
if (evt.intent == InputEvent::ReadyToRoll) {
|
|
|
|
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});
|
|
|
|
}
|
|
|
|
}
|
2021-04-10 18:10:25 +00:00
|
|
|
if (evt.intent == InputEvent::SetPattern && evt.asString() == m_scenes[m_idx].name) {
|
|
|
|
return;
|
|
|
|
}
|
2021-03-28 01:19:55 +00:00
|
|
|
if (evt.intent == InputEvent::SetPattern || evt.intent == InputEvent::NextPattern || evt.intent == InputEvent::PreviousPattern) {
|
2021-03-29 08:10:55 +00:00
|
|
|
Log.notice("Switching pattern!");
|
2021-03-28 01:19:55 +00:00
|
|
|
for(const char* pattern : m_scenes[m_idx].patterns) {
|
2022-06-11 09:02:27 +00:00
|
|
|
Log.verbose("Stopping pattern task %s", pattern);
|
2021-03-28 01:19:55 +00:00
|
|
|
MainLoop::instance()->dispatch(InputEvent{InputEvent::StopThing, pattern});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (evt.intent == InputEvent::NextPattern) {
|
|
|
|
m_idx++;
|
|
|
|
} else if (evt.intent == InputEvent::PreviousPattern) {
|
|
|
|
m_idx--;
|
|
|
|
} else {
|
2021-03-28 21:50:31 +00:00
|
|
|
//m_idx = evt.asInt();
|
|
|
|
for(m_idx = 0; m_idx < m_scenes.size(); m_idx++) {
|
|
|
|
if (!strcmp(evt.asString(), m_scenes[m_idx].name)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-03-28 01:19:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (m_idx < 0) {
|
|
|
|
m_idx = m_scenes.size() - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_idx >= m_scenes.size()) {
|
|
|
|
m_idx = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(const char* pattern : m_scenes[m_idx].patterns) {
|
2022-06-11 09:02:27 +00:00
|
|
|
Log.verbose("Starting pattern task %s", pattern);
|
2021-03-28 01:19:55 +00:00
|
|
|
MainLoop::instance()->dispatch(InputEvent{InputEvent::StartThing, pattern});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|