amuse/Editor/KeyboardWidget.hpp

102 lines
2.6 KiB
C++
Raw Normal View History

2018-10-07 03:40:25 +00:00
#pragma once
#include <QWidget>
2018-07-18 07:39:26 +00:00
#include <QSvgWidget>
2018-07-28 04:34:29 +00:00
#include <QSlider>
#include <QWheelEvent>
2018-07-18 07:39:26 +00:00
#include "StatusBarWidget.hpp"
2018-08-06 04:20:42 +00:00
#include "Common.hpp"
extern const QString NaturalKeyNames[7];
extern const QString SharpKeyNames[5];
extern const QString KeyStrings[12];
extern const int NaturalKeyNumbers[7];
extern const int SharpKeyNumbers[5];
2018-07-18 07:39:26 +00:00
class KeyboardWidget;
2018-12-08 05:20:09 +00:00
class KeyboardOctave : public QSvgWidget {
Q_OBJECT
int m_octave;
QRectF m_natural[7];
QRectF m_sharp[5];
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);
2018-07-18 07:39:26 +00:00
};
2018-12-08 05:20:09 +00:00
class KeyboardWidget : public QWidget {
Q_OBJECT
KeyboardOctave* m_widgets[11];
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);
void setStatusFocus(StatusBarFocus* statusFocus) { m_statusFocus = statusFocus; }
2018-07-18 07:39:26 +00:00
2018-12-08 05:20:09 +00:00
void mouseMoveEvent(QMouseEvent* event);
void mousePressEvent(QMouseEvent* event);
void mouseReleaseEvent(QMouseEvent* event);
void enterEvent(QEvent* event);
void leaveEvent(QEvent* event);
void wheelEvent(QWheelEvent* event);
void showEvent(QShowEvent* event);
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);
void enterEvent(QEvent* event);
void leaveEvent(QEvent* event);
void setStatusFocus(StatusBarFocus* statusFocus);
void sliderChange(SliderChange change);
};
2018-12-08 05:20:09 +00:00
class VelocitySlider : public KeyboardSlider {
Q_OBJECT
QString stringOfValue(int value) const;
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;
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;
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);
void wheelEvent(QWheelEvent* ev) { ev->ignore(); }
2018-07-28 04:34:29 +00:00
};