145 lines
3.3 KiB
C++
145 lines
3.3 KiB
C++
#include <wobjectimpl.h>
|
|
|
|
#include <score/application/ApplicationContext.hpp>
|
|
#include <Explorer/DocumentPlugin/DeviceDocumentPlugin.hpp>
|
|
#include <score/actions/ActionManager.hpp>
|
|
#include <Scenario/Application/ScenarioActions.hpp>
|
|
|
|
#include "Hardware.hpp"
|
|
|
|
namespace Hardware
|
|
{
|
|
Hardware::Hardware(const score::DocumentContext& doc)
|
|
: m_dev{doc.plugin<Explorer::DeviceDocumentPlugin>()}
|
|
, h_ofset{0.} // initial horizontal ofset
|
|
, v_ofset{0.} // initial verticalal ofset
|
|
, h_zoom{.125} // initial horizontal zoom
|
|
, v_zoom{1.1} // initial verticalal zoom
|
|
{
|
|
commandCallback = [&doc, this](Controller::Commands com, const bool& shift) {
|
|
switch (com)
|
|
{
|
|
case Controller::Play:
|
|
if (shift)
|
|
doc.app.actions.action<Actions::PlayGlobal>().action()->trigger();
|
|
else
|
|
doc.app.actions.action<Actions::Play>().action()->trigger();
|
|
break;
|
|
case Controller::Stop:
|
|
if (shift)
|
|
doc.app.actions.action<Actions::Reinitialize>().action()->trigger();
|
|
else
|
|
doc.app.actions.action<Actions::Stop>().action()->trigger();
|
|
break;
|
|
case Controller::Up:
|
|
if (shift)
|
|
{
|
|
v_zoom += .2;
|
|
draw_intervals();
|
|
}
|
|
else
|
|
{
|
|
v_ofset += .02;
|
|
draw_intervals();
|
|
}
|
|
break;
|
|
case Controller::Down:
|
|
if (shift)
|
|
{
|
|
if (v_zoom > .2)
|
|
{
|
|
v_zoom -= .2;
|
|
draw_intervals();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
v_ofset -= .02;
|
|
draw_intervals();
|
|
}
|
|
break;
|
|
case Controller::Left:
|
|
if (shift)
|
|
{
|
|
if (h_zoom > .02)
|
|
{
|
|
h_zoom -= .02;
|
|
draw_intervals();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (h_ofset > 0)
|
|
{
|
|
h_ofset -= .02;
|
|
draw_intervals();
|
|
}
|
|
}
|
|
break;
|
|
case Controller::Right:
|
|
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;
|
|
};
|
|
}
|
|
|
|
void Hardware::setupController()
|
|
{
|
|
ctl = new MidiController{};
|
|
ctl->on_command = commandCallback;
|
|
ctl->setup();
|
|
}
|
|
|
|
void Hardware::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<&Hardware::on_interval_changed>(this);
|
|
scenar->intervals.removed.connect<&Hardware::on_interval_changed>(this);
|
|
|
|
connect(scenar,
|
|
&Scenario::ProcessModel::intervalMoved,
|
|
[this] { draw_intervals(); });
|
|
}
|
|
|
|
void Hardware::on_interval_changed(const Scenario::IntervalModel &)
|
|
{
|
|
draw_intervals();
|
|
}
|
|
|
|
void Hardware::draw_intervals()
|
|
{
|
|
if (!ctl || !scenar) return;
|
|
|
|
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;
|
|
ctl->draw_line({st, y}, {st + def, y});
|
|
}
|
|
|
|
ctl->update_grid();
|
|
}
|
|
}
|
|
|
|
W_OBJECT_IMPL(Hardware::Hardware)
|