Loading...
Searching...
No Matches
AutomationPresenter.hpp
1#pragma once
2#include <State/UpdateAddress.hpp>
3
4#include <Device/Node/NodeListMimeSerialization.hpp>
5
6#include <Process/ProcessContext.hpp>
7#include <Process/ProcessMimeSerialization.hpp>
8
9#include <Magnetism/MagnetismAdjuster.hpp>
10
11#include <Curve/Process/CurveProcessPresenter.hpp>
12
13#include <Automation/AutomationModel.hpp>
14#include <Automation/AutomationView.hpp>
15#include <Automation/Commands/ChangeAddress.hpp>
16
17#include <score/application/GUIApplicationContext.hpp>
18
19#include <verdigris>
20
21namespace Automation
22{
23class LayerPresenter final : public Curve::CurveProcessPresenter<ProcessModel, LayerView>
24{
25 W_OBJECT(LayerPresenter)
26public:
28 const Curve::Style& style, const Automation::ProcessModel& layer, LayerView* view,
29 const Process::Context& context, QObject* parent)
30 : CurveProcessPresenter{style, layer, view, context, parent}
31 {
32 // TODO instead have a prettyNameChanged signal.
33 con(layer, &ProcessModel::tweenChanged, this, &LayerPresenter::on_tweenChanges);
34
35 connect(m_view, &LayerView::dropReceived, this, &LayerPresenter::on_dropReceived);
36
37 on_tweenChanges(layer.tween());
38 con(layer.curve(), &Curve::Model::curveReset, this,
39 [&] { on_tweenChanges(layer.tween()); });
40
41 // Queried with the curve rather than the automation, so that the
42 // automation's own points, including the dragged one, do not attract it.
43 auto& magnetism = (Process::MagnetismAdjuster&)
45 m_curve.setMagnetism([&layer, &magnetism](double x) {
46 const TimeVal dur = layer.duration();
47 if(dur.impl <= 0)
48 return x;
49 const auto info = magnetism.getPosition(
50 &layer.curve(), TimeVal{int64_t(x * double(dur.impl))});
51 return double(info.time.impl) / double(dur.impl);
52 });
53 }
54
55private:
56 void setFullView() override { m_curve.setBoundedMove(false); }
57
58 void on_tweenChanges(bool b)
59 {
60 for(Curve::SegmentView& seg : m_curve.segments())
61 {
62 if(seg.model().start().x() != 0.)
63 {
64 seg.setTween(false);
65 }
66 else
67 {
68 seg.setTween(b);
69 }
70 }
71 }
72
73 void on_dropReceived(const QPointF& pos, const QMimeData& mime)
74 {
75 if(auto addr = State::onUpdatableAddress(model().address(), mime))
76 {
77 CommandDispatcher<>{context().context.commandStack}.submit(
78 new ChangeAddress{model(), *addr});
79 }
80 else if(mime.hasFormat(score::mime::processpreset()))
81 {
82 handlePresetDrop(pos, mime);
83 }
84 }
85};
86}
Definition score-plugin-automation/Automation/Commands/ChangeAddress.hpp:24
Definition AutomationPresenter.hpp:24
Definition AutomationView.hpp:16
Definition AutomationModel.hpp:36
The CommandDispatcher class.
Definition CommandDispatcher.hpp:13
Definition CurveProcessPresenter.hpp:28
void setMagnetism(std::function< double(double)> f) noexcept
Definition CurvePresenter.hpp:83
Definition CurveSegmentView.hpp:27
Definition MagnetismAdjuster.hpp:24
Namespace related to the Automation process.
Definition AutomationColors.cpp:8
Definition CurveStyle.hpp:14
Definition ProcessContext.hpp:12
Definition TimeValue.hpp:21
const T & interfaces() const
Access to a specific interface list.
Definition ApplicationContext.hpp:87