Chris@923
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@923
|
2
|
Chris@923
|
3 /*
|
Chris@923
|
4 Sonic Visualiser
|
Chris@923
|
5 An audio file viewer and annotation editor.
|
Chris@923
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@923
|
7
|
Chris@923
|
8 This program is free software; you can redistribute it and/or
|
Chris@923
|
9 modify it under the terms of the GNU General Public License as
|
Chris@923
|
10 published by the Free Software Foundation; either version 2 of the
|
Chris@923
|
11 License, or (at your option) any later version. See the file
|
Chris@923
|
12 COPYING included with this distribution for more information.
|
Chris@923
|
13 */
|
Chris@923
|
14
|
Chris@923
|
15 #ifndef LEVEL_PAN_WIDGET_H
|
Chris@923
|
16 #define LEVEL_PAN_WIDGET_H
|
Chris@923
|
17
|
Chris@923
|
18 #include <QWidget>
|
Chris@923
|
19
|
Chris@923
|
20 /**
|
Chris@923
|
21 * A simple widget for coarse level and pan control.
|
Chris@923
|
22 */
|
Chris@923
|
23
|
Chris@923
|
24 class LevelPanWidget : public QWidget
|
Chris@923
|
25 {
|
Chris@923
|
26 Q_OBJECT
|
Chris@923
|
27
|
Chris@923
|
28 public:
|
Chris@923
|
29 LevelPanWidget(QWidget *parent = 0);
|
Chris@923
|
30 ~LevelPanWidget();
|
Chris@923
|
31
|
Chris@1201
|
32 /// Return level as a gain value. The basic level range is [0,1] but the
|
Chris@1201
|
33 /// gain scale may go up to 4.0
|
Chris@923
|
34 float getLevel() const;
|
Chris@923
|
35
|
Chris@923
|
36 /// Return pan as a value in the range [-1,1]
|
Chris@923
|
37 float getPan() const;
|
Chris@923
|
38
|
Chris@923
|
39 /// Find out whether the widget is editable
|
Chris@923
|
40 bool isEditable() const;
|
Chris@923
|
41
|
Chris@940
|
42 /// Discover whether the level range includes muting or not
|
Chris@940
|
43 bool includesMute() const;
|
Chris@940
|
44
|
Chris@929
|
45 /// Draw a suitably sized copy of the widget's contents to the given device
|
Chris@929
|
46 void renderTo(QPaintDevice *, QRectF, bool asIfEditable) const;
|
Chris@929
|
47
|
Chris@929
|
48 QSize sizeHint() const;
|
Chris@929
|
49
|
Chris@923
|
50 public slots:
|
Chris@1201
|
51 /// Set level. The basic level range is [0,1] but the scale may go
|
Chris@1201
|
52 /// higher. The value will be rounded.
|
Chris@923
|
53 void setLevel(float);
|
Chris@923
|
54
|
Chris@1201
|
55 /// Set pan in the range [-1,1]. The value will be rounded
|
Chris@923
|
56 void setPan(float);
|
Chris@923
|
57
|
Chris@1177
|
58 /// Set left and right peak monitoring levels in the range [0,1]
|
Chris@1177
|
59 void setMonitoringLevels(float, float);
|
Chris@1177
|
60
|
Chris@923
|
61 /// Specify whether the widget is editable or read-only (default editable)
|
Chris@923
|
62 void setEditable(bool);
|
Chris@940
|
63
|
Chris@940
|
64 /// Specify whether the level range should include muting or not
|
Chris@940
|
65 void setIncludeMute(bool);
|
Chris@923
|
66
|
Chris@1200
|
67 // public so it can be called from LevelPanToolButton (ew)
|
Chris@1200
|
68 virtual void wheelEvent(QWheelEvent *ev);
|
Chris@1200
|
69
|
Chris@923
|
70 signals:
|
Chris@1177
|
71 void levelChanged(float); // range [0,1]
|
Chris@1177
|
72 void panChanged(float); // range [-1,1]
|
Chris@923
|
73
|
Chris@1180
|
74 void mouseEntered();
|
Chris@1180
|
75 void mouseLeft();
|
Chris@1180
|
76
|
Chris@923
|
77 protected:
|
Chris@923
|
78 virtual void mousePressEvent(QMouseEvent *ev);
|
Chris@923
|
79 virtual void mouseMoveEvent(QMouseEvent *ev);
|
Chris@923
|
80 virtual void mouseReleaseEvent(QMouseEvent *ev);
|
Chris@923
|
81 virtual void paintEvent(QPaintEvent *ev);
|
Chris@1180
|
82 virtual void enterEvent(QEvent *);
|
Chris@1180
|
83 virtual void leaveEvent(QEvent *);
|
Chris@923
|
84
|
Chris@923
|
85 void emitLevelChanged();
|
Chris@923
|
86 void emitPanChanged();
|
Chris@923
|
87
|
Chris@923
|
88 int m_level;
|
Chris@923
|
89 int m_pan;
|
Chris@1177
|
90 float m_monitorLeft;
|
Chris@1177
|
91 float m_monitorRight;
|
Chris@923
|
92 bool m_editable;
|
Chris@940
|
93 bool m_includeMute;
|
Chris@923
|
94
|
Chris@1177
|
95 static int audioLevelToLevel(float audioLevel, bool withMute);
|
Chris@1177
|
96 static float levelToAudioLevel(int level, bool withMute);
|
Chris@1177
|
97
|
Chris@1177
|
98 static int audioPanToPan(float audioPan);
|
Chris@1177
|
99 static float panToAudioPan(int pan);
|
Chris@1177
|
100
|
Chris@929
|
101 QSizeF cellSize(QRectF) const;
|
Chris@929
|
102 QPointF cellCentre(QRectF, int level, int pan) const;
|
Chris@929
|
103 QSizeF cellLightSize(QRectF) const;
|
Chris@929
|
104 QRectF cellLightRect(QRectF, int level, int pan) const;
|
Chris@929
|
105 double thinLineWidth(QRectF) const;
|
Chris@929
|
106 void toCell(QRectF, QPointF loc, int &level, int &pan) const;
|
Chris@923
|
107 };
|
Chris@923
|
108
|
Chris@923
|
109 #endif
|