Skip to content

Commit 54c438a

Browse files
Add midi editor Y pos indicator
1 parent 7e7a552 commit 54c438a

File tree

5 files changed

+60
-11
lines changed

5 files changed

+60
-11
lines changed

src/ui/component/editor/MIDIContentViewer.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55

66
MIDIContentViewer::MIDIContentViewer(
77
const WheelFunc& wheelFunc,
8-
const WheelAltFunc& wheelAltFunc)
9-
: wheelFunc(wheelFunc), wheelAltFunc(wheelAltFunc) {
8+
const WheelAltFunc& wheelAltFunc,
9+
const MouseYPosFunc& mouseYPosFunc,
10+
const MouseLeaveFunc& mouseLeaveFunc)
11+
: wheelFunc(wheelFunc), wheelAltFunc(wheelAltFunc),
12+
mouseYPosFunc(mouseYPosFunc), mouseLeaveFunc(mouseLeaveFunc) {
1013
/** Look And Feel */
1114
this->setLookAndFeel(
1215
LookAndFeelFactory::getInstance()->forMidiContent());
@@ -177,6 +180,21 @@ void MIDIContentViewer::paintOverChildren(juce::Graphics& g) {
177180
//}
178181
}
179182

183+
void MIDIContentViewer::mouseMove(const juce::MouseEvent& event) {
184+
/** Send Y Pos */
185+
this->mouseYPosFunc(event.position.getY());
186+
}
187+
188+
void MIDIContentViewer::mouseDrag(const juce::MouseEvent& event) {
189+
/** Send Y Pos */
190+
this->mouseYPosFunc(event.position.getY());
191+
}
192+
193+
void MIDIContentViewer::mouseExit(const juce::MouseEvent& event) {
194+
/** Send Mouse Exit */
195+
this->mouseLeaveFunc();
196+
}
197+
180198
void MIDIContentViewer::mouseWheelMove(
181199
const juce::MouseEvent& event,
182200
const juce::MouseWheelDetails& wheel) {

src/ui/component/editor/MIDIContentViewer.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@ class MIDIContentViewer final
99
public:
1010
using WheelFunc = std::function<void(float, bool)>;
1111
using WheelAltFunc = std::function<void(double, double, float, bool)>;
12+
using MouseYPosFunc = std::function<void(float)>;
13+
using MouseLeaveFunc = std::function<void()>;
1214
MIDIContentViewer(
1315
const WheelFunc& wheelFunc,
14-
const WheelAltFunc& wheelAltFunc);
16+
const WheelAltFunc& wheelAltFunc,
17+
const MouseYPosFunc& mouseYPosFunc,
18+
const MouseLeaveFunc& mouseLeaveFunc);
1519

1620
void update(int index, uint64_t ref);
1721
void updateTempoLabel();
@@ -25,12 +29,17 @@ class MIDIContentViewer final
2529
void paint(juce::Graphics& g) override;
2630
void paintOverChildren(juce::Graphics& g) override;
2731

32+
void mouseMove(const juce::MouseEvent& event) override;
33+
void mouseDrag(const juce::MouseEvent& event) override;
34+
void mouseExit(const juce::MouseEvent& event) override;
2835
void mouseWheelMove(const juce::MouseEvent& event,
2936
const juce::MouseWheelDetails& wheel) override;
3037

3138
private:
3239
const WheelFunc wheelFunc;
3340
const WheelAltFunc wheelAltFunc;
41+
const MouseYPosFunc mouseYPosFunc;
42+
const MouseLeaveFunc mouseLeaveFunc;
3443

3544
/** 0 for white key and 1 for black key */
3645
const std::array<int, 12> keyMasks{ 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0 };

src/ui/component/editor/MIDISourceEditor.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,17 @@ MIDISourceEditor::MIDISourceEditor() {
109109
if (comp) {
110110
comp->mouseWheelOutsideWithAlt(centerNum, thumbPer, deltaY, reversed);
111111
}
112+
},
113+
[comp = PianoComponent::SafePointer(this->piano.get())]
114+
(float posY) {
115+
if (comp) {
116+
comp->mouseYPosChangedOutside(posY);
117+
}
118+
},
119+
[comp = PianoComponent::SafePointer(this->piano.get())] {
120+
if (comp) {
121+
comp->mouseLeaveOutside();
122+
}
112123
});
113124
this->addAndMakeVisible(this->content.get());
114125

src/ui/component/editor/PianoComponent.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,8 @@ void PianoComponent::mouseUp(const juce::MouseEvent& event) {
162162
}
163163

164164
void PianoComponent::mouseMove(const juce::MouseEvent& event) {
165-
/** Check Mouse Hovered Key */
166-
std::tie(this->keyHovered, std::ignore) = this->findCurrentKey(event.position);
167-
168-
/** Repaint */
169-
this->repaint();
165+
this->mouseYPosChangedOutside(
166+
event.position.getY(), event.position.getX());
170167
}
171168

172169
void PianoComponent::mouseDrag(const juce::MouseEvent& event) {
@@ -184,14 +181,12 @@ void PianoComponent::mouseDrag(const juce::MouseEvent& event) {
184181
}
185182

186183
void PianoComponent::mouseExit(const juce::MouseEvent& event) {
187-
this->keyHovered = -1;
188-
189184
if (this->keyPressed != -1) {
190185
this->keyUpDownFunc(this->keyPressed, false, 0);
191186
this->keyPressed = -1;
192187
}
193188

194-
this->repaint();
189+
this->mouseLeaveOutside();
195190
}
196191

197192
void PianoComponent::mouseWheelMove(
@@ -208,6 +203,19 @@ void PianoComponent::mouseWheelMove(
208203
}
209204
}
210205

206+
void PianoComponent::mouseYPosChangedOutside(float posY, float posX) {
207+
/** Check Mouse Hovered Key */
208+
std::tie(this->keyHovered, std::ignore) = this->findCurrentKey(juce::Point{ posX, posY });
209+
210+
/** Repaint */
211+
this->repaint();
212+
}
213+
214+
void PianoComponent::mouseLeaveOutside() {
215+
this->keyHovered = -1;
216+
this->repaint();
217+
}
218+
211219
std::tuple<int, float> PianoComponent::findCurrentKey(const juce::Point<float>& pos) const {
212220
float posX = pos.getX(), posY = pos.getY();
213221

src/ui/component/editor/PianoComponent.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ class PianoComponent final : public juce::Component {
2525
void mouseWheelMove(const juce::MouseEvent& event,
2626
const juce::MouseWheelDetails& wheel) override;
2727

28+
void mouseYPosChangedOutside(float posY, float posX = 0);
29+
void mouseLeaveOutside();
30+
2831
private:
2932
const WheelFunc wheelFunc;
3033
const WheelAltFunc wheelAltFunc;

0 commit comments

Comments
 (0)