-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathknob.cpp
More file actions
45 lines (35 loc) · 1.12 KB
/
Copy pathknob.cpp
File metadata and controls
45 lines (35 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "knob.h"
#include <QLabel>
Knob::Knob(QQueue<QPair<int, int>>* cc_queue, const LiquidSFZ::CCInfo& cc_info, QWidget *parent): QVBoxLayout(parent)
{
this->_queue = cc_queue;
this->_cc = cc_info.cc();
setAlignment(Qt::AlignHCenter);
QDial* dial = new QDial(parent);
addWidget(dial);
QLabel* label = new QLabel(parent);
label->setAlignment(Qt::AlignHCenter);
addWidget(label);
if (cc_info.has_label()) {
label->setText(QString::fromStdString(cc_info.label()));
} else {
label->setText(QString::number(cc_info.cc()));
}
dial->setMaximum(127);
dial->setMinimum(0);
dial->setValue(cc_info.default_value());
connect(dial, &QDial::valueChanged, this, &Knob::onValueChanged);
}
void Knob::onValueChanged(int val) {
_queue->enqueue(QPair<int, int>(_cc, val));
}
void Knob::setValue(int val) {
QDial* dial = static_cast<QDial*>(itemAt(0)->widget());
dial->setValue(val);
}
Knob::~Knob() {
QDial* dial = static_cast<QDial*>(itemAt(0)->widget());
QLabel* label = static_cast<QLabel*>(itemAt(1)->widget());
delete dial;
delete label;
}