Chris@923: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@923: Chris@923: /* Chris@923: Sonic Visualiser Chris@923: An audio file viewer and annotation editor. Chris@923: Centre for Digital Music, Queen Mary, University of London. Chris@923: Chris@923: This program is free software; you can redistribute it and/or Chris@923: modify it under the terms of the GNU General Public License as Chris@923: published by the Free Software Foundation; either version 2 of the Chris@923: License, or (at your option) any later version. See the file Chris@923: COPYING included with this distribution for more information. Chris@923: */ Chris@923: Chris@923: #ifndef LEVEL_PAN_WIDGET_H Chris@923: #define LEVEL_PAN_WIDGET_H Chris@923: Chris@923: #include Chris@923: Chris@1303: #include "WheelCounter.h" Chris@1303: Chris@923: /** Chris@923: * A simple widget for coarse level and pan control. Chris@923: */ Chris@923: Chris@923: class LevelPanWidget : public QWidget Chris@923: { Chris@923: Q_OBJECT Chris@923: Chris@923: public: Chris@923: LevelPanWidget(QWidget *parent = 0); Chris@923: ~LevelPanWidget(); Chris@923: Chris@1201: /// Return level as a gain value. The basic level range is [0,1] but the Chris@1201: /// gain scale may go up to 4.0 Chris@923: float getLevel() const; Chris@923: Chris@923: /// Return pan as a value in the range [-1,1] Chris@923: float getPan() const; Chris@923: Chris@923: /// Find out whether the widget is editable Chris@923: bool isEditable() const; Chris@923: Chris@940: /// Discover whether the level range includes muting or not Chris@940: bool includesMute() const; Chris@940: Chris@929: /// Draw a suitably sized copy of the widget's contents to the given device Chris@929: void renderTo(QPaintDevice *, QRectF, bool asIfEditable) const; Chris@929: Chris@1406: QSize sizeHint() const override; Chris@929: Chris@923: public slots: Chris@1201: /// Set level. The basic level range is [0,1] but the scale may go Chris@1201: /// higher. The value will be rounded. Chris@923: void setLevel(float); Chris@923: Chris@1201: /// Set pan in the range [-1,1]. The value will be rounded Chris@923: void setPan(float); Chris@923: Chris@1177: /// Set left and right peak monitoring levels in the range [0,1] Chris@1177: void setMonitoringLevels(float, float); Chris@1177: Chris@923: /// Specify whether the widget is editable or read-only (default editable) Chris@923: void setEditable(bool); Chris@940: Chris@940: /// Specify whether the level range should include muting or not Chris@940: void setIncludeMute(bool); Chris@1249: Chris@1249: /// Reset to default values Chris@1249: void setToDefault(); Chris@923: Chris@1200: // public so it can be called from LevelPanToolButton (ew) Chris@1406: void wheelEvent(QWheelEvent *ev) override; Chris@1589: Chris@923: signals: Chris@1177: void levelChanged(float); // range [0,1] Chris@1177: void panChanged(float); // range [-1,1] Chris@923: Chris@1180: void mouseEntered(); Chris@1180: void mouseLeft(); Chris@1180: Chris@923: protected: Chris@1406: void mousePressEvent(QMouseEvent *ev) override; Chris@1406: void mouseMoveEvent(QMouseEvent *ev) override; Chris@1406: void mouseReleaseEvent(QMouseEvent *ev) override; Chris@1406: void paintEvent(QPaintEvent *ev) override; Chris@1406: void enterEvent(QEvent *) override; Chris@1406: void leaveEvent(QEvent *) override; Chris@923: Chris@923: void emitLevelChanged(); Chris@923: void emitPanChanged(); Chris@1301: Chris@1301: int m_minNotch; Chris@1301: int m_maxNotch; Chris@1301: int m_notch; Chris@923: int m_pan; Chris@1177: float m_monitorLeft; Chris@1177: float m_monitorRight; Chris@923: bool m_editable; Chris@1249: bool m_editing; Chris@940: bool m_includeMute; Chris@1301: bool m_includeHalfSteps; Chris@1303: Chris@1303: WheelCounter m_wheelCounter; Chris@923: Chris@1301: int clampNotch(int notch) const; Chris@1302: int clampPan(int pan) const; Chris@1177: Chris@1301: int audioLevelToNotch(float audioLevel) const; Chris@1301: float notchToAudioLevel(int notch) const; Chris@1301: Chris@1301: int audioPanToPan(float audioPan) const; Chris@1301: float panToAudioPan(int pan) const; Chris@1301: Chris@1301: int coordsToNotch(QRectF rect, QPointF pos) const; Chris@1301: int coordsToPan(QRectF rect, QPointF pos) const; Chris@1301: Chris@1306: QColor cellToColour(int cell) const; Chris@1177: Chris@929: QSizeF cellSize(QRectF) const; Chris@1301: QPointF cellCentre(QRectF, int row, int col) const; Chris@929: QSizeF cellLightSize(QRectF) const; Chris@1301: QRectF cellLightRect(QRectF, int row, int col) const; Chris@1301: QRectF cellOutlineRect(QRectF, int row, int col) const; Chris@929: double thinLineWidth(QRectF) const; Chris@1304: double cornerRadius(QRectF) const; Chris@923: }; Chris@923: Chris@923: #endif