JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_KeyboardComponentBase.h
Go to the documentation of this file.
1 /*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce
27{
28
29//==============================================================================
41class JUCE_API KeyboardComponentBase : public Component,
43{
44public:
45 //==============================================================================
51 {
52 horizontalKeyboard,
53 verticalKeyboardFacingLeft,
54 verticalKeyboardFacingRight,
55 };
56
57 //==============================================================================
62 explicit KeyboardComponentBase (Orientation orientation);
63
65 ~KeyboardComponentBase() override = default;
66
67 //==============================================================================
69 void setKeyWidth (float widthInPixels);
70
72 float getKeyWidth() const noexcept { return keyWidth; }
73
75 void setScrollButtonWidth (int widthInPixels);
76
78 int getScrollButtonWidth() const noexcept { return scrollButtonWidth; }
79
81 void setOrientation (Orientation newOrientation);
82
84 Orientation getOrientation() const noexcept { return orientation; }
85
87 bool isHorizontal() const noexcept { return orientation == horizontalKeyboard; }
88
96 void setAvailableRange (int lowestNote, int highestNote);
97
102 int getRangeStart() const noexcept { return rangeStart; }
103
108 int getRangeEnd() const noexcept { return rangeEnd; }
109
116 void setLowestVisibleKey (int noteNumber);
117
122 int getLowestVisibleKey() const noexcept { return (int) firstKey; }
123
128 float getWhiteNoteLength() const noexcept;
129
131 void setBlackNoteLengthProportion (float ratio) noexcept;
132
134 float getBlackNoteLengthProportion() const noexcept { return blackNoteLengthRatio; }
135
140 float getBlackNoteLength() const noexcept;
141
143 void setBlackNoteWidthProportion (float ratio) noexcept;
144
146 float getBlackNoteWidthProportion() const noexcept { return blackNoteWidthRatio; }
147
152 float getBlackNoteWidth() const noexcept { return keyWidth * blackNoteWidthRatio; }
153
157 void setScrollButtonsVisible (bool canScroll);
158
159 //==============================================================================
168 {
169 upDownButtonBackgroundColourId = 0x1004000,
170 upDownButtonArrowColourId = 0x1004001
171 };
172
178 float getKeyStartPosition (int midiNoteNumber) const;
179
181 float getTotalKeyboardWidth() const noexcept;
182
185 struct JUCE_API NoteAndVelocity
186 {
187 int note;
188 float velocity;
189 };
190
196 NoteAndVelocity getNoteAndVelocityAtPosition (Point<float> position, bool includeChildComponents = false);
197
198 #ifndef DOXYGEN
200 [[deprecated ("This method has been deprecated in favour of getNoteAndVelocityAtPosition.")]]
201 int getNoteAtPosition (Point<float> p) { return getNoteAndVelocityAtPosition (p).note; }
202 #endif
203
205 Rectangle<float> getRectangleForKey (int midiNoteNumber) const;
206
207 //==============================================================================
219 void setOctaveForMiddleC (int octaveNumForMiddleC);
220
225 int getOctaveForMiddleC() const noexcept { return octaveNumForMiddleC; }
226
227 //==============================================================================
232
237 virtual void drawWhiteKey (int midiNoteNumber, Graphics& g, Rectangle<float> area) = 0;
238
243 virtual void drawBlackKey (int midiNoteNumber, Graphics& g, Rectangle<float> area) = 0;
244
248 virtual void drawUpDownButton (Graphics& g, int w, int h, bool isMouseOver, bool isButtonPressed, bool movesOctavesUp);
249
258 virtual Range<float> getKeyPosition (int midiNoteNumber, float keyWidth) const;
259
260 //==============================================================================
262 void paint (Graphics&) override;
264 void resized() override;
266 void mouseWheelMove (const MouseEvent&, const MouseWheelDetails&) override;
267
268private:
269 //==============================================================================
270 struct UpDownButton;
271
272 Range<float> getKeyPos (int midiNoteNumber) const;
273 NoteAndVelocity remappedXYToNote (Point<float>) const;
274 void setLowestVisibleKeyFloat (float noteNumber);
275
276 //==============================================================================
277 Orientation orientation;
278
279 float blackNoteLengthRatio = 0.7f, blackNoteWidthRatio = 0.7f;
280 float xOffset = 0.0f;
281 float keyWidth = 16.0f;
282 float firstKey = 12 * 4.0f;
283
284 int scrollButtonWidth = 12;
285 int rangeStart = 0, rangeEnd = 127;
286 int octaveNumForMiddleC = 3;
287
288 bool canScroll = true;
289 std::unique_ptr<Button> scrollDown, scrollUp;
290
291 //==============================================================================
293};
294
295} // namespace juce
Holds a list of ChangeListeners, and sends messages to them when instructed.
The base class for all JUCE user-interface objects.
A graphics context, used for drawing a component or image.
A base class for drawing a custom MIDI keyboard component.
bool isHorizontal() const noexcept
Returns true if the keyboard's orientation is horizontal.
virtual void drawKeyboardBackground(Graphics &g, Rectangle< float > area)=0
Use this method to draw the background of the keyboard that will be drawn under the white and black n...
float getKeyWidth() const noexcept
Returns the width that was set by setKeyWidth().
virtual void drawWhiteKey(int midiNoteNumber, Graphics &g, Rectangle< float > area)=0
Use this method to draw a white key of the keyboard in a given rectangle.
int getScrollButtonWidth() const noexcept
Returns the width that was set by setScrollButtonWidth().
virtual void drawBlackKey(int midiNoteNumber, Graphics &g, Rectangle< float > area)=0
Use this method to draw a black key of the keyboard in a given rectangle.
float getBlackNoteWidth() const noexcept
Returns the absolute width of the black notes.
~KeyboardComponentBase() override=default
Destructor.
int getRangeStart() const noexcept
Returns the first note in the available range.
int getRangeEnd() const noexcept
Returns the last note in the available range.
int getLowestVisibleKey() const noexcept
Returns the number of the first key shown in the component.
int getOctaveForMiddleC() const noexcept
This returns the value set by setOctaveForMiddleC().
Orientation getOrientation() const noexcept
Returns the keyboard's current direction.
Orientation
The direction of the keyboard.
ColourIds
Colour IDs to use to change the colour of the octave scroll buttons.
This structure is returned by the getNoteAndVelocityAtPosition() method.
Contains position and status information about a mouse event.
A pair of (x, y) coordinates.
Definition juce_Point.h:42
A general-purpose range object, that simply represents any linear range with a start and end point.
Definition juce_Range.h:40
Manages a rectangle and allows geometric operations to be performed on it.
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
This is a shorthand way of writing both a JUCE_DECLARE_NON_COPYABLE and JUCE_LEAK_DETECTOR macro for ...
JUCE Namespace.
Contains status information about a mouse wheel event.