2024-10-06 15:16:11 +01:00
|
|
|
#include <score/application/ApplicationContext.hpp>
|
|
|
|
#include <score/actions/ActionManager.hpp>
|
|
|
|
#include <Scenario/Application/ScenarioActions.hpp>
|
2024-10-15 21:00:53 +01:00
|
|
|
#include <Process/Style/ScenarioStyle.hpp>
|
2024-10-06 15:16:11 +01:00
|
|
|
|
2024-10-03 23:50:15 +01:00
|
|
|
#include "Controller.hpp"
|
|
|
|
|
2024-10-06 15:16:11 +01:00
|
|
|
namespace Hardware
|
|
|
|
{
|
|
|
|
Controller::Controller(const score::DocumentContext& doc)
|
2024-10-08 16:12:35 +01:00
|
|
|
: bugui::controller{[&doc, this]
|
|
|
|
(commands com, const bool& shift)
|
|
|
|
{
|
2024-10-06 15:16:11 +01:00
|
|
|
switch (com)
|
|
|
|
{
|
2024-10-08 16:12:35 +01:00
|
|
|
case Play:
|
2024-10-06 15:16:11 +01:00
|
|
|
if (shift)
|
|
|
|
doc.app.actions.action<Actions::PlayGlobal>().action()->trigger();
|
|
|
|
else
|
|
|
|
doc.app.actions.action<Actions::Play>().action()->trigger();
|
|
|
|
break;
|
2024-10-08 16:12:35 +01:00
|
|
|
case Stop:
|
2024-10-06 15:16:11 +01:00
|
|
|
if (shift)
|
|
|
|
doc.app.actions.action<Actions::Reinitialize>().action()->trigger();
|
|
|
|
else
|
|
|
|
doc.app.actions.action<Actions::Stop>().action()->trigger();
|
|
|
|
break;
|
2024-10-08 16:12:35 +01:00
|
|
|
case Up:
|
2024-10-06 15:16:11 +01:00
|
|
|
if (shift)
|
|
|
|
{
|
|
|
|
v_zoom += .2;
|
|
|
|
draw_intervals();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
v_ofset += .02;
|
|
|
|
draw_intervals();
|
|
|
|
}
|
|
|
|
break;
|
2024-10-08 16:12:35 +01:00
|
|
|
case Down:
|
2024-10-06 15:16:11 +01:00
|
|
|
if (shift)
|
|
|
|
{
|
|
|
|
if (v_zoom > .2)
|
|
|
|
{
|
|
|
|
v_zoom -= .2;
|
|
|
|
draw_intervals();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
v_ofset -= .02;
|
|
|
|
draw_intervals();
|
|
|
|
}
|
|
|
|
break;
|
2024-10-08 16:12:35 +01:00
|
|
|
case Left:
|
2024-10-06 15:16:11 +01:00
|
|
|
if (shift)
|
|
|
|
{
|
|
|
|
if (h_zoom > .02)
|
|
|
|
{
|
|
|
|
h_zoom -= .02;
|
|
|
|
draw_intervals();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (h_ofset > 0)
|
|
|
|
{
|
|
|
|
h_ofset -= .02;
|
|
|
|
draw_intervals();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2024-10-08 16:12:35 +01:00
|
|
|
case Right:
|
2024-10-06 15:16:11 +01:00
|
|
|
if (shift)
|
|
|
|
{
|
|
|
|
h_zoom += .02;
|
|
|
|
draw_intervals();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
h_ofset += .02;
|
|
|
|
draw_intervals();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// qDebug() << "v_ofset: " << v_ofset;
|
|
|
|
// qDebug() << "v_zoom: " << v_zoom;
|
|
|
|
// qDebug() << "h_ofset: " << h_ofset;
|
|
|
|
// qDebug() << "h_zoom: " << h_ofset;
|
2024-10-08 16:12:35 +01:00
|
|
|
}
|
2024-10-06 15:16:11 +01:00
|
|
|
}
|
2024-10-08 16:12:35 +01:00
|
|
|
{}
|
2024-10-06 15:16:11 +01:00
|
|
|
|
|
|
|
void Controller::setup_scenario(Scenario::ProcessModel* s)
|
|
|
|
{
|
|
|
|
scenar = s;
|
|
|
|
|
|
|
|
// Connet interval signals
|
|
|
|
// adapted from
|
|
|
|
// src/plugins/score-plugin-scenario/Scenario/Process/MiniScenarioView.cpp#18
|
|
|
|
scenar->intervals.added.connect<&Controller::on_interval_changed>(this);
|
|
|
|
scenar->intervals.removed.connect<&Controller::on_interval_changed>(this);
|
|
|
|
|
|
|
|
connect(scenar,
|
|
|
|
&Scenario::ProcessModel::intervalMoved,
|
|
|
|
[this] { draw_intervals(); });
|
|
|
|
}
|
|
|
|
|
|
|
|
void Controller::on_interval_changed(const Scenario::IntervalModel &)
|
|
|
|
{
|
|
|
|
draw_intervals();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Controller::draw_intervals()
|
|
|
|
{
|
|
|
|
if (!ctl || !scenar) return;
|
|
|
|
|
2024-10-15 21:00:53 +01:00
|
|
|
// Copied from MiniscenarioView
|
|
|
|
auto& skin = Process::Style::instance();
|
|
|
|
// set_stroke_color();
|
|
|
|
|
2024-10-06 15:16:11 +01:00
|
|
|
for(const Scenario::IntervalModel& c : scenar->intervals)
|
|
|
|
{
|
|
|
|
auto def = c.duration.defaultDuration().sec() * h_zoom;
|
|
|
|
auto st = (c.date().sec() * h_zoom) - h_ofset;
|
|
|
|
auto y = (c.heightPercentage() * v_zoom) + v_ofset;
|
2024-10-08 16:12:35 +01:00
|
|
|
draw_line({st, y}, {st + def, y});
|
2024-10-06 15:16:11 +01:00
|
|
|
}
|
|
|
|
|
2024-10-08 16:12:35 +01:00
|
|
|
update_grid();
|
2024-10-06 15:16:11 +01:00
|
|
|
}
|
2024-10-08 16:12:35 +01:00
|
|
|
|
2024-10-06 15:16:11 +01:00
|
|
|
}
|
|
|
|
|
2024-10-08 16:12:35 +01:00
|
|
|
#include <wobjectimpl.h>
|
2024-10-06 15:16:11 +01:00
|
|
|
W_OBJECT_IMPL(Hardware::Controller)
|