-
Notifications
You must be signed in to change notification settings - Fork 1
/
audiotrapmainwindow.cpp
148 lines (133 loc) · 5.03 KB
/
audiotrapmainwindow.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
#include <QFileDialog>
#include "audiotrapmainwindow.h"
#include "ui_audiotrapmainwindow.h"
AudioTrapMainWindow::AudioTrapMainWindow(AudioTrapRecorder &recorder, QWidget *parent) : QMainWindow(parent),
ui(new Ui::AudioTrapMainWindow),
m_recorder(recorder),
m_levelMeter(m_recorder.getAudioLevelMeter()) {
ui->setupUi(this);
connect(&m_recorder, SIGNAL(activated()), this, SLOT(update()), Qt::UniqueConnection);
connect(&m_recorder, SIGNAL(deactivated()), this, SLOT(update()), Qt::UniqueConnection);
connect(&m_recorder, SIGNAL(recording(QString)), this, SLOT(update()), Qt::UniqueConnection);
connect(&m_recorder, SIGNAL(stopped(QString)), this, SLOT(update()), Qt::UniqueConnection);
connect(&m_levelMeter, SIGNAL(update(int)), this, SLOT(levelUpdate()), Qt::UniqueConnection);
update();
}
void AudioTrapMainWindow::show() {
QMainWindow::show();
}
void AudioTrapMainWindow::update() {
// input device
ui->inputDeviceComboBox->clear();
ui->inputDeviceComboBox->addItems(m_recorder.getDeviceNames());
QString deviceName = m_recorder.getDeviceName();
int deviceIndex = ui->inputDeviceComboBox->findText(deviceName);
ui->inputDeviceComboBox->setCurrentIndex(deviceIndex);
// containers
ui->containerFormatComboBox->clear();
ui->containerFormatComboBox->addItems(m_recorder.supportedContainers());
ui->containerFormatComboBox->setCurrentIndex(ui->containerFormatComboBox->findText(m_recorder.getContainerFormat()));
// outputDir
ui->outputDirLabel->setText(m_recorder.getOutputDir());
// thold settings
ui->lowTriggerSlider->setValue(qint32(m_levelMeter.getLowThreshold()*1000));
ui->highTriggerSlider->setValue(qint32(m_levelMeter.getHighThreshold()*1000));
// dampening
ui->dampeningSpinBox->setValue(m_levelMeter.getDampening());
// active/inactive
if(m_recorder.isActive()) {
ui->inputDeviceComboBox->setDisabled(true);
ui->activateButton->setText("Deactivate");
if(m_recorder.isRecording()) {
ui->recordingStatusLabel->setText("Recording");
}
else {
ui->recordingStatusLabel->setText("Stopped");
}
}
else {
ui->inputDeviceComboBox->setEnabled(true);
ui->activateButton->setText("Activate");
ui->recordingStatusLabel->setText("Deactivated");
}
}
void AudioTrapMainWindow::levelUpdate() {
qreal exp = m_levelMeter.channelExpAmplitude();
QList<qreal> channels = m_levelMeter.avgAmplitude();
if(channels.length() > 0) {
ui->channel0ProgressBar->setValue(qint32(channels[0]*100));
}
else {
ui->channel0ProgressBar->setValue(0);
}
if(channels.length() > 1) {
ui->channel1ProgressBar->setValue(qint32(channels[1]*100));
}
else {
ui->channel1ProgressBar->setValue(0);
}
ui->triggerLevelProgressBar->setValue(qint32(exp*100));
}
AudioTrapMainWindow::~AudioTrapMainWindow() {
delete ui;
}
void AudioTrapMainWindow::addMessage(const QString &msg) {
ui->statusTextEdit->append(msg);
}
void AudioTrapMainWindow::on_dampeningSpinBox_valueChanged(double arg1) {
(void)(arg1);
m_levelMeter.setDampening(ui->dampeningSpinBox->value());
}
void AudioTrapMainWindow::on_lowTriggerSlider_valueChanged(int value) {
(void)(value);
qint32 v = ui->lowTriggerSlider->value();
qreal rv = m_levelMeter.setLowThreshold(v/1000.0);
ui->lowTriggerSlider->setValue(qint32(rv*1000.0));
ui->highTriggerSlider->setValue(qint32(m_levelMeter.getHighThreshold()*1000));
}
void AudioTrapMainWindow::on_highTriggerSlider_valueChanged(int value) {
(void)(value);
qint32 v = ui->highTriggerSlider->value();
qreal rv = m_levelMeter.setHighThreshold(v/1000.0);
ui->highTriggerSlider->setValue(qint32(rv*1000));
ui->lowTriggerSlider->setValue(qint32(m_levelMeter.getLowThreshold()*1000));
}
/**
* Recorder may adjust passed in tholds so need to get return value and reset them.
*/
void AudioTrapMainWindow::setThresholds(quint32 l, quint32 h) {
qDebug() << "TODO" << l << h;
}
void AudioTrapMainWindow::on_activateButton_clicked() {
if(m_recorder.isActive()) {
m_recorder.deactivate();
ui->activateButton->setText("Activate");
}
else {
m_recorder.activate();
ui->activateButton->setText("Deactivate");
}
}
void AudioTrapMainWindow::on_activateButton_toggled(bool checked) {
if(checked) {
m_recorder.activate();
}
else {
m_recorder.deactivate();
}
}
void AudioTrapMainWindow::on_inputDeviceComboBox_activated(const QString &arg1) {
m_recorder.setDeviceName(arg1);
}
void AudioTrapMainWindow::on_outputDirButton_clicked() {
QString dir = QFileDialog::getExistingDirectory(this,
tr("Select Directory"),
QDir::homePath(),
QFileDialog::ShowDirsOnly| QFileDialog::DontResolveSymlinks
);
m_recorder.setOutputDir(dir);
ui->outputDirLabel->setText(m_recorder.getOutputDir());
}
void AudioTrapMainWindow::on_containerFormatComboBox_activated(const QString &arg1) {
m_recorder.setContainerFormat(arg1);
}