-
Notifications
You must be signed in to change notification settings - Fork 0
/
sampleparams.cpp
109 lines (99 loc) · 3.09 KB
/
sampleparams.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
#include "sampleparams.h"
#include "ui_sampleparams.h"
SampleParams::SampleParams(Sample * sample, QWidget *parent) :
QWidget(parent),
ui(new Ui::SampleParams)
{
ui->setupUi(this);
mySample = sample;
connect(mySample, SIGNAL(started()), SLOT(onSampleStarted()));
connect(mySample, SIGNAL(stopped()), SLOT(onSampleStopped()));
updateSampleInfo();
connect(ui->volumeSlider, SIGNAL(sliderMoved(int)), mySample, SLOT(setVolume(int)));
connect(ui->volumeSlider, SIGNAL(valueChanged(int)), mySample, SLOT(setVolume(int)));
connect(ui->panDial, SIGNAL(sliderMoved(int)), mySample, SLOT(setPanning(int)));
connect(ui->panDial, SIGNAL(valueChanged(int)), mySample, SLOT(setPanning(int)));
connect(ui->keyCombo, SIGNAL(currentIndexChanged(int)), SLOT(onKeyComboChanged(int)));
connect(ui->noLoopRadio, SIGNAL(toggled(bool)), SLOT(onRadioChanged(bool)));
connect(ui->simpleLoopRadio, SIGNAL(toggled(bool)), SLOT(onRadioChanged(bool)));
connect(ui->autoLoopRadio, SIGNAL(toggled(bool)), SLOT(onRadioChanged(bool)));
connect(ui->muteButton, SIGNAL(toggled(bool)), mySample, SLOT(setMute(bool)));
}
SampleParams::~SampleParams()
{
delete ui;
}
void SampleParams::updateSampleInfo()
{
ui->namLabel->setText(mySample->name());
ui->filenameLabel->setText(mySample->fileName());
ui->durationLabel->setText(msToString(mySample->length()));
switch (mySample->loopType())
{
case Sample::SimpleLoop:
ui->simpleLoopRadio->setChecked(true);
break;
case Sample::AutoLoop:
ui->autoLoopRadio->setChecked(true);
break;
default:
ui->noLoopRadio->setChecked(true);
break;
}
QMap<Qt::Key, QString> kbdKeys = KeyboardKey::getKeysMap();
foreach(Qt::Key key, kbdKeys.keys())
ui->keyCombo->addItem("Key " + kbdKeys.value(key), int(key));
for (int i = 0; i < ui->keyCombo->count(); i++)
{
if ((Qt::Key)ui->keyCombo->itemData(i).toInt() == mySample->key().key())
{
ui->keyCombo->setCurrentIndex(i);
break;
}
}
ui->volumeSlider->setValue(mySample->getVolume());
ui->panDial->setValue(mySample->getPan());
}
void SampleParams::changeEvent(QEvent *e)
{
QWidget::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
QString SampleParams::msToString(unsigned int time)
{
// milliseconds
qint64 msecs = time % 1000;
qint64 secs = (time / 1000) % 60;
qint64 mins = (time / 1000) / 60;
return QString("%1:%2:%3").arg(mins).arg(secs, 2, 10, QChar('0')).arg(msecs, 3, 10, QChar('0'));
}
void SampleParams::onSampleStarted()
{
ui->namLabel->setStyleSheet("background-color: red;");
}
void SampleParams::onSampleStopped()
{
ui->namLabel->setStyleSheet("");
}
void SampleParams::onKeyComboChanged(int index)
{
mySample->setKey(KeyboardKey((Qt::Key)ui->keyCombo->itemData(index).toInt()));
}
void SampleParams::onRadioChanged(bool on)
{
if (on)
{
Sample::LoopType lt = Sample::NoLoop;;
if (sender() == ui->simpleLoopRadio)
lt = Sample::SimpleLoop;
if (sender() == ui->autoLoopRadio)
lt = Sample::AutoLoop;
mySample->setLoopType(lt);
}
}