Loading...
Searching...
No Matches
PatternView.hpp
1#pragma once
2#include <score_plugin_midi_export.h>
3#include <Process/LayerView.hpp>
4#include <Process/ZoomHelper.hpp>
5
6#include <score/tools/BarsDrag.hpp>
7
8#include <Patternist/PatternEdit.hpp>
9#include <Patternist/PatternGrid.hpp>
10#include <Patternist/PatternModel.hpp>
11
12#include <optional>
13
14namespace score
15{
16class QGraphicsNoteChooser;
17}
18namespace Patternist
19{
20class ProcessModel;
21class SCORE_PLUGIN_MIDI_EXPORT View final : public Process::LayerView
22{
23 W_OBJECT(View)
24public:
25 enum class Mode
26 {
28 Fit,
30 Timeline
31 };
32
33 explicit View(const Patternist::ProcessModel& model, QGraphicsItem* parent);
34 ~View() override;
35
36 void setMode(Mode m);
39 void setAdvanced(bool b);
40 void setTimeGrid(const TimeGrid& g);
41 void setZoom(ZoomRatio z);
42 void setField(StepField f);
43 void setSelectedLane(int lane);
44 int selectedLane() const noexcept { return m_selectedLane; }
45
47 int headerLaneAt(QPointF pos) const noexcept;
48
49 struct Cell
50 {
51 int lane{-1};
52 int step{-1};
53 };
56 const StepSelection& selection() const;
60 const std::vector<int>& selectedLanes() const noexcept { return m_selectedLanes; }
61 void setSelectedLanes(std::vector<int> lanes);
63 void clearSelection();
64 void selectAll();
65 void setSelectMode(bool b);
67 void setRings(bool b);
68 bool rings() const noexcept { return m_rings; }
69
74 {
75 int lane{-1};
76 std::vector<int> starts;
77 };
78 PasteTarget pasteTarget(int lanes) const;
81 StepField field() const noexcept;
83 double minimumHeight() const noexcept;
85 const std::vector<float>& draggedValues() const noexcept { return m_dragValues; }
86
88 void paintStep(int lane, int step, Patternist::Note n)
89 W_SIGNAL(paintStep, lane, step, n);
90 void paintFinished() W_SIGNAL(paintFinished);
91 void noteChanged(int lane, int note) W_SIGNAL(noteChanged, lane, note);
92 void noteChangeFinished() W_SIGNAL(noteChangeFinished);
93 void muteToggled(int lane) W_SIGNAL(muteToggled, lane);
94 void soloToggled(int lane) W_SIGNAL(soloToggled, lane);
95 void laneSelected(int lane) W_SIGNAL(laneSelected, lane);
97 void fieldEdited(int lane, int step, int field, float value)
98 W_SIGNAL(fieldEdited, lane, step, field, value);
99 void fieldEditFinished() W_SIGNAL(fieldEditFinished);
102 void fieldValuesEdited(int lane, int field) W_SIGNAL(fieldValuesEdited, lane, field);
103 void stepMenuRequested(int lane, int step, QPoint screen)
104 W_SIGNAL(stepMenuRequested, lane, step, screen);
105
106 void selectionChanged() W_SIGNAL(selectionChanged);
107 void fieldSelected(int field) W_SIGNAL(fieldSelected, field);
109 void fieldRandomized(int lane, int field) W_SIGNAL(fieldRandomized, lane, field);
110 void fieldReset(int lane, int field) W_SIGNAL(fieldReset, lane, field);
113 void laneValueEdited(int lane, int which, int value)
114 W_SIGNAL(laneValueEdited, lane, which, value);
115 void laneValueEditFinished() W_SIGNAL(laneValueEditFinished);
116
117private:
118 static constexpr StepField allFields[]
119 = {StepField::Velocity, StepField::VelocityRandom, StepField::Chance,
120 StepField::Offset, StepField::OffsetRandom, StepField::Gate,
121 StepField::GateRandom, StepField::Ratchet, StepField::Pace,
122 StepField::Pitch, StepField::PitchRandom};
125 struct FieldRow
126 {
127 StepField value;
128 std::optional<StepField> random;
129 };
130 static constexpr FieldRow fieldRows[]
131 = {{StepField::Velocity, StepField::VelocityRandom},
132 {StepField::Chance, {}},
133 {StepField::Offset, StepField::OffsetRandom},
134 {StepField::Gate, StepField::GateRandom},
135 {StepField::Ratchet, {}},
136 {StepField::Pace, {}},
137 {StepField::Pitch, StepField::PitchRandom}};
139 bool fieldUsed(StepField f) const noexcept;
140 QString fieldLabel(StepField f) const;
141 double randomButtonWidth() const noexcept;
143 static constexpr int all_button = 999;
144 static constexpr int mute_button = 1000;
145 static constexpr int solo_button = 2000;
146 static constexpr int field_button = 3000;
147 static constexpr int steps_button = 5000;
148 static constexpr int rate_button = 6000;
149
150 QFont nameFont() const;
151 const QFont& smallFont() const;
152 bool stackedHeader() const noexcept;
153 bool laneValues() const noexcept;
154 bool ringsMode() const noexcept;
155 struct Ring
156 {
157 double inner{}, outer{};
158 };
159 QRectF ringArea() const noexcept;
160 QPointF ringCenter() const noexcept;
161 Ring ring(int lane) const noexcept;
162 std::pair<double, double> slotTurns(const StepSlot& sl) const noexcept;
163 Cell ringCellAt(QPointF pos) const noexcept;
164 void paintRings(QPainter*, const Pattern&) const;
165 void paintRingCenter(QPainter*, const Pattern&, QRectF box) const;
166 double cellHeight() const noexcept;
167 QRectF valueRect(int lane, int which) const noexcept;
168 void paintValue(
169 QPainter* painter, QRectF r, const QString& text, bool inherited, int id) const;
170 QRectF nameRect(int lane) const noexcept;
171 QRectF fieldButtonRect(int i) const noexcept;
172 QRectF allButtonRect() const noexcept;
173 void toggleLane(int lane);
174 int buttonAt(QPointF pos) const noexcept;
175 void pressButton(int id, Qt::KeyboardModifiers mods);
176 void paintButton(
177 QPainter* painter, QRectF r, const QString& text, bool on, const QColor& onColor,
178 int id) const;
179
180 const Pattern* pattern() const noexcept;
181 void updateLanes();
182 void layoutLanes();
183 void invalidateSlots();
184 const std::vector<StepSlot>& slots(int lane) const;
186 int playingSlot(int lane) const noexcept;
187
188 double headerWidth() const noexcept;
189 double measureHeader() const noexcept;
190 double fieldButtonHeight() const noexcept;
191 bool laneButtons() const noexcept;
192 double gridTop() const noexcept;
193 double gridBottom() const noexcept;
194 double laneHeight() const noexcept;
195 QRectF laneRect(int lane) const noexcept;
196 QRectF muteRect(int lane) const noexcept;
197 QRectF soloRect(int lane) const noexcept;
198 double fieldHeight() const noexcept;
199 QRectF fieldRect() const noexcept;
200 bool canEdit() const noexcept;
201 Cell cellAt(QPointF pos) const noexcept;
202 int fieldStepAt(QPointF pos) const noexcept;
203
204 void paint_impl(QPainter*) const override;
205 void paintCells(QPainter*, const Pattern&) const;
206 void paintHeader(QPainter*, const Pattern&) const;
207 void paintField(QPainter*, const Pattern&) const;
208 void paintStatus(QPainter*) const;
209
210 void heightChanged(qreal) override;
211 void widthChanged(qreal) override;
212
213 void mousePressEvent(QGraphicsSceneMouseEvent* event) override;
214 void mouseMoveEvent(QGraphicsSceneMouseEvent* event) override;
215 void mouseReleaseEvent(QGraphicsSceneMouseEvent* event) override;
216 void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event) override;
217 void hoverMoveEvent(QGraphicsSceneHoverEvent* event) override;
218 void hoverLeaveEvent(QGraphicsSceneHoverEvent* event) override;
219 void contextMenuEvent(QGraphicsSceneContextMenuEvent* event) override;
220 bool sceneEvent(QEvent* event) override;
221 bool sceneEventFilter(QGraphicsItem* watched, QEvent* event) override;
222 QVariant itemChange(GraphicsItemChange change, const QVariant& value) override;
223 void dropEvent(QGraphicsSceneDragDropEvent* event) override;
224
225 void paintAt(QPointF pos);
226 void startFieldDrag(QPointF pos, Qt::KeyboardModifiers mods);
227 void dragField(QPointF pos);
228 void selectOver(QPointF pos);
229 struct SelectionArea
230 {
231 int lane0{-1}, lane1{-1};
232 double x0{}, x1{};
233 bool operator==(const SelectionArea&) const noexcept = default;
234 };
235 void setSelectionArea(SelectionArea a);
236 void editFieldAt(QPointF pos);
237 void endPainting();
238
239 const Patternist::ProcessModel& m_model;
240
241 std::vector<score::QGraphicsNoteChooser*> m_lanes;
242 Mode m_mode{Mode::Fit};
243 bool m_advanced{};
244 StepField m_field{StepField::Velocity};
245 int m_selectedLane{};
246 TimeGrid m_grid;
247 ZoomRatio m_zoom{};
248 mutable std::vector<std::vector<StepSlot>> m_slots;
249 mutable bool m_slotsValid{};
250 mutable std::optional<double> m_headerWidth;
252 mutable double m_span{};
253
254 int m_execPattern{-1};
255 int m_pendingPattern{-1};
256
257 Cell m_hover;
258 int m_hoverButton{-1};
259 struct ValueDrag
260 {
261 int id{};
262 int lane{};
263 int which{};
264 double y{};
265 int start{};
266 };
267 std::optional<ValueDrag> m_valueDrag;
268 double m_hoverX{};
269 SelectionArea m_selectionArea;
270 mutable StepSelection m_selection;
271 std::vector<int> m_selectedLanes;
272 mutable bool m_selectionValid{};
273 QPointF m_selectAnchor;
274 bool m_selecting{};
275 bool m_selectMode{};
276 bool m_rings{};
278 std::optional<Note> m_painting;
279 Cell m_lastPainted;
280 bool m_editingField{};
281 score::BarsDrag m_fieldDrag;
282 std::vector<float> m_dragValues;
283 bool m_swallowContextMenu{};
284};
285}
Definition PatternModel.hpp:247
Definition PatternView.hpp:22
void paintStep(int lane, int step, Patternist::Note n)
Set a step while painting: emitted for every step the mouse enters.
Mode
Definition PatternView.hpp:26
const std::vector< int > & selectedLanes() const noexcept
Definition PatternView.hpp:60
Definition LayerView.hpp:21
Base toolkit upon which the software is built.
Definition Application.cpp:83
STL namespace.
Definition PatternEdit.hpp:67
Definition PatternGrid.hpp:20
Definition PatternView.hpp:50
Definition PatternView.hpp:74
A modifier drag over a row of bars, each the value of a step.
Definition BarsDrag.hpp:22