1 //=============================================================================
2 //  MusE Score
3 //  Linux Music Score Editor
4 //
5 //  Copyright (C) 2009 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 __PIANO_H__
21 #define __PIANO_H__
22 
23 namespace Ms {
24 
25 static const int pianoWidth = 40;
26 static const int keyHeight = 13;
27 
28 enum class PianoOrientation : char { HORIZONTAL, VERTICAL };
29 
30 //---------------------------------------------------------
31 //   Piano
32 //---------------------------------------------------------
33 
34 class Piano : public QWidget {
35       Q_OBJECT
36 
37       PianoOrientation _orientation;
38       double _ymag;
39       int _ypos;
40 
41       int yRange;
42       int curPitch;
43       int curKeyPressed;
44 
45       static QPixmap* octave;
46       static QPixmap* mk1;
47       static QPixmap* mk2;
48       static QPixmap* mk3;
49       static QPixmap* mk4;
50 
51       virtual void paintEvent(QPaintEvent*);
52       virtual void mousePressEvent(QMouseEvent*);
53       virtual void mouseReleaseEvent(QMouseEvent*);
54       virtual void mouseMoveEvent(QMouseEvent* event);
55       virtual void leaveEvent(QEvent*);
56 
57       int pitch2y(int pitch) const;
58       int y2pitch(int y) const;
59 
60    signals:
61       void pitchChanged(int);
62       void keyPressed(int pitch);
63       void keyReleased(int pitch);
64 
65    public slots:
66       void setYpos(int val);
67       void setMag(double, double);
68       void setPitch(int);
69 
70    public:
71       Piano(QWidget* parent = 0);
72       void setOrientation(PianoOrientation);
73       };
74 
75 
76 } // namespace Ms
77 #endif
78 
79