Commit d75742e49393115a8b051a02df7c613ecaffb96c
1 parent
1d848d8450
Exists in
master
and in
2 other branches
음향 효과 개선
- QSound, QSoundEffect 대신 aplay 사용. 해당 클래스는 음향이 깨지는 문제가 있음
Showing
5 changed files
with
141 additions
and
46 deletions
Show diff stats
app/gui/oven_control/manualcookwindow.cpp
... | ... | @@ -154,7 +154,8 @@ ManualCookWindow::ManualCookWindow(QWidget *parent, Define::Mode mode) : |
154 | 154 | updateViewTimer.start(100); |
155 | 155 | |
156 | 156 | foreach (QPushButton *button, findChildren<QPushButton *>()) |
157 | - connect(button, &QPushButton::pressed, SoundPlayer::playClick); | |
157 | + if (button != ui->runStopButton) | |
158 | + connect(button, &QPushButton::pressed, SoundPlayer::playClick); | |
158 | 159 | |
159 | 160 | QTimer::singleShot(0, this, SLOT(setupAnimation())); |
160 | 161 | |
... | ... | @@ -906,6 +907,8 @@ void ManualCookWindow::on_runStopButton_clicked() |
906 | 907 | stop(); |
907 | 908 | else if (oven->time() > 0) |
908 | 909 | start(); |
910 | + else | |
911 | + SoundPlayer::playClick(); | |
909 | 912 | |
910 | 913 | updateView(); |
911 | 914 | } | ... | ... |
app/gui/oven_control/oven_control.pro
app/gui/oven_control/resources.qrc
... | ... | @@ -533,11 +533,6 @@ |
533 | 533 | <file>images/config/102_icon_play_ov.png</file> |
534 | 534 | <file>images/config/102_icon_play.png</file> |
535 | 535 | <file>images/config/102_usb_icon.png</file> |
536 | - <file>sounds/error1.wav</file> | |
537 | - <file>sounds/error2.wav</file> | |
538 | - <file>sounds/start.wav</file> | |
539 | - <file>sounds/stop.wav</file> | |
540 | - <file>sounds/button.wav</file> | |
541 | 536 | <file>images/config/100_fav_pannel_icon_ov.png</file> |
542 | 537 | <file>images/config/100_fav_pannel_icon.png</file> |
543 | 538 | <file>images/config/105_icon_cancel_ov.png</file> | ... | ... |
app/gui/oven_control/soundplayer.cpp
... | ... | @@ -2,6 +2,7 @@ |
2 | 2 | #include "system.h" |
3 | 3 | |
4 | 4 | #include "config.h" |
5 | +#include "unistd.h" | |
5 | 6 | |
6 | 7 | namespace { |
7 | 8 | QThread playThread; |
... | ... | @@ -9,50 +10,54 @@ QThread playThread; |
9 | 10 | |
10 | 11 | SoundPlayWorker::SoundPlayWorker() |
11 | 12 | { |
12 | - current = 0; | |
13 | - click = 0; | |
13 | + repeat_ = false; | |
14 | + proc = new QProcess(this); | |
15 | + | |
16 | + connect(proc, SIGNAL(finished(int)), SLOT(onFinished())); | |
14 | 17 | } |
15 | 18 | |
16 | 19 | void SoundPlayWorker::play(const QString &filename) |
17 | 20 | { |
18 | - if (current && !current->isFinished()) | |
19 | - current->stop(); | |
20 | - | |
21 | - if (click && click->isPlaying()) | |
22 | - click->stop(); | |
23 | - | |
24 | - if (map.contains(filename)) | |
25 | - current = map.value(filename); | |
26 | - else | |
21 | + if (proc->state() != QProcess::NotRunning) | |
27 | 22 | { |
28 | - current = new QSound(filename); | |
29 | - map[filename] = current; | |
23 | + proc->terminate(); | |
24 | + proc->waitForFinished(); | |
30 | 25 | } |
31 | 26 | |
32 | - current->play(); | |
27 | + proc->start(QString("aplay"), QStringList(filename)); | |
28 | + proc->waitForStarted(); | |
33 | 29 | } |
34 | 30 | |
35 | 31 | void SoundPlayWorker::playClick() |
36 | 32 | { |
37 | - if (current && !current->isFinished()) | |
38 | - current->stop(); | |
33 | + play("/falinux/sounds/button.wav"); | |
34 | +} | |
39 | 35 | |
40 | - if (click && click->isPlaying()) | |
41 | - click->stop(); | |
36 | +void SoundPlayWorker::setVolume(int volume) | |
37 | +{ | |
38 | + System::setVolume(volume); | |
39 | +} | |
40 | + | |
41 | +void SoundPlayWorker::repeat(const QString &filename) | |
42 | +{ | |
43 | + repeat_ = true; | |
44 | + play(filename); | |
45 | +} | |
42 | 46 | |
43 | - if (click == 0) | |
47 | +void SoundPlayWorker::stop() | |
48 | +{ | |
49 | + repeat_ = false; | |
50 | + if (proc->state() != QProcess::NotRunning) | |
44 | 51 | { |
45 | - click = new QSoundEffect; | |
46 | - click->setSource(QUrl::fromLocalFile(":/sounds/button.wav")); | |
47 | - click->setVolume(1.0); | |
52 | + proc->terminate(); | |
53 | + proc->waitForFinished(); | |
48 | 54 | } |
49 | - | |
50 | - click->play(); | |
51 | 55 | } |
52 | 56 | |
53 | -void SoundPlayWorker::setVolume(int volume) | |
57 | +void SoundPlayWorker::onFinished() | |
54 | 58 | { |
55 | - System::setVolume(volume); | |
59 | + if (repeat_) | |
60 | + proc->start(); | |
56 | 61 | } |
57 | 62 | |
58 | 63 | SoundPlayer *SoundPlayer::instance = 0; |
... | ... | @@ -65,6 +70,8 @@ SoundPlayer::SoundPlayer() |
65 | 70 | connect(this, SIGNAL(setVolume(int)), w, SLOT(setVolume(int))); |
66 | 71 | connect(this, SIGNAL(operate(QString)), w, SLOT(play(QString))); |
67 | 72 | connect(this, SIGNAL(click()), w, SLOT(playClick())); |
73 | + connect(this, SIGNAL(operateRepeat(QString)), w, SLOT(repeat(QString))); | |
74 | + connect(this, SIGNAL(operateStop()), w, SLOT(stop())); | |
68 | 75 | |
69 | 76 | playThread.start(); |
70 | 77 | } |
... | ... | @@ -78,22 +85,22 @@ void SoundPlayer::play(const QString &filename) |
78 | 85 | emit setVolume(0); |
79 | 86 | break; |
80 | 87 | case 1: |
81 | - emit setVolume(40); | |
88 | + emit setVolume(60); | |
82 | 89 | break; |
83 | 90 | case 2: |
84 | - emit setVolume(50); | |
91 | + emit setVolume(70); | |
85 | 92 | break; |
86 | 93 | case 3: |
87 | - emit setVolume(60); | |
94 | + emit setVolume(80); | |
88 | 95 | break; |
89 | 96 | case 4: |
90 | - emit setVolume(70); | |
97 | + emit setVolume(85); | |
91 | 98 | break; |
92 | 99 | case 5: |
93 | - emit setVolume(80); | |
100 | + emit setVolume(90); | |
94 | 101 | break; |
95 | 102 | case 6: |
96 | - emit setVolume(90); | |
103 | + emit setVolume(95); | |
97 | 104 | break; |
98 | 105 | case 7: |
99 | 106 | emit setVolume(100); |
... | ... | @@ -115,17 +122,54 @@ void SoundPlayer::emitClick() |
115 | 122 | emit setVolume(0); |
116 | 123 | break; |
117 | 124 | case 1: |
118 | - emit setVolume(50); | |
125 | + emit setVolume(75); | |
119 | 126 | break; |
120 | 127 | case 2: |
121 | - emit setVolume(60); | |
128 | + emit setVolume(80); | |
122 | 129 | break; |
123 | 130 | case 3: |
124 | - emit setVolume(70); | |
131 | + emit setVolume(85); | |
125 | 132 | break; |
126 | 133 | case 4: |
134 | + emit setVolume(90); | |
135 | + break; | |
136 | + case 5: | |
137 | + emit setVolume(95); | |
138 | + break; | |
139 | + case 6: | |
140 | + emit setVolume(98); | |
141 | + break; | |
142 | + case 7: | |
143 | + emit setVolume(100); | |
144 | + break; | |
145 | + default: | |
146 | + emit setVolume(0); | |
147 | + break; | |
148 | + } | |
149 | + | |
150 | + emit click(); | |
151 | +} | |
152 | + | |
153 | +void SoundPlayer::repeat(const QString &filename) | |
154 | +{ | |
155 | + Define::config_item item = Config::getInstance()->getConfigValue(Define::config_marster_vol); | |
156 | + switch (item.d32) | |
157 | + { | |
158 | + case 0: | |
159 | + emit setVolume(0); | |
160 | + break; | |
161 | + case 1: | |
162 | + emit setVolume(60); | |
163 | + break; | |
164 | + case 2: | |
165 | + emit setVolume(70); | |
166 | + break; | |
167 | + case 3: | |
127 | 168 | emit setVolume(80); |
128 | 169 | break; |
170 | + case 4: | |
171 | + emit setVolume(85); | |
172 | + break; | |
129 | 173 | case 5: |
130 | 174 | emit setVolume(90); |
131 | 175 | break; |
... | ... | @@ -140,7 +184,12 @@ void SoundPlayer::emitClick() |
140 | 184 | break; |
141 | 185 | } |
142 | 186 | |
143 | - emit click(); | |
187 | + emit operateRepeat(filename); | |
188 | +} | |
189 | + | |
190 | +void SoundPlayer::stopPlay() | |
191 | +{ | |
192 | + emit operateStop(); | |
144 | 193 | } |
145 | 194 | |
146 | 195 | void SoundPlayer::playClick() |
... | ... | @@ -156,7 +205,7 @@ void SoundPlayer::playStart() |
156 | 205 | if (instance == 0) |
157 | 206 | instance = new SoundPlayer; |
158 | 207 | |
159 | - instance->play(":/sounds/start.wav"); | |
208 | + instance->play("/falinux/sounds/start.wav"); | |
160 | 209 | } |
161 | 210 | |
162 | 211 | void SoundPlayer::playStop() |
... | ... | @@ -164,7 +213,7 @@ void SoundPlayer::playStop() |
164 | 213 | if (instance == 0) |
165 | 214 | instance = new SoundPlayer; |
166 | 215 | |
167 | - instance->play(":/sounds/stop.wav"); | |
216 | + instance->play("/falinux/sounds/stop.wav"); | |
168 | 217 | } |
169 | 218 | |
170 | 219 | void SoundPlayer::playError1() |
... | ... | @@ -172,7 +221,7 @@ void SoundPlayer::playError1() |
172 | 221 | if (instance == 0) |
173 | 222 | instance = new SoundPlayer; |
174 | 223 | |
175 | - instance->play(":/sounds/error1.wav"); | |
224 | + instance->play("/falinux/sounds/error1.wav"); | |
176 | 225 | } |
177 | 226 | |
178 | 227 | void SoundPlayer::playError2() |
... | ... | @@ -180,5 +229,29 @@ void SoundPlayer::playError2() |
180 | 229 | if (instance == 0) |
181 | 230 | instance = new SoundPlayer; |
182 | 231 | |
183 | - instance->play(":/sounds/error2.wav"); | |
232 | + instance->play("/falinux/sounds/error2.wav"); | |
233 | +} | |
234 | + | |
235 | +void SoundPlayer::repeatError1() | |
236 | +{ | |
237 | + if (instance == 0) | |
238 | + instance = new SoundPlayer; | |
239 | + | |
240 | + instance->repeat("/falinux/sounds/error1.wav"); | |
241 | +} | |
242 | + | |
243 | +void SoundPlayer::repeatError2() | |
244 | +{ | |
245 | + if (instance == 0) | |
246 | + instance = new SoundPlayer; | |
247 | + | |
248 | + instance->repeat("/falinux/sounds/error2.wav"); | |
249 | +} | |
250 | + | |
251 | +void SoundPlayer::stop() | |
252 | +{ | |
253 | + if (instance == 0) | |
254 | + instance = new SoundPlayer; | |
255 | + | |
256 | + instance->stopPlay(); | |
184 | 257 | } | ... | ... |
app/gui/oven_control/soundplayer.h
... | ... | @@ -6,10 +6,14 @@ |
6 | 6 | #include <QSoundEffect> |
7 | 7 | #include <QThread> |
8 | 8 | #include <QMap> |
9 | +#include <QProcess> | |
9 | 10 | |
10 | 11 | class SoundPlayWorker : public QObject |
11 | 12 | { |
12 | 13 | Q_OBJECT |
14 | + | |
15 | + bool repeat_; | |
16 | + | |
13 | 17 | public: |
14 | 18 | explicit SoundPlayWorker(); |
15 | 19 | |
... | ... | @@ -17,11 +21,17 @@ public slots: |
17 | 21 | void play(const QString &filename); |
18 | 22 | void playClick(); |
19 | 23 | void setVolume(int volume); |
24 | + void repeat(const QString &filename); | |
25 | + void stop(); | |
20 | 26 | |
21 | 27 | private: |
22 | 28 | QMap<QString, QSound *> map; |
23 | 29 | QSound *current; |
24 | 30 | QSoundEffect *click; |
31 | + QProcess *proc; | |
32 | + | |
33 | +private slots: | |
34 | + void onFinished(); | |
25 | 35 | }; |
26 | 36 | |
27 | 37 | class SoundPlayer : public QObject |
... | ... | @@ -31,6 +41,8 @@ class SoundPlayer : public QObject |
31 | 41 | explicit SoundPlayer(); |
32 | 42 | void play(const QString &filename); |
33 | 43 | void emitClick(); |
44 | + void repeat(const QString &filename); | |
45 | + void stopPlay(); | |
34 | 46 | |
35 | 47 | |
36 | 48 | static SoundPlayer *instance; |
... | ... | @@ -41,11 +53,16 @@ public: |
41 | 53 | static void playStop(); |
42 | 54 | static void playError1(); |
43 | 55 | static void playError2(); |
56 | + static void repeatError1(); | |
57 | + static void repeatError2(); | |
58 | + static void stop(); | |
44 | 59 | |
45 | 60 | signals: |
46 | 61 | void setVolume(int); |
47 | 62 | void operate(const QString &); |
48 | 63 | void click(); |
64 | + void operateRepeat(const QString &); | |
65 | + void operateStop(); | |
49 | 66 | }; |
50 | 67 | |
51 | 68 | #endif // SOUNDPLAYER_H | ... | ... |