Repository navigation
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
134 lines (116 loc) · 3.24 KB
/
Copy pathmainwindow.cpp
File metadata and controls
134 lines (116 loc) · 3.24 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include "mainwindow.hpp"
#include "ui_mainwindow.h"
#include <QThread>
#include <iostream>
#include <lo/lo.h>
#define MUTY_HAS_SMOOTH_SWTICHING 0
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
address = ui->hostTxt->text().toStdString();
port = ui->portTxt->text().toStdString();
path = ui->pathCB->currentText().toStdString();
minVal = (float) ui->minSB->value() / 100;
maxVal = (float) ui->maxSB->value() / 100;
ui->settingsWidget->setVisible(false);
adjustSize();
on_invertBtn_clicked();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::SendData(float value)
{
const auto addr = lo_address_new(address.c_str(), port.c_str());
const auto SendMessageImpl = [&](float val)
{
const auto msg = lo_message_new();
lo_message_add_float(msg, val);
lo_send_message(addr, path.c_str(), msg);
lo_message_free(msg);
ui->statusLabel->setText(QString("C=%0 MIN=%1 MAX=%2").arg(currentValue).arg(minVal).arg(maxVal));
};
#if MUTY_HAS_SMOOTH_SWTICHING
auto val = currentValue;
while (std::abs(val - value) >= 0.06)
{
SendMessageImpl(val);
QThread::msleep(10);
val += ((val >= value ? -1 : +1) * 0.05);
}
#endif
currentValue = value;
SendMessageImpl(value);
lo_address_free(addr);
}
void MainWindow::on_muteButton_pressed()
{
SendData(minVal);
}
void MainWindow::on_muteButton_released()
{
SendData(maxVal);
ui->stickyMuteButton->setChecked(false);
}
void MainWindow::on_minSlider_valueChanged(int value)
{
ui->minSB->setValue(value);
minVal = (float) value / 100;
}
void MainWindow::on_maxSlider_valueChanged(int value)
{
ui->maxSB->setValue(value);
maxVal = (float) value / 100;
}
void MainWindow::on_minSB_valueChanged(int arg1)
{
ui->minSlider->setValue(arg1);
minVal = (float) arg1 / 100;
}
void MainWindow::on_maxSB_valueChanged(int arg1)
{
ui->maxSlider->setValue(arg1);
maxVal = (float) arg1 / 100;
}
void MainWindow::on_hostTxt_textEdited(const QString &arg1)
{
address = arg1.toStdString();
}
void MainWindow::on_portTxt_textEdited(const QString &arg1)
{
port = arg1.toStdString();
}
void MainWindow::on_pathCB_currentTextChanged(const QString &arg1)
{
path = arg1.toStdString();
}
void MainWindow::on_settingsBtn_clicked()
{
const auto currentSize = this->size();
ui->settingsWidget->setVisible(!ui->settingsWidget->isVisible());
this->adjustSize();
this->resize(originalSize);
this->adjustSize();
originalSize = currentSize;
}
void MainWindow::on_invertBtn_clicked()
{
{
const float _min = minVal * 100;
const float _max = maxVal * 100;
// Switch MIN and MAX
ui->minSB->setValue(_max);
ui->minSlider->setValue(_max);
ui->maxSB->setValue(_min);
ui->maxSlider->setValue(_min);
}
// minVal and maxVal have been updated (Exchanged)
// If current is min, set to max (which is now exchanged into "minVal")
SendData((currentValue == maxVal) ? minVal : maxVal);
ui->stickyMuteButton->setChecked(currentValue == minVal);
}
void MainWindow::on_stickyMuteButton_clicked(bool checked)
{
SendData(checked ? minVal : maxVal);
}