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,7 +154,8 @@ ManualCookWindow::ManualCookWindow(QWidget *parent, Define::Mode mode) : | ||
| 154 | updateViewTimer.start(100); | 154 | updateViewTimer.start(100); |
| 155 | 155 | ||
| 156 | foreach (QPushButton *button, findChildren<QPushButton *>()) | 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 | QTimer::singleShot(0, this, SLOT(setupAnimation())); | 160 | QTimer::singleShot(0, this, SLOT(setupAnimation())); |
| 160 | 161 | ||
| @@ -906,6 +907,8 @@ void ManualCookWindow::on_runStopButton_clicked() | @@ -906,6 +907,8 @@ void ManualCookWindow::on_runStopButton_clicked() | ||
| 906 | stop(); | 907 | stop(); |
| 907 | else if (oven->time() > 0) | 908 | else if (oven->time() > 0) |
| 908 | start(); | 909 | start(); |
| 910 | + else | ||
| 911 | + SoundPlayer::playClick(); | ||
| 909 | 912 | ||
| 910 | updateView(); | 913 | updateView(); |
| 911 | } | 914 | } |
app/gui/oven_control/oven_control.pro
| @@ -329,3 +329,10 @@ TRANSLATIONS += lang_en.ts lang_zh.ts | @@ -329,3 +329,10 @@ TRANSLATIONS += lang_en.ts lang_zh.ts | ||
| 329 | 329 | ||
| 330 | target.path = /falinux/dev | 330 | target.path = /falinux/dev |
| 331 | INSTALLS += target | 331 | INSTALLS += target |
| 332 | + | ||
| 333 | +DISTFILES += \ | ||
| 334 | + sounds/button.wav \ | ||
| 335 | + sounds/error1.wav \ | ||
| 336 | + sounds/error2.wav \ | ||
| 337 | + sounds/start.wav \ | ||
| 338 | + sounds/stop.wav |
app/gui/oven_control/resources.qrc
| @@ -533,11 +533,6 @@ | @@ -533,11 +533,6 @@ | ||
| 533 | <file>images/config/102_icon_play_ov.png</file> | 533 | <file>images/config/102_icon_play_ov.png</file> |
| 534 | <file>images/config/102_icon_play.png</file> | 534 | <file>images/config/102_icon_play.png</file> |
| 535 | <file>images/config/102_usb_icon.png</file> | 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 | <file>images/config/100_fav_pannel_icon_ov.png</file> | 536 | <file>images/config/100_fav_pannel_icon_ov.png</file> |
| 542 | <file>images/config/100_fav_pannel_icon.png</file> | 537 | <file>images/config/100_fav_pannel_icon.png</file> |
| 543 | <file>images/config/105_icon_cancel_ov.png</file> | 538 | <file>images/config/105_icon_cancel_ov.png</file> |
app/gui/oven_control/soundplayer.cpp
| @@ -2,6 +2,7 @@ | @@ -2,6 +2,7 @@ | ||
| 2 | #include "system.h" | 2 | #include "system.h" |
| 3 | 3 | ||
| 4 | #include "config.h" | 4 | #include "config.h" |
| 5 | +#include "unistd.h" | ||
| 5 | 6 | ||
| 6 | namespace { | 7 | namespace { |
| 7 | QThread playThread; | 8 | QThread playThread; |
| @@ -9,50 +10,54 @@ QThread playThread; | @@ -9,50 +10,54 @@ QThread playThread; | ||
| 9 | 10 | ||
| 10 | SoundPlayWorker::SoundPlayWorker() | 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 | void SoundPlayWorker::play(const QString &filename) | 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 | void SoundPlayWorker::playClick() | 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 | SoundPlayer *SoundPlayer::instance = 0; | 63 | SoundPlayer *SoundPlayer::instance = 0; |
| @@ -65,6 +70,8 @@ SoundPlayer::SoundPlayer() | @@ -65,6 +70,8 @@ SoundPlayer::SoundPlayer() | ||
| 65 | connect(this, SIGNAL(setVolume(int)), w, SLOT(setVolume(int))); | 70 | connect(this, SIGNAL(setVolume(int)), w, SLOT(setVolume(int))); |
| 66 | connect(this, SIGNAL(operate(QString)), w, SLOT(play(QString))); | 71 | connect(this, SIGNAL(operate(QString)), w, SLOT(play(QString))); |
| 67 | connect(this, SIGNAL(click()), w, SLOT(playClick())); | 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 | playThread.start(); | 76 | playThread.start(); |
| 70 | } | 77 | } |
| @@ -78,22 +85,22 @@ void SoundPlayer::play(const QString &filename) | @@ -78,22 +85,22 @@ void SoundPlayer::play(const QString &filename) | ||
| 78 | emit setVolume(0); | 85 | emit setVolume(0); |
| 79 | break; | 86 | break; |
| 80 | case 1: | 87 | case 1: |
| 81 | - emit setVolume(40); | 88 | + emit setVolume(60); |
| 82 | break; | 89 | break; |
| 83 | case 2: | 90 | case 2: |
| 84 | - emit setVolume(50); | 91 | + emit setVolume(70); |
| 85 | break; | 92 | break; |
| 86 | case 3: | 93 | case 3: |
| 87 | - emit setVolume(60); | 94 | + emit setVolume(80); |
| 88 | break; | 95 | break; |
| 89 | case 4: | 96 | case 4: |
| 90 | - emit setVolume(70); | 97 | + emit setVolume(85); |
| 91 | break; | 98 | break; |
| 92 | case 5: | 99 | case 5: |
| 93 | - emit setVolume(80); | 100 | + emit setVolume(90); |
| 94 | break; | 101 | break; |
| 95 | case 6: | 102 | case 6: |
| 96 | - emit setVolume(90); | 103 | + emit setVolume(95); |
| 97 | break; | 104 | break; |
| 98 | case 7: | 105 | case 7: |
| 99 | emit setVolume(100); | 106 | emit setVolume(100); |
| @@ -115,17 +122,54 @@ void SoundPlayer::emitClick() | @@ -115,17 +122,54 @@ void SoundPlayer::emitClick() | ||
| 115 | emit setVolume(0); | 122 | emit setVolume(0); |
| 116 | break; | 123 | break; |
| 117 | case 1: | 124 | case 1: |
| 118 | - emit setVolume(50); | 125 | + emit setVolume(75); |
| 119 | break; | 126 | break; |
| 120 | case 2: | 127 | case 2: |
| 121 | - emit setVolume(60); | 128 | + emit setVolume(80); |
| 122 | break; | 129 | break; |
| 123 | case 3: | 130 | case 3: |
| 124 | - emit setVolume(70); | 131 | + emit setVolume(85); |
| 125 | break; | 132 | break; |
| 126 | case 4: | 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 | emit setVolume(80); | 168 | emit setVolume(80); |
| 128 | break; | 169 | break; |
| 170 | + case 4: | ||
| 171 | + emit setVolume(85); | ||
| 172 | + break; | ||
| 129 | case 5: | 173 | case 5: |
| 130 | emit setVolume(90); | 174 | emit setVolume(90); |
| 131 | break; | 175 | break; |
| @@ -140,7 +184,12 @@ void SoundPlayer::emitClick() | @@ -140,7 +184,12 @@ void SoundPlayer::emitClick() | ||
| 140 | break; | 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 | void SoundPlayer::playClick() | 195 | void SoundPlayer::playClick() |
| @@ -156,7 +205,7 @@ void SoundPlayer::playStart() | @@ -156,7 +205,7 @@ void SoundPlayer::playStart() | ||
| 156 | if (instance == 0) | 205 | if (instance == 0) |
| 157 | instance = new SoundPlayer; | 206 | instance = new SoundPlayer; |
| 158 | 207 | ||
| 159 | - instance->play(":/sounds/start.wav"); | 208 | + instance->play("/falinux/sounds/start.wav"); |
| 160 | } | 209 | } |
| 161 | 210 | ||
| 162 | void SoundPlayer::playStop() | 211 | void SoundPlayer::playStop() |
| @@ -164,7 +213,7 @@ void SoundPlayer::playStop() | @@ -164,7 +213,7 @@ void SoundPlayer::playStop() | ||
| 164 | if (instance == 0) | 213 | if (instance == 0) |
| 165 | instance = new SoundPlayer; | 214 | instance = new SoundPlayer; |
| 166 | 215 | ||
| 167 | - instance->play(":/sounds/stop.wav"); | 216 | + instance->play("/falinux/sounds/stop.wav"); |
| 168 | } | 217 | } |
| 169 | 218 | ||
| 170 | void SoundPlayer::playError1() | 219 | void SoundPlayer::playError1() |
| @@ -172,7 +221,7 @@ void SoundPlayer::playError1() | @@ -172,7 +221,7 @@ void SoundPlayer::playError1() | ||
| 172 | if (instance == 0) | 221 | if (instance == 0) |
| 173 | instance = new SoundPlayer; | 222 | instance = new SoundPlayer; |
| 174 | 223 | ||
| 175 | - instance->play(":/sounds/error1.wav"); | 224 | + instance->play("/falinux/sounds/error1.wav"); |
| 176 | } | 225 | } |
| 177 | 226 | ||
| 178 | void SoundPlayer::playError2() | 227 | void SoundPlayer::playError2() |
| @@ -180,5 +229,29 @@ void SoundPlayer::playError2() | @@ -180,5 +229,29 @@ void SoundPlayer::playError2() | ||
| 180 | if (instance == 0) | 229 | if (instance == 0) |
| 181 | instance = new SoundPlayer; | 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,10 +6,14 @@ | ||
| 6 | #include <QSoundEffect> | 6 | #include <QSoundEffect> |
| 7 | #include <QThread> | 7 | #include <QThread> |
| 8 | #include <QMap> | 8 | #include <QMap> |
| 9 | +#include <QProcess> | ||
| 9 | 10 | ||
| 10 | class SoundPlayWorker : public QObject | 11 | class SoundPlayWorker : public QObject |
| 11 | { | 12 | { |
| 12 | Q_OBJECT | 13 | Q_OBJECT |
| 14 | + | ||
| 15 | + bool repeat_; | ||
| 16 | + | ||
| 13 | public: | 17 | public: |
| 14 | explicit SoundPlayWorker(); | 18 | explicit SoundPlayWorker(); |
| 15 | 19 | ||
| @@ -17,11 +21,17 @@ public slots: | @@ -17,11 +21,17 @@ public slots: | ||
| 17 | void play(const QString &filename); | 21 | void play(const QString &filename); |
| 18 | void playClick(); | 22 | void playClick(); |
| 19 | void setVolume(int volume); | 23 | void setVolume(int volume); |
| 24 | + void repeat(const QString &filename); | ||
| 25 | + void stop(); | ||
| 20 | 26 | ||
| 21 | private: | 27 | private: |
| 22 | QMap<QString, QSound *> map; | 28 | QMap<QString, QSound *> map; |
| 23 | QSound *current; | 29 | QSound *current; |
| 24 | QSoundEffect *click; | 30 | QSoundEffect *click; |
| 31 | + QProcess *proc; | ||
| 32 | + | ||
| 33 | +private slots: | ||
| 34 | + void onFinished(); | ||
| 25 | }; | 35 | }; |
| 26 | 36 | ||
| 27 | class SoundPlayer : public QObject | 37 | class SoundPlayer : public QObject |
| @@ -31,6 +41,8 @@ class SoundPlayer : public QObject | @@ -31,6 +41,8 @@ class SoundPlayer : public QObject | ||
| 31 | explicit SoundPlayer(); | 41 | explicit SoundPlayer(); |
| 32 | void play(const QString &filename); | 42 | void play(const QString &filename); |
| 33 | void emitClick(); | 43 | void emitClick(); |
| 44 | + void repeat(const QString &filename); | ||
| 45 | + void stopPlay(); | ||
| 34 | 46 | ||
| 35 | 47 | ||
| 36 | static SoundPlayer *instance; | 48 | static SoundPlayer *instance; |
| @@ -41,11 +53,16 @@ public: | @@ -41,11 +53,16 @@ public: | ||
| 41 | static void playStop(); | 53 | static void playStop(); |
| 42 | static void playError1(); | 54 | static void playError1(); |
| 43 | static void playError2(); | 55 | static void playError2(); |
| 56 | + static void repeatError1(); | ||
| 57 | + static void repeatError2(); | ||
| 58 | + static void stop(); | ||
| 44 | 59 | ||
| 45 | signals: | 60 | signals: |
| 46 | void setVolume(int); | 61 | void setVolume(int); |
| 47 | void operate(const QString &); | 62 | void operate(const QString &); |
| 48 | void click(); | 63 | void click(); |
| 64 | + void operateRepeat(const QString &); | ||
| 65 | + void operateStop(); | ||
| 49 | }; | 66 | }; |
| 50 | 67 | ||
| 51 | #endif // SOUNDPLAYER_H | 68 | #endif // SOUNDPLAYER_H |