2018-10-07 03:40:25 +00:00
|
|
|
#pragma once
|
2018-07-09 18:05:31 +00:00
|
|
|
|
2019-08-28 03:44:19 +00:00
|
|
|
#include <array>
|
|
|
|
|
2018-07-28 04:34:29 +00:00
|
|
|
#include <QSlider>
|
2019-08-28 00:51:38 +00:00
|
|
|
#include <QString>
|
|
|
|
#include <QSvgWidget>
|
2018-07-28 04:34:29 +00:00
|
|
|
#include <QWheelEvent>
|
2019-08-28 00:51:38 +00:00
|
|
|
#include <QWidget>
|
2018-08-06 04:20:42 +00:00
|
|
|
|
2019-08-28 03:44:19 +00:00
|
|
|
extern const std::array<QString, 7> NaturalKeyNames;
|
|
|
|
extern const std::array<QString, 5> SharpKeyNames;
|
|
|
|
extern const std::array<QString, 12> KeyStrings;
|
|
|
|
extern const std::array<int, 7> NaturalKeyNumbers;
|
|
|
|
extern const std::array<int, 5> SharpKeyNumbers;
|
2018-07-18 07:39:26 +00:00
|
|
|
|
|
|
|
class KeyboardWidget;
|
2019-08-28 00:51:38 +00:00
|
|
|
class StatusBarFocus;
|
2018-07-18 07:39:26 +00:00
|
|
|
|
2018-12-08 05:20:09 +00:00
|
|
|
class KeyboardOctave : public QSvgWidget {
|
|
|
|
Q_OBJECT
|
|
|
|
int m_octave;
|
2019-08-28 03:44:19 +00:00
|
|
|
std::array<QRectF, 7> m_natural;
|
|
|
|
std::array<QRectF, 5> m_sharp;
|
2018-12-08 05:20:09 +00:00
|
|
|
QTransform m_widgetToSvg;
|
|
|
|
|
2018-07-18 07:39:26 +00:00
|
|
|
public:
|
2018-12-08 05:20:09 +00:00
|
|
|
explicit KeyboardOctave(int octave, const QString& svgPath, QWidget* parent = Q_NULLPTR);
|
|
|
|
int getOctave() const { return m_octave; }
|
|
|
|
int getKey(const QPoint& localPos) const;
|
2019-08-25 04:37:47 +00:00
|
|
|
void resizeEvent(QResizeEvent* event) override;
|
2018-07-18 07:39:26 +00:00
|
|
|
};
|
2018-07-09 18:05:31 +00:00
|
|
|
|
2018-12-08 05:20:09 +00:00
|
|
|
class KeyboardWidget : public QWidget {
|
|
|
|
Q_OBJECT
|
2019-08-28 03:44:19 +00:00
|
|
|
std::array<KeyboardOctave*, 11> m_widgets{};
|
2018-12-08 05:20:09 +00:00
|
|
|
StatusBarFocus* m_statusFocus = nullptr;
|
|
|
|
int m_lastOctave = -1;
|
|
|
|
int m_lastKey = -1;
|
|
|
|
bool m_holding = false;
|
|
|
|
|
|
|
|
std::pair<int, int> _getOctaveAndKey(QMouseEvent* event) const;
|
|
|
|
void _startKey(int octave, int key);
|
|
|
|
void _stopKey();
|
|
|
|
void _moveOnKey(int octave, int key);
|
|
|
|
void _pressOnKey(int octave, int key);
|
2018-07-18 07:39:26 +00:00
|
|
|
|
2018-07-09 18:05:31 +00:00
|
|
|
public:
|
2018-12-08 05:20:09 +00:00
|
|
|
explicit KeyboardWidget(QWidget* parent = Q_NULLPTR);
|
2019-08-28 00:51:38 +00:00
|
|
|
~KeyboardWidget() override;
|
|
|
|
|
2018-12-08 05:20:09 +00:00
|
|
|
void setStatusFocus(StatusBarFocus* statusFocus) { m_statusFocus = statusFocus; }
|
2018-07-18 07:39:26 +00:00
|
|
|
|
2019-08-25 04:37:47 +00:00
|
|
|
void mouseMoveEvent(QMouseEvent* event) override;
|
|
|
|
void mousePressEvent(QMouseEvent* event) override;
|
|
|
|
void mouseReleaseEvent(QMouseEvent* event) override;
|
|
|
|
void enterEvent(QEvent* event) override;
|
|
|
|
void leaveEvent(QEvent* event) override;
|
|
|
|
void wheelEvent(QWheelEvent* event) override;
|
|
|
|
void showEvent(QShowEvent* event) override;
|
2018-07-28 04:34:29 +00:00
|
|
|
|
|
|
|
signals:
|
2018-12-08 05:20:09 +00:00
|
|
|
void notePressed(int key);
|
|
|
|
void noteReleased();
|
2018-07-28 04:34:29 +00:00
|
|
|
};
|
|
|
|
|
2018-12-08 05:20:09 +00:00
|
|
|
class KeyboardSlider : public QSlider {
|
|
|
|
Q_OBJECT
|
2018-07-28 04:34:29 +00:00
|
|
|
protected:
|
2018-12-08 05:20:09 +00:00
|
|
|
StatusBarFocus* m_statusFocus = nullptr;
|
|
|
|
virtual QString stringOfValue(int value) const = 0;
|
|
|
|
|
2018-07-28 04:34:29 +00:00
|
|
|
public:
|
2018-12-08 05:20:09 +00:00
|
|
|
explicit KeyboardSlider(QWidget* parent = Q_NULLPTR);
|
2019-08-28 00:51:38 +00:00
|
|
|
~KeyboardSlider() override;
|
|
|
|
|
2019-08-25 04:37:47 +00:00
|
|
|
void enterEvent(QEvent* event) override;
|
|
|
|
void leaveEvent(QEvent* event) override;
|
2018-12-08 05:20:09 +00:00
|
|
|
void setStatusFocus(StatusBarFocus* statusFocus);
|
2019-08-25 04:37:47 +00:00
|
|
|
void sliderChange(SliderChange change) override;
|
2018-07-09 18:05:31 +00:00
|
|
|
};
|
|
|
|
|
2018-12-08 05:20:09 +00:00
|
|
|
class VelocitySlider : public KeyboardSlider {
|
|
|
|
Q_OBJECT
|
2019-08-25 04:37:47 +00:00
|
|
|
QString stringOfValue(int value) const override;
|
2018-07-28 04:34:29 +00:00
|
|
|
|
2018-12-08 05:20:09 +00:00
|
|
|
public:
|
|
|
|
explicit VelocitySlider(QWidget* parent = Q_NULLPTR);
|
2018-07-28 04:34:29 +00:00
|
|
|
};
|
|
|
|
|
2018-12-08 05:20:09 +00:00
|
|
|
class ModulationSlider : public KeyboardSlider {
|
|
|
|
Q_OBJECT
|
2019-08-25 04:37:47 +00:00
|
|
|
QString stringOfValue(int value) const override;
|
2018-12-08 05:20:09 +00:00
|
|
|
|
2018-07-28 04:34:29 +00:00
|
|
|
public:
|
2018-12-08 05:20:09 +00:00
|
|
|
explicit ModulationSlider(QWidget* parent = Q_NULLPTR);
|
2018-07-28 04:34:29 +00:00
|
|
|
};
|
|
|
|
|
2018-12-08 05:20:09 +00:00
|
|
|
class PitchSlider : public KeyboardSlider {
|
|
|
|
Q_OBJECT
|
2019-08-25 04:37:47 +00:00
|
|
|
QString stringOfValue(int value) const override;
|
2018-12-08 05:20:09 +00:00
|
|
|
|
2018-07-28 04:34:29 +00:00
|
|
|
public:
|
2018-12-08 05:20:09 +00:00
|
|
|
explicit PitchSlider(QWidget* parent = Q_NULLPTR);
|
2019-08-25 04:37:47 +00:00
|
|
|
void mouseReleaseEvent(QMouseEvent* ev) override;
|
|
|
|
void wheelEvent(QWheelEvent* ev) override { ev->ignore(); }
|
2018-07-28 04:34:29 +00:00
|
|
|
};
|