-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp.orig
252 lines (198 loc) · 7.48 KB
/
mainwindow.cpp.orig
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
#include <opencv2/opencv.hpp>
#include "videoengine.h"
#include "colorkeyerhsv.h"
#include "QShortcut"
using namespace std;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
colorKeyerHSV(new ColorKeyerHSV())
{
QShortcut *spacebar = new QShortcut(QKeySequence(Qt::Key_Space),this);
ui->setupUi(this);
ui->midiControllerSpinBox->setValue(16);
connect(spacebar, SIGNAL(activated()), this, SLOT(toggleButtonBySpaceBar()));
ui->midiControllerValueDisplay->setPalette(Qt::green);
QStringList connections = midiOutput.connections(true);
ui->comboBox->addItems(connections);
connect(spacebar, SIGNAL(activated()), this, SLOT(toggleButtonBySpaceBar()));
<<<<<<< HEAD
midiOutput.open("Microsoft GS Wavetable Synth");
=======
midiOutput.open("Gesture2Midi");
ui->comboBox->setCurrentText("Gesture2Midi");
>>>>>>> Added Gesture2Midi Port as Default
midichannel = ui->midichannel->value();
colorKeyerHSV->setHueTolerance(ui->hueTolerance->value());
colorKeyerHSV->setHueValue(ui->hueValue->value());
colorKeyerHSV->setSaturationTolerance(ui->saturationTolerance->value());
colorKeyerHSV->setSaturationValue(ui->saturationValue->value());
videoEngine = new VideoEngine();
videoEngine -> setProcessor(colorKeyerHSV);
connect(videoEngine, SIGNAL(sendProcessedImage(const QImage&)), ui->videoLabel, SLOT(setImage(const QImage&)));
videoEngine -> openCamera();
videoEngine -> start();
}
MainWindow::~MainWindow()
{ delete colorKeyerHSV;
delete ui;
delete videoEngine;
}
void MainWindow::on_midichannel_valueChanged(int arg1)
{
midichannel = arg1;
}
void MainWindow::on_comboBox_activated(const QString &arg1)
{
midiOutput.open(arg1);
}
void MainWindow::on_checkBoxMedian_toggled(bool checked)
{
colorKeyerHSV->setMedianEnable(checked);
}
void MainWindow::on_checkBoxUseOpen_toggled(bool checked)
{
colorKeyerHSV->setOpeningEnable(checked);
}
void MainWindow::on_checkBoxMaskSmallRegions_toggled(bool checked)
{
colorKeyerHSV->setMaskSmallRegions(checked);
}
void MainWindow::on_hueTolerance_valueChanged(int value)
{
colorKeyerHSV->setHueTolerance(value);
}
void MainWindow::on_saturationTolerance_valueChanged(int value)
{
colorKeyerHSV->setSaturationTolerance(value);
}
void MainWindow::on_hueValue_valueChanged(int value)
{
colorKeyerHSV->setHueValue(value);
}
void MainWindow::on_saturationValue_valueChanged(int value)
{
colorKeyerHSV->setSaturationValue(value);
}
void MainWindow::sendMidiParameter(){
int midiControllerValue = colorKeyerHSV->handAnalyzer->midiParameterController->getMidiController();
midiOutput.sendController(midichannel,midiControllerNumber,midiControllerValue);
this->ui->midiControllerValueDisplay->display(midiControllerValue);
this->ui->midiControllerValueKnob->setValue(midiControllerValue);
if (this->colorKeyerHSV->handAnalyzer->isSchlag()){
int numberOfFingers = this->colorKeyerHSV->handAnalyzer->getNumberOfFingers();
vector<int> currentNotes = this->colorKeyerHSV->handAnalyzer->midiNoteController->getCurrentNotes(numberOfFingers);
vector<int> notesToTurnOff;
vector<int> notesToTurnOn;
if (!this->currentlyPlaying.empty()){
//Check which notes needs to be turned off etc.
vector<int> intersection = this->instersection(this->currentlyPlaying, currentNotes);
notesToTurnOff = this->difference( this->currentlyPlaying, intersection);
notesToTurnOn = this->difference(currentNotes, intersection);
} else {
for (int it : currentNotes){
notesToTurnOn.push_back(it);
}
}
// qDebug() << "Number of notes to turn on given by the midinoteController " << currentNotes.size();
// qDebug() << "Number off notes to turn on: " << notesToTurnOn.size();
for (int i = 0; i < notesToTurnOff.size(); i++){
// qDebug() << "Turn off note: " << notesToTurnOff.at(i);
this->midiOutput.sendNoteOff(midichannel, notesToTurnOff.at(i), 0);
}
for (int i = 0; i < notesToTurnOn.size(); i++){
// qDebug() << "Turn on note: " << notesToTurnOn.at(i);
this->midiOutput.sendNoteOn(midichannel, notesToTurnOn.at(i), 127);
}
this->currentlyPlaying.clear();
for (int i = 0; i < currentNotes.size(); i++){
this->currentlyPlaying.push_back(currentNotes.at(i));
}
}
}
vector<int> MainWindow::instersection(vector<int> v1, vector<int> v2)
{
vector<int> v3;
sort(v1.begin(), v1.end());
sort(v2.begin(), v2.end());
set_intersection(v1.begin(),v1.end(),v2.begin(),v2.end(),back_inserter(v3));
return v3;
}
vector<int> MainWindow::difference(vector<int> v1, vector<int> v2)
{
vector<int> v3;
sort(v1.begin(), v1.end());
sort(v2.begin(), v2.end());
set_difference(v1.begin(),v1.end(),v2.begin(),v2.end(),back_inserter(v3));
return v3;
}
void MainWindow::on_sendMidiControllerCheckbox_toggled(bool checked){
this->ui->midiMappingModeCheckBox->setDisabled(checked);
this->ui->midiMappingModeButton->setDisabled(checked);
if(checked){
connect(&timer, SIGNAL(timeout()),this, SLOT(sendMidiParameter()));
timer.start(50);
}else{
timer.stop();
for (int i = 0; i < this->currentlyPlaying.size(); i++){
this->midiOutput.sendNoteOff(midichannel, this->currentlyPlaying.at(i), 0);
}
this->currentlyPlaying.clear();
}
}
void MainWindow::on_midiMappingModeCheckBox_toggled(bool checked){
this->ui->sendMidiControllerCheckbox->setDisabled(checked);
if (checked) {
timer.stop();
for (int i = 0; i < this->currentlyPlaying.size(); i++){
this->midiOutput.sendNoteOff(midichannel, this->currentlyPlaying.at(i), 0);
}
this->currentlyPlaying.clear();
}
}
void MainWindow::on_midiMappingModeButton_pressed()
{
midiOutput.sendController(midichannel,midiControllerNumber,127);
}
void MainWindow::on_midiMappingModeButton_released()
{
midiOutput.sendController(midichannel,midiControllerNumber,0);
}
void MainWindow::toggleButtonBySpaceBar()
{
this->ui->midiMappingModeButton->animateClick();
}
void MainWindow::on_midiControllerSpinBox_valueChanged(int arg1)
{
midiControllerNumber = arg1;
}
void MainWindow::setUpCurrentNote(){
//Stop all playing notes at first
for (int i = 0; i < this->currentlyPlaying.size(); i++){
this->midiOutput.sendNoteOff(midichannel, this->currentlyPlaying.at(i), 0);
}
this->currentlyPlaying.clear();
//Then set the new note
string grundton = this->ui->rootComboBox->currentText().toStdString();
int oktave = this->ui->octaveSpinBox->value();
this->colorKeyerHSV->handAnalyzer->midiNoteController->setNoteForNoteWithOctave(grundton, oktave);
}
void MainWindow::on_rootComboBox_activated(const QString &arg1)
{
this->setUpCurrentNote();
}
void MainWindow::on_octaveSpinBox_valueChanged(int arg1)
{
this->setUpCurrentNote();
}
void MainWindow::on_presetComboBox_activated(const QString &arg1)
{
for (int i = 0; i < this->currentlyPlaying.size(); i++){
this->midiOutput.sendNoteOff(midichannel, this->currentlyPlaying.at(i), 0);
}
this->currentlyPlaying.clear();
this->colorKeyerHSV->handAnalyzer->midiNoteController->setPresetWithName(arg1.toStdString());
}