Skip to content

Commit d90e7d3

Browse files
Add midi editor drag
1 parent 54c438a commit d90e7d3

File tree

10 files changed

+168
-14
lines changed

10 files changed

+168
-14
lines changed

src/ui/component/editor/MIDIContentViewer.cpp

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,17 @@
44
#include "../../../audioCore/AC_API.h"
55

66
MIDIContentViewer::MIDIContentViewer(
7+
const ScrollFunc& scrollFunc,
78
const WheelFunc& wheelFunc,
89
const WheelAltFunc& wheelAltFunc,
910
const MouseYPosFunc& mouseYPosFunc,
10-
const MouseLeaveFunc& mouseLeaveFunc)
11-
: wheelFunc(wheelFunc), wheelAltFunc(wheelAltFunc),
12-
mouseYPosFunc(mouseYPosFunc), mouseLeaveFunc(mouseLeaveFunc) {
11+
const MouseLeaveFunc& mouseLeaveFunc,
12+
const DragStartFunc& dragStartFunc,
13+
const DragProcessFunc& dragProcessFunc,
14+
const DragEndFunc& dragEndFunc)
15+
: scrollFunc(scrollFunc), wheelFunc(wheelFunc), wheelAltFunc(wheelAltFunc),
16+
mouseYPosFunc(mouseYPosFunc), mouseLeaveFunc(mouseLeaveFunc),
17+
dragStartFunc(dragStartFunc), dragProcessFunc(dragProcessFunc), dragEndFunc(dragEndFunc) {
1318
/** Look And Feel */
1419
this->setLookAndFeel(
1520
LookAndFeelFactory::getInstance()->forMidiContent());
@@ -180,6 +185,26 @@ void MIDIContentViewer::paintOverChildren(juce::Graphics& g) {
180185
//}
181186
}
182187

188+
void MIDIContentViewer::mouseDown(const juce::MouseEvent& event) {
189+
if (event.mods.isLeftButtonDown() && event.mods.isAltDown()) {
190+
/** Move View Area */
191+
this->viewMoving = true;
192+
this->setMouseCursor(juce::MouseCursor::DraggingHandCursor);
193+
this->dragStartFunc();
194+
}
195+
}
196+
197+
void MIDIContentViewer::mouseUp(const juce::MouseEvent& event) {
198+
if (event.mods.isLeftButtonDown()) {
199+
/** Move View */
200+
if (this->viewMoving) {
201+
this->viewMoving = false;
202+
this->setMouseCursor(juce::MouseCursor::NormalCursor);
203+
this->dragEndFunc();
204+
}
205+
}
206+
}
207+
183208
void MIDIContentViewer::mouseMove(const juce::MouseEvent& event) {
184209
/** Send Y Pos */
185210
this->mouseYPosFunc(event.position.getY());
@@ -188,11 +213,43 @@ void MIDIContentViewer::mouseMove(const juce::MouseEvent& event) {
188213
void MIDIContentViewer::mouseDrag(const juce::MouseEvent& event) {
189214
/** Send Y Pos */
190215
this->mouseYPosFunc(event.position.getY());
216+
217+
/** Auto Scroll */
218+
float xPos = event.position.getX();
219+
if (!this->viewMoving) {
220+
double delta = 0;
221+
if (xPos > this->getWidth()) {
222+
delta = xPos - this->getWidth();
223+
}
224+
else if (xPos < 0) {
225+
delta = xPos;
226+
}
227+
228+
if (delta != 0) {
229+
this->scrollFunc(delta / 4);
230+
}
231+
}
232+
233+
if (event.mods.isLeftButtonDown()) {
234+
/** Move View */
235+
if (this->viewMoving) {
236+
int distanceX = event.getDistanceFromDragStartX();
237+
int distanceY = event.getDistanceFromDragStartY();
238+
this->dragProcessFunc(distanceX, distanceY, true, true);
239+
}
240+
}
191241
}
192242

193243
void MIDIContentViewer::mouseExit(const juce::MouseEvent& event) {
194244
/** Send Mouse Exit */
195245
this->mouseLeaveFunc();
246+
247+
/** Move View */
248+
if (this->viewMoving) {
249+
this->viewMoving = false;
250+
this->setMouseCursor(juce::MouseCursor::NormalCursor);
251+
this->dragEndFunc();
252+
}
196253
}
197254

198255
void MIDIContentViewer::mouseWheelMove(

src/ui/component/editor/MIDIContentViewer.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,23 @@ class MIDIContentViewer final
77
: public juce::Component,
88
public LevelMeterHub::Target {
99
public:
10+
using ScrollFunc = std::function<void(double)>;
1011
using WheelFunc = std::function<void(float, bool)>;
1112
using WheelAltFunc = std::function<void(double, double, float, bool)>;
1213
using MouseYPosFunc = std::function<void(float)>;
1314
using MouseLeaveFunc = std::function<void()>;
15+
using DragStartFunc = std::function<void(void)>;
16+
using DragProcessFunc = std::function<void(int, int, bool, bool)>;
17+
using DragEndFunc = std::function<void(void)>;
1418
MIDIContentViewer(
19+
const ScrollFunc& scrollFunc,
1520
const WheelFunc& wheelFunc,
1621
const WheelAltFunc& wheelAltFunc,
1722
const MouseYPosFunc& mouseYPosFunc,
18-
const MouseLeaveFunc& mouseLeaveFunc);
23+
const MouseLeaveFunc& mouseLeaveFunc,
24+
const DragStartFunc& dragStartFunc,
25+
const DragProcessFunc& dragProcessFunc,
26+
const DragEndFunc& dragEndFunc);
1927

2028
void update(int index, uint64_t ref);
2129
void updateTempoLabel();
@@ -29,17 +37,23 @@ class MIDIContentViewer final
2937
void paint(juce::Graphics& g) override;
3038
void paintOverChildren(juce::Graphics& g) override;
3139

40+
void mouseDown(const juce::MouseEvent& event) override;
41+
void mouseUp(const juce::MouseEvent& event) override;
3242
void mouseMove(const juce::MouseEvent& event) override;
3343
void mouseDrag(const juce::MouseEvent& event) override;
3444
void mouseExit(const juce::MouseEvent& event) override;
3545
void mouseWheelMove(const juce::MouseEvent& event,
3646
const juce::MouseWheelDetails& wheel) override;
3747

3848
private:
49+
const ScrollFunc scrollFunc;
3950
const WheelFunc wheelFunc;
4051
const WheelAltFunc wheelAltFunc;
4152
const MouseYPosFunc mouseYPosFunc;
4253
const MouseLeaveFunc mouseLeaveFunc;
54+
const DragStartFunc dragStartFunc;
55+
const DragProcessFunc dragProcessFunc;
56+
const DragEndFunc dragEndFunc;
4357

4458
/** 0 for white key and 1 for black key */
4559
const std::array<int, 12> keyMasks{ 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0 };
@@ -66,6 +80,8 @@ class MIDIContentViewer final
6680
using BlockItem = std::tuple<double, double>;
6781
juce::Array<BlockItem> blockItemTemp;
6882

83+
bool viewMoving = false;
84+
6985
std::unique_ptr<juce::Image> rulerTemp = nullptr;
7086
std::unique_ptr<juce::Image> keyTemp = nullptr;
7187
std::unique_ptr<juce::Image> blockTemp = nullptr;

src/ui/component/editor/MIDISourceEditor.cpp

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,19 @@ MIDISourceEditor::MIDISourceEditor() {
5454
comp->mouseWheelOutsideWithAlt(centerNum, thumbPer, deltaY, reversed);
5555
}
5656
},
57-
[comp = ScrollerBase::SafePointer(this)] {
57+
[comp = MIDISourceEditor::SafePointer(this)] {
5858
if (comp) {
5959
comp->processAreaDragStart();
6060
}
6161
},
62-
[comp = ScrollerBase::SafePointer(this)]
62+
[comp = MIDISourceEditor::SafePointer(this)]
6363
(int distanceX, int distanceY, bool moveX, bool moveY) {
6464
if (comp) {
6565
comp->processAreaDragTo(
6666
distanceX, distanceY, moveX, moveY);
6767
}
6868
},
69-
[comp = ScrollerBase::SafePointer(this)] {
69+
[comp = MIDISourceEditor::SafePointer(this)] {
7070
if (comp) {
7171
comp->processAreaDragEnd();
7272
}
@@ -98,6 +98,12 @@ MIDISourceEditor::MIDISourceEditor() {
9898

9999
/** Content */
100100
this->content = std::make_unique<MIDIContentViewer>(
101+
[comp = ScrollerBase::SafePointer(this->hScroller.get())]
102+
(double delta) {
103+
if (comp) {
104+
comp->scroll(delta);
105+
}
106+
},
101107
[comp = ScrollerBase::SafePointer(this->hScroller.get())]
102108
(float deltaY, bool reversed) {
103109
if (comp) {
@@ -120,6 +126,23 @@ MIDISourceEditor::MIDISourceEditor() {
120126
if (comp) {
121127
comp->mouseLeaveOutside();
122128
}
129+
},
130+
[comp = MIDISourceEditor::SafePointer(this)] {
131+
if (comp) {
132+
comp->processAreaDragStart();
133+
}
134+
},
135+
[comp = MIDISourceEditor::SafePointer(this)]
136+
(int distanceX, int distanceY, bool moveX, bool moveY) {
137+
if (comp) {
138+
comp->processAreaDragTo(
139+
distanceX, distanceY, moveX, moveY);
140+
}
141+
},
142+
[comp = MIDISourceEditor::SafePointer(this)] {
143+
if (comp) {
144+
comp->processAreaDragEnd();
145+
}
123146
});
124147
this->addAndMakeVisible(this->content.get());
125148

src/ui/component/editor/SourceTimeRuler.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,23 @@ void SourceTimeRuler::mouseWheelMove(const juce::MouseEvent& event,
526526
}
527527
}
528528

529+
void SourceTimeRuler::mouseExit(const juce::MouseEvent& event) {
530+
/** Move Label */
531+
if (this->dragLabelIndex > -1) {
532+
/** Reset State */
533+
this->dragLabelIndex = -1;
534+
this->labelDragOffset = 0;
535+
this->labelDragPos = 0;
536+
}
537+
538+
/** Move View */
539+
else if (this->viewMoving) {
540+
this->viewMoving = false;
541+
this->mouseMove(event);/**< Update Mouse Cursor */
542+
this->dragEndFunc();
543+
}
544+
}
545+
529546
std::tuple<double, double> SourceTimeRuler::getViewArea(
530547
double pos, double itemSize) const {
531548
double secStart = pos / itemSize;

src/ui/component/editor/SourceTimeRuler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class SourceTimeRuler final
3636
void mouseMove(const juce::MouseEvent& event) override;
3737
void mouseWheelMove(const juce::MouseEvent& event,
3838
const juce::MouseWheelDetails& wheel) override;
39+
void mouseExit(const juce::MouseEvent& event) override;
3940

4041
/** Place, IsBar, barId */
4142
using LineItem = std::tuple<double, bool, int>;

src/ui/component/sequencer/SeqTimeRuler.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,23 @@ void SeqTimeRuler::mouseWheelMove(const juce::MouseEvent& event,
526526
}
527527
}
528528

529+
void SeqTimeRuler::mouseExit(const juce::MouseEvent& event) {
530+
/** Move Label */
531+
if (this->dragLabelIndex > -1) {
532+
/** Reset State */
533+
this->dragLabelIndex = -1;
534+
this->labelDragOffset = 0;
535+
this->labelDragPos = 0;
536+
}
537+
538+
/** Move View */
539+
else if (this->viewMoving) {
540+
this->viewMoving = false;
541+
this->mouseMove(event);/**< Update Mouse Cursor */
542+
this->dragEndFunc();
543+
}
544+
}
545+
529546
std::tuple<double, double> SeqTimeRuler::getViewArea(
530547
double pos, double itemSize) const {
531548
double secStart = pos / itemSize;

src/ui/component/sequencer/SeqTimeRuler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class SeqTimeRuler final
3636
void mouseMove(const juce::MouseEvent& event) override;
3737
void mouseWheelMove(const juce::MouseEvent& event,
3838
const juce::MouseWheelDetails& wheel) override;
39+
void mouseExit(const juce::MouseEvent& event) override;
3940

4041
/** Place, IsBar, barId */
4142
using LineItem = std::tuple<double, bool, int>;

src/ui/component/sequencer/SeqTrackContentViewer.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,18 @@ void SeqTrackContentViewer::mouseUp(const juce::MouseEvent& event) {
781781
}
782782

783783
void SeqTrackContentViewer::mouseExit(const juce::MouseEvent& event) {
784+
/** Move View */
785+
if (this->viewMoving) {
786+
this->viewMoving = false;
787+
this->mouseMove(event);/**< Update Mouse Cursor */
788+
this->dragEndFunc();
789+
}
790+
791+
this->dragType = DragType::None;
792+
this->pressedBlockIndex = -1;
793+
this->mousePressedSecond = 0;
794+
this->blockValid = true;
795+
this->copyMode = false;
784796
this->mouseCurrentSecond = -1;
785797
this->repaint();
786798
}

src/ui/component/sequencer/SeqView.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,15 @@ void SeqView::TrackList::mouseWheelMove(const juce::MouseEvent& event,
238238

239239
}
240240

241+
void SeqView::TrackList::mouseExit(const juce::MouseEvent& event) {
242+
/** Move View */
243+
if (this->viewMoving) {
244+
this->viewMoving = false;
245+
this->setMouseCursor(juce::MouseCursor::NormalCursor);
246+
this->dragEndFunc();
247+
}
248+
}
249+
241250
void SeqView::TrackList::add() {
242251
CoreActions::insertSeqGUI();
243252
}
@@ -310,24 +319,24 @@ SeqView::SeqView()
310319
comp->mouseWheelOutsideWithAlt(centerNum, thumbPer, deltaY, reversed);
311320
}
312321
},
313-
[comp = ScrollerBase::SafePointer(this)] {
322+
[comp = SeqView::SafePointer(this)] {
314323
if (comp) {
315324
comp->processAreaDragStart();
316325
}
317326
},
318-
[comp = ScrollerBase::SafePointer(this)]
327+
[comp = SeqView::SafePointer(this)]
319328
(int distanceX, int distanceY, bool moveX, bool moveY) {
320329
if (comp) {
321330
comp->processAreaDragTo(
322331
distanceX, distanceY, moveX, moveY);
323332
}
324333
},
325-
[comp = ScrollerBase::SafePointer(this)] {
334+
[comp = SeqView::SafePointer(this)] {
326335
if (comp) {
327336
comp->processAreaDragEnd();
328337
}
329338
},
330-
[comp = ScrollerBase::SafePointer(this)]
339+
[comp = SeqView::SafePointer(this)]
331340
(int index) {
332341
if (comp) {
333342
comp->editing(index);
@@ -374,19 +383,19 @@ SeqView::SeqView()
374383
comp->mouseWheelOutsideWithAlt(centerNum, thumbPer, deltaY, reversed);
375384
}
376385
},
377-
[comp = ScrollerBase::SafePointer(this)] {
386+
[comp = SeqView::SafePointer(this)] {
378387
if (comp) {
379388
comp->processAreaDragStart();
380389
}
381390
},
382-
[comp = ScrollerBase::SafePointer(this)]
391+
[comp = SeqView::SafePointer(this)]
383392
(int distanceX, int distanceY, bool moveX, bool moveY) {
384393
if (comp) {
385394
comp->processAreaDragTo(
386395
distanceX, distanceY, moveX, moveY);
387396
}
388397
},
389-
[comp = ScrollerBase::SafePointer(this)] {
398+
[comp = SeqView::SafePointer(this)] {
390399
if (comp) {
391400
comp->processAreaDragEnd();
392401
}

src/ui/component/sequencer/SeqView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class SeqView final
7979
void mouseDrag(const juce::MouseEvent& event) override;
8080
void mouseWheelMove(const juce::MouseEvent& event,
8181
const juce::MouseWheelDetails& wheel) override;
82+
void mouseExit(const juce::MouseEvent& event) override;
8283

8384
private:
8485
juce::OwnedArray<SeqTrackComponent> list;

0 commit comments

Comments
 (0)