Debian Codegraph @

BambooTracker/gui/instrument_editor/fm_operator_table.hpp

raw
1 /*
2 * Copyright (C) 2018-2021 Rerrah
3 *
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use,
8 * copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following
11 * conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26 #ifndef FM_OPERATOR_TABLE_HPP
27 #define FM_OPERATOR_TABLE_HPP
28
29 #include <unordered_map>
30 #include <memory>
31 #include <vector>
32 #include <QFrame>
33 #include <QShowEvent>
34 #include <QResizeEvent>
35 #include <QString>
36 #include <QImage>
37 #include <QPainter>
38 #include <QPointF>
39 #include "gui/labeled_vertical_slider.hpp"
40 #include "gui/color_palette.hpp"
41 #include "enum_hash.hpp"
42
43 namespace Ui {
44 class FMOperatorTable;
45 enum class FMOperatorParameter;
46 }
47
48 class FMOperatorTable : public QFrame
49 {
50 Q_OBJECT
51
52 public:
53 explicit FMOperatorTable(QWidget *parent = nullptr);
54 ~FMOperatorTable() override;
55
56 void setEnvelopeSetNames(std::vector<QString> list);
57 void setColorPalette(std::shared_ptr<ColorPalette> palette);
58
59 void setOperatorNumber(int n);
60 int operatorNumber() const;
61
62 void setValue(Ui::FMOperatorParameter param, int value);
63 void setGroupEnabled(bool enabled);
64
65 void setDTDisplayType(bool useNegative);
66
67 QString toString() const;
68
69 protected:
70 bool eventFilter(QObject* obj, QEvent* event) override;
71 void showEvent(QShowEvent*) override;
72 void resizeEvent(QResizeEvent*) override;
73
74 signals:
75 void operatorValueChanged(Ui::FMOperatorParameter param, int value);
76 void operatorEnableChanged(bool enable);
77 void copyEnvelopePressed();
78 void pasteEnvelopePressed();
79 void pasteEnvelopeFromPressed(int typenum);
80 void copyOperatorPressed(int num);
81 void pasteOperatorPressed(int num);
82
83 private slots:
84 void on_ssgegCheckBox_stateChanged(int);
85 void on_groupBox_toggled(bool arg1);
86 void on_groupBox_customContextMenuRequested(const QPoint &pos);
87
88 private:
89 Ui::FMOperatorTable *ui;
90 std::shared_ptr<ColorPalette> palette_;
91 int number_;
92 std::unordered_map<Ui::FMOperatorParameter, LabeledVerticalSlider*> sliderMap_;
93 std::vector<QString> envelopeTypes_;
94 bool isDTNegative_;
95 bool isIgnoreEvent_;
96
97 // Envelope graph
98 QImage envmap_;
99 static constexpr int ENV_H_ = 127;
100 static constexpr int ENV_W_ = 200;
101 static constexpr int SSGEG_H_ = 35;
102 static constexpr int ENV_LINE_W_ = 2;
103 static constexpr int ENV_LINE_T_ = 1;
104 double xr_, yr_;
105
106 void resizeGraph();
107 void repaintGraph();
108
109 inline void drawLine(QPainter& painter, qreal x1, qreal y1, qreal x2, qreal y2)
110 {
111 painter.drawLine(ENV_LINE_W_ + x1 * xr_ + 1, ENV_LINE_W_ + y1 * yr_ + 1,
112 ENV_LINE_W_ + x2 * xr_ + 1, ENV_LINE_W_ + y2 * yr_ + 1);
113 }
114
115 inline void drawLine(QPainter& painter, const QPointF& p1, const QPointF& p2)
116 {
117 drawLine(painter, p1.x(), p1.y(), p2.x(), p2.y());
118 }
119
120 inline void drawLines(QPainter& painter, const QVector<QPointF>& ps)
121 {
122 for (int i = 1; i < ps.size(); ++i) {
123 drawLine(painter, ps[i-1], ps[i]);
124 }
125 }
126 };
127
128 namespace Ui {
129 enum class FMOperatorParameter
130 {
131 AR, DR, SR, RR, SL, TL, KS, ML, DT, AM, SSGEG
132 };
133 }
134
135 #endif // FM_OPERATOR_TABLE_HPP