From d75742e49393115a8b051a02df7c613ecaffb96c Mon Sep 17 00:00:00 2001 From: victor Date: Wed, 21 Jun 2017 14:56:56 +0900 Subject: [PATCH] =?UTF-8?q?=EC=9D=8C=ED=96=A5=20=ED=9A=A8=EA=B3=BC=20?= =?UTF-8?q?=EA=B0=9C=EC=84=A0=20-=20QSound,=20QSoundEffect=20=EB=8C=80?= =?UTF-8?q?=EC=8B=A0=20aplay=20=EC=82=AC=EC=9A=A9.=20=ED=95=B4=EB=8B=B9=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=EB=8A=94=20=EC=9D=8C=ED=96=A5?= =?UTF-8?q?=EC=9D=B4=20=EA=B9=A8=EC=A7=80=EB=8A=94=20=EB=AC=B8=EC=A0=9C?= =?UTF-8?q?=EA=B0=80=20=EC=9E=88=EC=9D=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/gui/oven_control/manualcookwindow.cpp | 5 +- app/gui/oven_control/oven_control.pro | 7 ++ app/gui/oven_control/resources.qrc | 5 - app/gui/oven_control/soundplayer.cpp | 153 ++++++++++++++++++++++-------- app/gui/oven_control/soundplayer.h | 17 ++++ 5 files changed, 141 insertions(+), 46 deletions(-) diff --git a/app/gui/oven_control/manualcookwindow.cpp b/app/gui/oven_control/manualcookwindow.cpp index 449a945..a2281c3 100644 --- a/app/gui/oven_control/manualcookwindow.cpp +++ b/app/gui/oven_control/manualcookwindow.cpp @@ -154,7 +154,8 @@ ManualCookWindow::ManualCookWindow(QWidget *parent, Define::Mode mode) : updateViewTimer.start(100); foreach (QPushButton *button, findChildren()) - connect(button, &QPushButton::pressed, SoundPlayer::playClick); + if (button != ui->runStopButton) + connect(button, &QPushButton::pressed, SoundPlayer::playClick); QTimer::singleShot(0, this, SLOT(setupAnimation())); @@ -906,6 +907,8 @@ void ManualCookWindow::on_runStopButton_clicked() stop(); else if (oven->time() > 0) start(); + else + SoundPlayer::playClick(); updateView(); } diff --git a/app/gui/oven_control/oven_control.pro b/app/gui/oven_control/oven_control.pro index f00c178..274c6a5 100644 --- a/app/gui/oven_control/oven_control.pro +++ b/app/gui/oven_control/oven_control.pro @@ -329,3 +329,10 @@ TRANSLATIONS += lang_en.ts lang_zh.ts target.path = /falinux/dev INSTALLS += target + +DISTFILES += \ + sounds/button.wav \ + sounds/error1.wav \ + sounds/error2.wav \ + sounds/start.wav \ + sounds/stop.wav diff --git a/app/gui/oven_control/resources.qrc b/app/gui/oven_control/resources.qrc index 0d94a57..432b2dc 100644 --- a/app/gui/oven_control/resources.qrc +++ b/app/gui/oven_control/resources.qrc @@ -533,11 +533,6 @@ images/config/102_icon_play_ov.png images/config/102_icon_play.png images/config/102_usb_icon.png - sounds/error1.wav - sounds/error2.wav - sounds/start.wav - sounds/stop.wav - sounds/button.wav images/config/100_fav_pannel_icon_ov.png images/config/100_fav_pannel_icon.png images/config/105_icon_cancel_ov.png diff --git a/app/gui/oven_control/soundplayer.cpp b/app/gui/oven_control/soundplayer.cpp index 8eb8601..67bf6c5 100644 --- a/app/gui/oven_control/soundplayer.cpp +++ b/app/gui/oven_control/soundplayer.cpp @@ -2,6 +2,7 @@ #include "system.h" #include "config.h" +#include "unistd.h" namespace { QThread playThread; @@ -9,50 +10,54 @@ QThread playThread; SoundPlayWorker::SoundPlayWorker() { - current = 0; - click = 0; + repeat_ = false; + proc = new QProcess(this); + + connect(proc, SIGNAL(finished(int)), SLOT(onFinished())); } void SoundPlayWorker::play(const QString &filename) { - if (current && !current->isFinished()) - current->stop(); - - if (click && click->isPlaying()) - click->stop(); - - if (map.contains(filename)) - current = map.value(filename); - else + if (proc->state() != QProcess::NotRunning) { - current = new QSound(filename); - map[filename] = current; + proc->terminate(); + proc->waitForFinished(); } - current->play(); + proc->start(QString("aplay"), QStringList(filename)); + proc->waitForStarted(); } void SoundPlayWorker::playClick() { - if (current && !current->isFinished()) - current->stop(); + play("/falinux/sounds/button.wav"); +} - if (click && click->isPlaying()) - click->stop(); +void SoundPlayWorker::setVolume(int volume) +{ + System::setVolume(volume); +} + +void SoundPlayWorker::repeat(const QString &filename) +{ + repeat_ = true; + play(filename); +} - if (click == 0) +void SoundPlayWorker::stop() +{ + repeat_ = false; + if (proc->state() != QProcess::NotRunning) { - click = new QSoundEffect; - click->setSource(QUrl::fromLocalFile(":/sounds/button.wav")); - click->setVolume(1.0); + proc->terminate(); + proc->waitForFinished(); } - - click->play(); } -void SoundPlayWorker::setVolume(int volume) +void SoundPlayWorker::onFinished() { - System::setVolume(volume); + if (repeat_) + proc->start(); } SoundPlayer *SoundPlayer::instance = 0; @@ -65,6 +70,8 @@ SoundPlayer::SoundPlayer() connect(this, SIGNAL(setVolume(int)), w, SLOT(setVolume(int))); connect(this, SIGNAL(operate(QString)), w, SLOT(play(QString))); connect(this, SIGNAL(click()), w, SLOT(playClick())); + connect(this, SIGNAL(operateRepeat(QString)), w, SLOT(repeat(QString))); + connect(this, SIGNAL(operateStop()), w, SLOT(stop())); playThread.start(); } @@ -78,22 +85,22 @@ void SoundPlayer::play(const QString &filename) emit setVolume(0); break; case 1: - emit setVolume(40); + emit setVolume(60); break; case 2: - emit setVolume(50); + emit setVolume(70); break; case 3: - emit setVolume(60); + emit setVolume(80); break; case 4: - emit setVolume(70); + emit setVolume(85); break; case 5: - emit setVolume(80); + emit setVolume(90); break; case 6: - emit setVolume(90); + emit setVolume(95); break; case 7: emit setVolume(100); @@ -115,17 +122,54 @@ void SoundPlayer::emitClick() emit setVolume(0); break; case 1: - emit setVolume(50); + emit setVolume(75); break; case 2: - emit setVolume(60); + emit setVolume(80); break; case 3: - emit setVolume(70); + emit setVolume(85); break; case 4: + emit setVolume(90); + break; + case 5: + emit setVolume(95); + break; + case 6: + emit setVolume(98); + break; + case 7: + emit setVolume(100); + break; + default: + emit setVolume(0); + break; + } + + emit click(); +} + +void SoundPlayer::repeat(const QString &filename) +{ + Define::config_item item = Config::getInstance()->getConfigValue(Define::config_marster_vol); + switch (item.d32) + { + case 0: + emit setVolume(0); + break; + case 1: + emit setVolume(60); + break; + case 2: + emit setVolume(70); + break; + case 3: emit setVolume(80); break; + case 4: + emit setVolume(85); + break; case 5: emit setVolume(90); break; @@ -140,7 +184,12 @@ void SoundPlayer::emitClick() break; } - emit click(); + emit operateRepeat(filename); +} + +void SoundPlayer::stopPlay() +{ + emit operateStop(); } void SoundPlayer::playClick() @@ -156,7 +205,7 @@ void SoundPlayer::playStart() if (instance == 0) instance = new SoundPlayer; - instance->play(":/sounds/start.wav"); + instance->play("/falinux/sounds/start.wav"); } void SoundPlayer::playStop() @@ -164,7 +213,7 @@ void SoundPlayer::playStop() if (instance == 0) instance = new SoundPlayer; - instance->play(":/sounds/stop.wav"); + instance->play("/falinux/sounds/stop.wav"); } void SoundPlayer::playError1() @@ -172,7 +221,7 @@ void SoundPlayer::playError1() if (instance == 0) instance = new SoundPlayer; - instance->play(":/sounds/error1.wav"); + instance->play("/falinux/sounds/error1.wav"); } void SoundPlayer::playError2() @@ -180,5 +229,29 @@ void SoundPlayer::playError2() if (instance == 0) instance = new SoundPlayer; - instance->play(":/sounds/error2.wav"); + instance->play("/falinux/sounds/error2.wav"); +} + +void SoundPlayer::repeatError1() +{ + if (instance == 0) + instance = new SoundPlayer; + + instance->repeat("/falinux/sounds/error1.wav"); +} + +void SoundPlayer::repeatError2() +{ + if (instance == 0) + instance = new SoundPlayer; + + instance->repeat("/falinux/sounds/error2.wav"); +} + +void SoundPlayer::stop() +{ + if (instance == 0) + instance = new SoundPlayer; + + instance->stopPlay(); } diff --git a/app/gui/oven_control/soundplayer.h b/app/gui/oven_control/soundplayer.h index c2e1501..ef54d4b 100644 --- a/app/gui/oven_control/soundplayer.h +++ b/app/gui/oven_control/soundplayer.h @@ -6,10 +6,14 @@ #include #include #include +#include class SoundPlayWorker : public QObject { Q_OBJECT + + bool repeat_; + public: explicit SoundPlayWorker(); @@ -17,11 +21,17 @@ public slots: void play(const QString &filename); void playClick(); void setVolume(int volume); + void repeat(const QString &filename); + void stop(); private: QMap map; QSound *current; QSoundEffect *click; + QProcess *proc; + +private slots: + void onFinished(); }; class SoundPlayer : public QObject @@ -31,6 +41,8 @@ class SoundPlayer : public QObject explicit SoundPlayer(); void play(const QString &filename); void emitClick(); + void repeat(const QString &filename); + void stopPlay(); static SoundPlayer *instance; @@ -41,11 +53,16 @@ public: static void playStop(); static void playError1(); static void playError2(); + static void repeatError1(); + static void repeatError2(); + static void stop(); signals: void setVolume(int); void operate(const QString &); void click(); + void operateRepeat(const QString &); + void operateStop(); }; #endif // SOUNDPLAYER_H -- 2.1.4