-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon_types.cpp
More file actions
78 lines (70 loc) · 1.51 KB
/
common_types.cpp
File metadata and controls
78 lines (70 loc) · 1.51 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
#include <QDebug>
#include "common_types.h"
ToneWaveForm::ToneWaveForm()
{
m_id = WAVE_UNKNOWN;
}
ToneWaveForm::ToneWaveForm(Id id)
{
setId(id);
}
ToneWaveForm::ToneWaveForm(QString name)
{
if (name == "sine") {
m_id = WAVE_SINE;
} else if (name == "square") {
m_id = WAVE_SQUARE;
} else if (name == "sawtooth") {
m_id = WAVE_SAWTOOTH;
} else if (name == "triangle") {
m_id = WAVE_TRIANGLE;
} else {
qWarning() << "Invalid format of waveform's name:" << name;
Q_ASSERT(false);
m_id = WAVE_UNKNOWN;
}
}
ToneWaveForm::Id ToneWaveForm::id() const
{
return m_id;
}
void ToneWaveForm::setId(Id id)
{
if ((id <= WAVE_UNKNOWN) || (id >= WAVE_LAST)) {
qWarning() << "Invalid signal waveform id:" << id;
Q_ASSERT(false);
id = WAVE_UNKNOWN;
}
m_id = id;
}
QString ToneWaveForm::getName() const
{
switch (m_id) {
case WAVE_UNKNOWN:
return "unknown";
case WAVE_SINE:
return "sine";
case WAVE_SQUARE:
return "square";
case WAVE_SAWTOOTH:
return "sawtooth";
case WAVE_TRIANGLE:
return "triangle";
case WAVE_LAST:
return "-----";
default:
qWarning() << "Invalid tone's waveform id:" << m_id;
Q_ASSERT(false);
return "sine";
}
}
QString ToneWaveForm::getName(Id id)
{
ToneWaveForm wave(id);
return wave.getName();
}
QDebug operator<<(QDebug d, const ToneWaveForm &tone)
{
d << tone.getName();
return d;
}