MuseScore  3.4
Music composition and notation
pianotools.h
Go to the documentation of this file.
1 //=============================================================================
2 // MusE Score
3 // Linux Music Score Editor
4 //
5 // Copyright (C) 2011-2016 Werner Schweer and others
6 //
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License version 2.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 //=============================================================================
19 
20 #ifndef __PIANOTOOLS_H__
21 #define __PIANOTOOLS_H__
22 
23 #include "libmscore/note.h"
24 #include "libmscore/select.h"
25 
26 namespace Ms {
27 
28 class HPiano;
29 
30 //---------------------------------------------------------
31 // PianoKeyItem
32 //---------------------------------------------------------
33 
34 class PianoKeyItem : public QGraphicsPathItem {
35  int type;
36  int _pitch;
37  bool _pressed;
39  bool _selected;
41 
42  virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0);
43  virtual void mousePressEvent(QGraphicsSceneMouseEvent*);
44  virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent*);
45 
46  public:
47  PianoKeyItem(HPiano* , int p);
48  void setType(int val);
49  int pitch() { return _pitch; }
50  void setPressed(bool p) { _pressed = p; }
51  void setHighlighted(bool h) { _highlighted = h; }
52  void setSelected(bool s) { _selected = s; }
53  };
54 
55 //---------------------------------------------------------
56 // HPiano
57 //---------------------------------------------------------
58 
59 class HPiano : public QGraphicsView {
60  Q_OBJECT
61  int _firstKey;
62  int _lastKey;
63  //Pitches pressed due to playback
65  //Pitches pressed due to user interaction
66  QSet<int> _pressedPitches;
67  QList<PianoKeyItem*> keys;
68  qreal scaleVal;
69  virtual void wheelEvent(QWheelEvent*);
70  virtual bool event(QEvent* event);
71  bool gestureEvent(QGestureEvent *event);
72  void setScale(qreal);
73 
74  signals:
75  void keyPressed(int pitch, bool chord, int velo);
76  void keyReleased(int pitch, bool chord, int velo);
77 
78  public:
79  HPiano(QWidget* parent = 0);
80  friend class PianoKeyItem;
81  void setPressedPlaybackPitches(QSet<int> pitches);
82  void pressPitch(int pitch);
83  void releasePitch(int pitch);
84  void clearSelection();
85  void changeSelection(const Selection& selection);
86  void updateAllKeys();
87  virtual QSize sizeHint() const;
88 
89  public slots:
90  void setMaximum(bool top_level);
91  };
92 
93 //---------------------------------------------------------
94 // PianoTools
95 //---------------------------------------------------------
96 
97 class PianoTools : public QDockWidget {
98  Q_OBJECT
99 
101 
102  signals:
103  void keyPressed(int pitch, bool chord, int vel);
104  void keyReleased(int pitch, bool chord, int vel);
105 
106  protected:
107  virtual void changeEvent(QEvent *event);
108  void retranslate();
109 
110  public:
111  PianoTools(QWidget* parent = 0);
112  void pressPitch(int pitch) { _piano->pressPitch(pitch); }
113  void releasePitch(int pitch) { _piano->releasePitch(pitch); }
114  void setPlaybackNotes(QList<const Note*> notes);
115  void clearSelection();
116  void changeSelection(const Selection& selection);
117  };
118 
119 
120 } // namespace Ms
121 #endif
122 
HPiano * piano
Definition: pianotools.h:40
int pitch()
Definition: pianotools.h:49
Definition: select.h:136
QSet< int > _pressedPitches
Definition: pianotools.h:66
bool _highlighted
Definition: pianotools.h:38
Definition: pianotools.h:59
QSet< int > _pressedPlaybackPitches
Definition: pianotools.h:64
void releasePitch(int pitch)
Definition: pianotools.h:113
void releasePitch(int pitch)
Definition: pianotools.cpp:177
void setSelected(bool s)
Definition: pianotools.h:52
HPiano * _piano
Definition: pianotools.h:100
int _firstKey
Definition: pianotools.h:61
bool _pressed
Definition: pianotools.h:37
void setHighlighted(bool h)
Definition: pianotools.h:51
PianoKeyItem(HPiano *, int p)
Definition: pianotools.cpp:240
bool _selected
Definition: pianotools.h:39
void setType(int val)
Definition: pianotools.cpp:259
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0)
Definition: pianotools.cpp:383
int _pitch
Definition: pianotools.h:36
Definition: aeolus.cpp:26
void pressPitch(int pitch)
Definition: pianotools.cpp:167
Definition: pianotools.h:97
void setPressed(bool p)
Definition: pianotools.h:50
Definition of classes Note and NoteHead.
virtual void mousePressEvent(QGraphicsSceneMouseEvent *)
Definition: pianotools.cpp:360
void pressPitch(int pitch)
Definition: pianotools.h:112
int type
Definition: pianotools.h:35
QList< PianoKeyItem * > keys
Definition: pianotools.h:67
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *)
Definition: pianotools.cpp:372
int _lastKey
Definition: pianotools.h:62
Definition: pianotools.h:34
qreal scaleVal
Definition: pianotools.h:68