-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
253 lines (210 loc) · 7.61 KB
/
mainwindow.cpp
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
253
//----------------------------------------------------------------------
// VMouse - OpenCV Virtual Mouse (HCI)
// Copyright (C) 2014 Kunal Dawn <kunal.dawn@gmail.com>
// Copyright (C) 2014 Medha Devaraj <medha.devaraj@gmail.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//----------------------------------------------------------------------
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <iostream>
#include <QMessageBox>
#include <opencv2/opencv.hpp>
#include "systemconfiguration.h"
using namespace cv;
using namespace std;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
// create a new system configuration object
SystemConfiguration config;
// load the settings to system configuration
config.loadSettings();
ui->setupUi(this);
// configWindow = NULL;
configWindow = new ConfigurationWindow();
audioThread = new QThread;
connect(configWindow, SIGNAL(sr(int)), this, SLOT(set_sr(int)));
connect(configWindow, SIGNAL(bs(int)), this, SLOT(set_bs(int)));
qDebug() << "From main thread: " << QThread::currentThreadId();
qTimer = new QTimer(this);
timerHand = new QTimer(this);
}
void MainWindow::startAutoMode(int devId)
{
ui->inputCameraId->setDisabled(true);
cameraId = devId;
// initialize the capture device
captureDevice = VideoCapture(cameraId);
// check if the device is accessable
if(!captureDevice.isOpened())
{
// create a new message box
QMessageBox messageBox(this);
// show warning message
messageBox.warning(this, "Warning", "Can not open Camera Device", QMessageBox::Ok);
// return from this function as capture device is not correct
return;
}
// every thing is ok, start capturing
startProcessing();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_startBtn_clicked()
{
// read the camera id
cameraId = ui->inputCameraId->value();
// initialize the capture device
captureDevice = VideoCapture(cameraId);
// check if the device is accessable
if(!captureDevice.isOpened())
{
// create a new message box
QMessageBox messageBox(this);
// show warning message
messageBox.warning(this,"Warning","Can not open Camera Device",QMessageBox::Ok);
// return from this function as capture device is not correct
return;
}
// every thing is ok, start capturing
startProcessing();
}
void MainWindow::updateCameraFeedDisplay(QImage img1, QImage img2)
{
// display received images
ui->displayProcessedFrame->setPixmap(QPixmap::fromImage(img1).scaled(ui->displayProcessedFrame->width(), ui->displayProcessedFrame->height()));
ui->displayDetectedPoints->setPixmap(QPixmap::fromImage(img2).scaled(ui->displayDetectedPoints->width(), ui->displayDetectedPoints->height()));
}
void MainWindow::startProcessing()
{
// disable start brn
ui->startBtn->setEnabled(false);
// create a new camera capture object
cameraCapture = new CameraCapture(captureDevice);
cameraCapture->overlay.setOverlay(cameraCapture->overlay.generate12Tone(range));
// set up audio
configWindow->disableStuff();
connectParameters();
audioHandler = new Audio(sample_rate, buffer_size);
audioHandler->moveToThread(audioThread);
connect(qTimer, SIGNAL(timeout()), audioHandler, SLOT(run()));
connect(audioHandler, SIGNAL(initDone()), this, SLOT(connectFinalPoints()));
// connect the signal to receive images
connect(cameraCapture,SIGNAL(capturedNewFrame(QImage,QImage)),this,SLOT(updateCameraFeedDisplay(QImage,QImage)));
// start capturing process
cameraCapture->start();
audioThread->start();
qTimer->start(1);
}
void MainWindow::on_btn_configure_clicked()
{
// check if configuration window is already not initilized
if(!configWindow)
{
// create a new config window
configWindow = new ConfigurationWindow();
}
// show the c onfig wondow
configWindow->show();
// activate the window
configWindow->raise();
configWindow->activateWindow();
}
void MainWindow::connectFinalPoints()
{
// point the data translator to the final finger points
audioHandler->translator->finalPoints = cameraCapture->processor.getFinalPoints();
audioHandler->finalPoints = cameraCapture->processor.getFinalPoints();
connect(timerHand, SIGNAL(timeout()), audioHandler, SLOT(checkPlaying()));
connect(audioHandler->translator, SIGNAL(sendNumTones(int)), audioHandler->synth, SLOT(setOscNum(int)));
connect(qTimer, SIGNAL(timeout()), audioHandler, SLOT(run()));
timerHand->start(5);
}
void MainWindow::connectParameters()
{
connect(configWindow, SIGNAL(volume(float)), this, SLOT(set_volume(float)));
connect(configWindow, SIGNAL(pitch(float)), this, SLOT(set_pitch(float)));
connect(configWindow, SIGNAL(playing(bool)), this, SLOT(set_playing(bool)));
connect(configWindow, SIGNAL(numTones(int)), this, SLOT(set_numTone(int)));
connect(configWindow, SIGNAL(tn(int)), this, SLOT(set_tone(int)));
connect(configWindow, SIGNAL(rng(int)), this, SLOT(set_range(int)));
connect(configWindow, SIGNAL(quantized(bool)), this, SLOT(set_quantized(bool)));
connect(configWindow, SIGNAL(harmonic(int)), this, SLOT(set_harmonic(int)));
connect(configWindow, SIGNAL(divisions(int)), this, SLOT(set_divisions(int)));
connect(configWindow, SIGNAL(overlayOn(bool)), this, SLOT(set_overlayOn(bool)));
connect(configWindow, SIGNAL(overlayHeight(float)), this, SLOT(set_overlayHeight(float)));
}
void MainWindow::set_sr(int sr)
{
sample_rate = sr;
}
void MainWindow::set_bs(int bs)
{
buffer_size = bs;
}
void MainWindow::set_volume(float vol)
{
audioHandler->synth->masterVolume = vol;
}
void MainWindow::set_pitch(float pitch)
{
// float factor = Translator::getFactor(400)/1e4f;
// float freq = Translator::getDegreeFreq(20, pitch*factor);
audioHandler->translator->startingFreq = pitch;
}
void MainWindow::set_playing(bool playing)
{
audioHandler->synth->masterPlaying = !playing;
}
void MainWindow::set_numTone(int num)
{
audioHandler->translator->maxTones = num;
}
void MainWindow::set_tone(int tn)
{
audioHandler->synth->setTone(tn);
}
void MainWindow::set_range(int rng)
{
range = rng;
audioHandler->translator->range = rng;
cameraCapture->overlay.update();
cameraCapture->overlay.setOverlay(cameraCapture->overlay.generate12Tone(range));
}
void MainWindow::set_quantized(bool quant)
{
audioHandler->translator->quantizing = quant;
}
void MainWindow::set_harmonic(int harm)
{
audioHandler->translator->harmonic = harm;
}
void MainWindow::set_divisions(int div)
{
audioHandler->translator->divisions = div;
}
void MainWindow::set_overlayOn(bool overOn)
{
cameraCapture->overlay.showing = overOn;
}
void MainWindow::set_overlayHeight(float overHeight)
{
cameraCapture->overlay.heightFactor = overHeight;
cameraCapture->overlay.update();
cameraCapture->overlay.setOverlay(cameraCapture->overlay.generate12Tone(range));
}