2018-10-07 03:40:25 +00:00
|
|
|
#pragma once
|
2018-07-09 18:05:31 +00:00
|
|
|
|
2019-08-25 11:57:31 +00:00
|
|
|
#include <array>
|
|
|
|
#include <bitset>
|
2019-08-28 00:51:38 +00:00
|
|
|
#include <cstdint>
|
|
|
|
#include <unordered_map>
|
2019-08-25 11:57:31 +00:00
|
|
|
|
2018-08-06 04:20:42 +00:00
|
|
|
#include <QFrame>
|
2019-08-25 11:57:31 +00:00
|
|
|
#include <QPushButton>
|
2018-08-06 04:20:42 +00:00
|
|
|
#include <QStaticText>
|
|
|
|
#include <QSvgRenderer>
|
|
|
|
|
2019-08-28 00:51:38 +00:00
|
|
|
#include "EditorWidget.hpp"
|
|
|
|
#include "ProjectModel.hpp"
|
|
|
|
|
|
|
|
#include <amuse/AudioGroupPool.hpp>
|
|
|
|
#include <amuse/Common.hpp>
|
|
|
|
|
2018-08-06 04:20:42 +00:00
|
|
|
class KeymapEditor;
|
2019-08-28 00:51:38 +00:00
|
|
|
class QCheckBox;
|
|
|
|
class QScrollArea;
|
|
|
|
class QSpinBox;
|
2018-08-06 04:20:42 +00:00
|
|
|
|
2018-12-08 05:20:09 +00:00
|
|
|
class PaintButton : public QPushButton {
|
|
|
|
Q_OBJECT
|
2018-08-06 04:20:42 +00:00
|
|
|
public:
|
2018-12-08 05:20:09 +00:00
|
|
|
explicit PaintButton(QWidget* parent = Q_NULLPTR);
|
2019-08-25 04:37:47 +00:00
|
|
|
void mouseReleaseEvent(QMouseEvent* event) override { event->ignore(); }
|
|
|
|
void mouseMoveEvent(QMouseEvent* event) override { event->ignore(); }
|
|
|
|
void focusOutEvent(QFocusEvent* event) override { event->ignore(); }
|
|
|
|
void keyPressEvent(QKeyEvent* event) override { event->ignore(); }
|
2018-08-06 04:20:42 +00:00
|
|
|
};
|
|
|
|
|
2019-08-25 11:57:31 +00:00
|
|
|
using PaintPalette = std::array<QColor, 129>;
|
|
|
|
|
2018-12-08 05:20:09 +00:00
|
|
|
class KeymapView : public QWidget {
|
|
|
|
Q_OBJECT
|
|
|
|
friend class KeymapControls;
|
|
|
|
friend class KeymapEditor;
|
|
|
|
amuse::ObjToken<ProjectModel::KeymapNode> m_node;
|
|
|
|
QSvgRenderer m_octaveRenderer;
|
|
|
|
QSvgRenderer m_lastOctaveRenderer;
|
2019-08-25 11:57:31 +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;
|
|
|
|
QFont m_keyFont;
|
2019-08-25 11:57:31 +00:00
|
|
|
std::array<QStaticText, 128> m_keyTexts;
|
|
|
|
std::array<int, 128> m_keyPalettes;
|
2018-12-08 05:20:09 +00:00
|
|
|
KeymapEditor* getEditor() const;
|
|
|
|
int getKey(const QPoint& localPos) const;
|
2019-08-25 11:57:31 +00:00
|
|
|
void drawKey(QPainter& painter, const QRect& octaveRect, qreal penWidth, const PaintPalette& keyPalette, int o,
|
2018-12-08 05:20:09 +00:00
|
|
|
int k) const;
|
|
|
|
|
2018-08-06 04:20:42 +00:00
|
|
|
public:
|
2018-12-08 05:20:09 +00:00
|
|
|
explicit KeymapView(QWidget* parent = Q_NULLPTR);
|
2019-08-28 00:51:38 +00:00
|
|
|
~KeymapView() override;
|
|
|
|
|
2018-12-08 05:20:09 +00:00
|
|
|
void loadData(ProjectModel::KeymapNode* node);
|
|
|
|
void unloadData();
|
|
|
|
ProjectModel::INode* currentNode() const;
|
2018-08-06 04:20:42 +00:00
|
|
|
|
2019-08-25 04:37:47 +00:00
|
|
|
void paintEvent(QPaintEvent* ev) override;
|
|
|
|
void mousePressEvent(QMouseEvent* ev) override;
|
|
|
|
void mouseMoveEvent(QMouseEvent* ev) override;
|
|
|
|
void wheelEvent(QWheelEvent* event) override;
|
2018-08-06 04:20:42 +00:00
|
|
|
};
|
|
|
|
|
2018-12-08 05:20:09 +00:00
|
|
|
class KeymapControls : public QFrame {
|
|
|
|
Q_OBJECT
|
|
|
|
friend class KeymapView;
|
|
|
|
friend class KeymapEditor;
|
|
|
|
FieldProjectNode* m_macro;
|
|
|
|
QSpinBox* m_transpose;
|
|
|
|
QSpinBox* m_pan;
|
|
|
|
QCheckBox* m_surround;
|
|
|
|
QSpinBox* m_prioOffset;
|
|
|
|
PaintButton* m_paintButton;
|
|
|
|
bool m_enableUpdate = true;
|
|
|
|
KeymapEditor* getEditor() const;
|
|
|
|
void setPaintIdx(int idx);
|
|
|
|
void setKeymap(const amuse::Keymap& km);
|
|
|
|
|
2018-08-06 04:20:42 +00:00
|
|
|
public:
|
2018-12-08 05:20:09 +00:00
|
|
|
explicit KeymapControls(QWidget* parent = Q_NULLPTR);
|
2019-08-28 00:51:38 +00:00
|
|
|
~KeymapControls() override;
|
|
|
|
|
2018-12-08 05:20:09 +00:00
|
|
|
void loadData(ProjectModel::KeymapNode* node);
|
|
|
|
void unloadData();
|
2019-08-28 00:51:38 +00:00
|
|
|
|
2018-08-06 04:20:42 +00:00
|
|
|
public slots:
|
2018-12-08 05:20:09 +00:00
|
|
|
void controlChanged();
|
|
|
|
void paintButtonPressed();
|
2018-08-06 04:20:42 +00:00
|
|
|
};
|
2018-07-09 18:05:31 +00:00
|
|
|
|
2018-12-08 05:20:09 +00:00
|
|
|
class KeymapEditor : public EditorWidget {
|
|
|
|
Q_OBJECT
|
|
|
|
friend class KeymapView;
|
|
|
|
friend class KeymapControls;
|
|
|
|
QScrollArea* m_scrollArea;
|
|
|
|
KeymapView* m_kmView;
|
|
|
|
KeymapControls* m_controls;
|
2019-08-25 11:57:31 +00:00
|
|
|
PaintPalette m_paintPalette;
|
2018-12-08 05:20:09 +00:00
|
|
|
amuse::Keymap m_controlKeymap;
|
|
|
|
std::unordered_map<uint64_t, std::pair<int, int>> m_configToIdx;
|
|
|
|
std::bitset<129> m_idxBitmap;
|
|
|
|
bool m_inPaint = false;
|
|
|
|
void _touch();
|
|
|
|
void touchKey(int key, bool bulk = false);
|
|
|
|
void touchControl(const amuse::Keymap& km);
|
|
|
|
int allocateConfigIdx(uint64_t key);
|
|
|
|
void deallocateConfigIdx(uint64_t key);
|
|
|
|
int getConfigIdx(uint64_t key) const;
|
|
|
|
|
2018-07-09 18:05:31 +00:00
|
|
|
public:
|
2018-12-08 05:20:09 +00:00
|
|
|
explicit KeymapEditor(QWidget* parent = Q_NULLPTR);
|
2019-08-28 00:51:38 +00:00
|
|
|
~KeymapEditor() override;
|
|
|
|
|
2018-12-08 05:20:09 +00:00
|
|
|
bool loadData(ProjectModel::KeymapNode* node);
|
2019-08-25 04:37:47 +00:00
|
|
|
void unloadData() override;
|
|
|
|
ProjectModel::INode* currentNode() const override;
|
|
|
|
void keyPressEvent(QKeyEvent* event) override;
|
2018-07-09 18:05:31 +00:00
|
|
|
};
|