9 #include "vstgui/lib/vstguifwd.h" 10 #include "vstgui/lib/ccolor.h" 11 #include "vstgui/lib/cview.h" 12 #include "vstgui/lib/dispatchlist.h" 13 #include "vstgui/lib/itouchevent.h" 24 using NoteIndex = int16_t;
25 using NumNotes = uint8_t;
27 static constexpr NumNotes MaxNotes = 128;
42 void setKeyPressed (NoteIndex note,
bool state);
44 virtual void setKeyRange (NoteIndex startNote, NumNotes numKeys);
45 NoteIndex getKeyRangeStart ()
const {
return startNote; }
46 NumNotes getNumKeys ()
const {
return numKeys; }
47 NumNotes getNumWhiteKeys ()
const;
49 void setWhiteKeyWidth (CCoord width);
50 void setBlackKeyWidth (CCoord width);
51 void setBlackKeyHeight (CCoord height);
52 void setLineWidth (CCoord width);
53 CCoord getWhiteKeyWidth ()
const {
return whiteKeyWidth; }
54 CCoord getBlackKeyWidth ()
const {
return blackKeyWidth; }
55 CCoord getBlackKeyHeight ()
const {
return blackKeyHeight; }
56 CCoord getLineWidth ()
const {
return lineWidth; }
58 void setFrameColor (
CColor color);
59 void setFontColor (
CColor color);
60 void setWhiteKeyColor (
CColor color);
61 void setWhiteKeyPressedColor (
CColor color);
62 void setBlackKeyColor (
CColor color);
63 void setBlackKeyPressedColor (
CColor color);
64 CColor getFrameColor ()
const {
return frameColor; }
65 CColor getFontColor ()
const {
return fontColor; }
66 CColor getWhiteKeyColor ()
const {
return whiteKeyColor; }
67 CColor getWhiteKeyPressedColor ()
const {
return whiteKeyPressedColor; }
68 CColor getBlackKeyColor ()
const {
return blackKeyColor; }
69 CColor getBlackKeyPressedColor ()
const {
return blackKeyPressedColor; }
72 CFontDesc* getNoteNameFont ()
const {
return noteNameFont; }
73 void setDrawNoteText (
bool state);
74 bool getDrawNoteText ()
const {
return drawNoteText; }
76 void setBitmap (BitmapID bID,
CBitmap* bitmap);
77 CBitmap* getBitmap (BitmapID bID)
const;
79 void setWhiteKeyBitmapInset (
const CRect& inset);
80 void setBlackKeyBitmapInset (
const CRect& inset);
82 const CRect& getNoteRect (NoteIndex note)
const {
return noteRectCache[note]; }
83 bool isWhiteKey (NoteIndex note)
const;
90 using NoteRectCache = std::array<CRect, MaxNotes>;
92 void invalidNote (NoteIndex note);
94 NoteIndex pointToNote (
const CPoint& p,
bool ignoreY)
const;
95 const NoteRectCache& getNoteRectCache ()
const {
return noteRectCache; }
98 void drawNote (
CDrawContext* context,
CRect& rect, NoteIndex note,
bool isWhite)
const;
99 CRect calcNoteRect (NoteIndex note)
const;
100 void updateNoteRectCache ()
const;
101 void createBitmapCache ();
104 std::array<SharedPointer<CBitmap>,
static_cast<size_t> (BitmapID::NumBitmaps)>;
111 CRect whiteKeyBitmapInset;
112 CRect blackKeyBitmapInset;
114 CCoord whiteKeyWidth {30};
115 CCoord blackKeyWidth {20};
116 CCoord blackKeyHeight {20};
117 CCoord lineWidth {1.};
119 CColor frameColor {kBlackCColor};
120 CColor fontColor {kBlackCColor};
121 CColor whiteKeyColor {kWhiteCColor};
122 CColor whiteKeyPressedColor {kGreyCColor};
123 CColor blackKeyColor {kBlackCColor};
124 CColor blackKeyPressedColor {kGreyCColor};
126 NumNotes numKeys {88};
127 NoteIndex startNote {21};
128 bool drawNoteText {
false};
129 mutable bool noteRectCacheInvalid {
true};
130 mutable NoteRectCache noteRectCache;
131 std::bitset<MaxNotes> keyPressed {};
154 bool operator!= (
const Range& r)
const 156 return position != r.position || length != r.length;
164 void setKeyRange (NoteIndex startNote, NumNotes numKeys)
override;
165 void setSelectionRange (
const Range& range);
166 void setSelectionMinMax (NumNotes minRange, NumNotes maxRange);
167 const Range& getSelectionRange ()
const {
return selectionRange; }
168 NumNotes getSelectionMin ()
const {
return rangeMin; }
169 NumNotes getSelectionMax ()
const {
return rangeMax; }
170 NumNotes getNumWhiteKeysSelected ()
const;
172 void registerKeyRangeChangedListener (IKeyboardViewKeyRangeChangedListener* listener);
173 void unregisterKeyRangeChangedListener (IKeyboardViewKeyRangeChangedListener* listener);
177 DispatchList<IKeyboardViewKeyRangeChangedListener*> listeners;
179 Range selectionRange {0, 12};
180 NumNotes rangeMin {12};
181 NumNotes rangeMax {24};
183 #if VSTGUI_TOUCH_EVENT_HANDLING 184 void onTouchEvent (ITouchEvent& event)
override;
185 bool wantsMultiTouchEvents ()
const override;
186 void onTouchBegin (
const ITouchEvent::TouchPair& touch, ITouchEvent& event);
187 void onTouchMove (
const ITouchEvent::TouchPair& touch, ITouchEvent& event);
189 enum TouchMode {kUnknown, kMoveRange, kChangeRangeFront, kChangeRangeBack};
191 Range selectionRangeOnTouchStart;
192 int32_t touchIds[2] {-1};
193 TouchMode touchMode {kUnknown};
194 NoteIndex touchStartNote[2];
196 CMouseEventResult onMouseDown (CPoint& where,
const CButtonState& buttons)
override;
197 CMouseEventResult onMouseMoved (CPoint& where,
const CButtonState& buttons)
override;
198 CMouseEventResult onMouseUp (CPoint& where,
const CButtonState& buttons)
override;
199 CMouseEventResult onMouseCancel ()
override;
201 Range moveStartRange;
202 NoteIndex moveStartNote {-1};
209 using NoteIndex = KeyboardViewBase::NoteIndex;
211 virtual int32_t onNoteOn (NoteIndex note,
double xPos,
double yPos) = 0;
212 virtual void onNoteOff (NoteIndex note, int32_t noteID) = 0;
214 virtual void onNoteModulation (int32_t noteID,
double xPos,
double yPos) = 0;
222 int32_t onNoteOn (NoteIndex note,
double xPos,
double yPos)
override {
return -1; }
223 void onNoteOff (NoteIndex note, int32_t noteID)
override {}
224 void onNoteModulation (int32_t noteID,
double xPos,
double yPos)
override {}
235 double calcYParameter (NoteIndex note, CCoord y)
const;
236 double calcXParameter (NoteIndex note, CCoord x)
const;
237 #if VSTGUI_TOUCH_EVENT_HANDLING 238 bool wantsMultiTouchEvents ()
const override {
return true; }
239 void onTouchEvent (ITouchEvent& event)
override;
240 void onTouchBegin (
const ITouchEvent::TouchPair& touch, ITouchEvent& event);
241 void onTouchMove (
const ITouchEvent::TouchPair& touch, ITouchEvent& event);
242 void onTouchEnd (
const ITouchEvent::TouchPair& touch, ITouchEvent& event);
248 NoteTouch (NoteIndex note) : note (note), noteID (-1) {}
251 std::map<int32_t, NoteTouch> noteTouches;
254 void doNoteOn (NoteIndex note,
double yPos,
double xPos);
259 CMouseEventResult onMouseCancel ()
override;
261 NoteIndex pressedNote {-1};
font class
Definition: cfont.h:31
Rect structure.
Definition: crect.h:17
Definition: keyboardview.h:136
bool sizeToFit() override
resize view to optimal size
Definition: keyboardview.cpp:562
Definition: keyboardview.h:207
Definition: vstguibase.h:299
A drawing context encapsulates the drawing context of the underlying OS.
Definition: cdrawcontext.h:29
void setViewSize(const CRect &rect, bool invalid=true) override
set views size
Definition: keyboardview.cpp:555
RGBA Color structure.
Definition: ccolor.h:15
Definition: keyboardview.h:21
Definition: keyboardview.h:144
Encapsulates various platform depended kinds of bitmaps.
Definition: cbitmap.h:21
Definition: keyboardview.h:228
Definition: customcontrols.cpp:8
void drawRect(CDrawContext *context, const CRect &dirtyRect) override
called if the view should draw itself
Definition: keyboardview.cpp:769
Base Class of all view objects.
Definition: cview.h:44
Definition: keyboardview.h:147
virtual void invalid()
mark whole view as invalid
Definition: cview.h:63
void drawRect(CDrawContext *context, const CRect &dirtyRect) override
called if the view should draw itself
Definition: keyboardview.cpp:265
Definition: keyboardview.h:220
Point structure.
Definition: cpoint.h:17