amuse/Editor/KeyboardWidget.hpp

108 lines
2.9 KiB
C++
Raw Normal View History

2018-10-07 03:40:25 +00:00
#pragma once
#include <array>
2018-07-28 04:34:29 +00:00
#include <QSlider>
#include <QString>
#include <QSvgWidget>
2018-07-28 04:34:29 +00:00
#include <QWheelEvent>
#include <QWidget>
2018-08-06 04:20:42 +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;
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;
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;
void resizeEvent(QResizeEvent* event) override;
2018-07-18 07:39:26 +00:00
};
2018-12-08 05:20:09 +00:00
class KeyboardWidget : public QWidget {
Q_OBJECT
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
public:
2018-12-08 05:20:09 +00:00
explicit KeyboardWidget(QWidget* parent = Q_NULLPTR);
~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
void mouseMoveEvent(QMouseEvent* event) override;
void mousePressEvent(QMouseEvent* event) override;
void mouseReleaseEvent(QMouseEvent* event) override;
2021-01-24 00:27:34 +00:00
void enterEvent(QEnterEvent* 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);
~KeyboardSlider() override;
2021-01-24 00:27:34 +00:00
void enterEvent(QEnterEvent* event) override;
void leaveEvent(QEvent* event) override;
2018-12-08 05:20:09 +00:00
void setStatusFocus(StatusBarFocus* statusFocus);
void sliderChange(SliderChange change) override;
};
2018-12-08 05:20:09 +00:00
class VelocitySlider : public KeyboardSlider {
Q_OBJECT
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
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
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);
void mouseReleaseEvent(QMouseEvent* ev) override;
void wheelEvent(QWheelEvent* ev) override { ev->ignore(); }
2018-07-28 04:34:29 +00:00
};