Loading...
Searching...
No Matches
TempoView.hpp
1#pragma once
2#include <Process/Dataflow/Port.hpp>
3#include <Process/Focus/FocusDispatcher.hpp>
4#include <Process/LayerPresenter.hpp>
5
6#include <Curve/CurveView.hpp>
7#include <Curve/Process/CurveProcessPresenter.hpp>
8
9#include <Scenario/Document/Tempo/TempoProcess.hpp>
10
11namespace Scenario
12{
13
14class TempoView final : public Process::LayerView
15{
16public:
17 explicit TempoView(QGraphicsItem* parent)
18 : Process::LayerView{parent}
19 {
20 setZValue(1);
21 setFlags(
22 ItemClipsToShape | ItemClipsChildrenToShape | ItemIsSelectable
23 | ItemIsFocusable);
24 setAcceptDrops(true);
25 }
26
27 void setCurveView(Curve::View* view) { m_curveView = view; }
28 ~TempoView() override { }
29
30private:
31 QPixmap pixmap() noexcept override
32 {
33 if(m_curveView)
34 return m_curveView->pixmap();
35 else
36 return QPixmap();
37 }
38
39 void paint_impl(QPainter* painter) const override { }
40 void dropEvent(QGraphicsSceneDragDropEvent* event) override
41 {
42 if(event->mimeData())
43 dropReceived(event->pos(), *event->mimeData());
44 }
45
46 Curve::View* m_curveView{};
47};
48
49class TempoPresenter final : public Curve::CurveProcessPresenter<TempoProcess, TempoView>
50{
51public:
52 explicit TempoPresenter(
53 const Curve::Style& style, const Scenario::TempoProcess& layer, TempoView* view,
54 const Process::Context& context, QObject* parent)
55 : CurveProcessPresenter{style, layer, view, context, parent}
56 {
57 // only disable the curve when using the first 2 inlets
58 for(int i = 0; i < 2; i++)
59 {
60 QObject::connect(layer.inlets()[i], &Process::Inlet::addressChanged, this, [this] {
61 disableIfNeeded();
62 });
63
64 QObject::connect(layer.inlets()[i], &Process::Inlet::cablesChanged, this, [this] {
65 disableIfNeeded();
66 });
67 }
68 }
69
70 void setFullView() override { m_curve.setBoundedMove(false); }
71
72private:
73 void disableIfNeeded()
74 {
75 bool should_disable{false};
76
77 // only disable the curve when using the first 2 inlets
78 for(int i = 0; i < 2; i++)
79 {
80 const auto inlet{m_process.inlets()[i]};
81
82 if(inlet->address().isSet() || !inlet->cables().empty())
83 should_disable = true;
84 }
85
86 if(should_disable)
87 m_curve.disable();
88 else
89 m_curve.enable();
90 }
91};
92}
Definition CurveProcessPresenter.hpp:28
Definition CurveView.hpp:25
Definition LayerView.hpp:21
Definition TempoView.hpp:50
Definition TempoView.hpp:15
Main plug-in of score.
Definition score-plugin-dataflow/Dataflow/PortItem.hpp:13
Definition CurveStyle.hpp:13
Definition ProcessContext.hpp:12