#include #include #include #include #include "Controller.hpp" #include "Hardware/IntervalWidget.hpp" namespace Hardware { Controller::Controller(const score::DocumentContext& document, Scenario::IntervalModel& interval, std::string_view device_name) : bugui::controller{device_name} , doc{document} , interval{&interval} { // Connet interval signals // adapted from // src/plugins/score-plugin-scenario/Scenario/Process/MiniScenarioView.cpp#18 auto scnr = qobject_cast(&*interval.processes.begin()); scnr->intervals.mutable_added.connect<&Controller::on_interval_added>(this); scnr->intervals.removed.connect<&Controller::on_interval_removed>(this); connect(scnr, &Scenario::ProcessModel::intervalMoved, [this] { update(); }); for(Scenario::IntervalModel& c : scnr->intervals) widgets.emplace_back(std::make_unique(this, interval)); update(); } void Controller::on_interval_added(Scenario::IntervalModel &interval) { widgets.emplace_back(std::make_unique(this, interval)); update(); } void Controller::on_interval_removed(const Scenario::IntervalModel& interval) { std::erase_if(widgets, [&interval] (auto& w) { return static_cast(w.get())->get_model().id() == interval.id(); }); update(); } void Controller::on_interval_changed(const Scenario::IntervalModel &) { update(); } void Controller::paint(bugui::painter& painter) { // // Copied from MiniscenarioView // auto& skin = Process::Style::instance(); // const auto col = skin.IntervalBase().color(); // painter.set_color(col.red(), col.green(), col.blue(), col.alpha()); // auto scnr = qobject_cast(&*interval->processes.begin()); // for(const Scenario::IntervalModel& c : scnr->intervals) // { // int def = c.duration.defaultDuration().sec(); // // auto def = c.duration.defaultDuration().sec() * h_zoom; // int st = c.date().sec() - h_ofset; // // auto st = (c.date().sec() * h_zoom) - h_ofset; // int y = (c.heightPercentage() * height()) + v_ofset; // // auto y = (c.heightPercentage() * v_zoom) + v_ofset; // painter.draw_line({st, y}, {st + def, y}); // } } void Controller::on_grid(float x, float y, bool pressed) { qDebug() << "x: " << x << " y: " << y << " pressed: " << pressed; } void Controller::on_play(bool pressed) { if (m_shift) doc.app.actions.action().action()->trigger(); else doc.app.actions.action().action()->trigger(); } void Controller::on_stop(bool pressed) { if (m_shift) doc.app.actions.action().action()->trigger(); else doc.app.actions.action().action()->trigger(); } void Controller::on_shift(bool pressed) { m_shift = pressed; } void Controller::on_up(bool pressed) { if (m_shift) { v_scale += .2; update(); } else { v_ofset += .02; update(); } } void Controller::on_down(bool pressed) { if (m_shift) { if (v_scale > .2) { v_scale -= .2; update(); } } else { v_ofset -= .02; update(); } } void Controller::on_left(bool pressed) { if (m_shift) { if (h_scale > .02) { h_scale -= .02; update(); } } else { if (h_ofset > 0) { h_ofset -= .02; update(); } } } void Controller::on_right(bool pressed) { if (m_shift) { h_scale += .02; update(); } else { h_ofset += .02; update(); } } } // namespace hardware #include W_OBJECT_IMPL(Hardware::Controller)