From 04299ad6fb42143b32ee436da94eda3d66dcfab3 Mon Sep 17 00:00:00 2001 From: victor Date: Mon, 26 Jun 2017 17:30:01 +0900 Subject: [PATCH] =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=ED=94=84?= =?UTF-8?q?=EB=A1=9C=EA=B7=B8=EB=9E=A8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- samplecode/.gitignore | 1 + samplecode/playclicker/.gitignore | 1 + samplecode/playclicker/main.cpp | 11 +++ samplecode/playclicker/mainwindow.cpp | 23 +++++ samplecode/playclicker/mainwindow.h | 25 ++++++ samplecode/playclicker/mainwindow.ui | 52 +++++++++++ samplecode/playclicker/playclicker.pro | 22 +++++ samplecode/playclicker/soundplayer.cpp | 160 +++++++++++++++++++++++++++++++++ samplecode/playclicker/soundplayer.h | 68 ++++++++++++++ 9 files changed, 363 insertions(+) create mode 100644 samplecode/.gitignore create mode 100644 samplecode/playclicker/.gitignore create mode 100644 samplecode/playclicker/main.cpp create mode 100644 samplecode/playclicker/mainwindow.cpp create mode 100644 samplecode/playclicker/mainwindow.h create mode 100644 samplecode/playclicker/mainwindow.ui create mode 100644 samplecode/playclicker/playclicker.pro create mode 100644 samplecode/playclicker/soundplayer.cpp create mode 100644 samplecode/playclicker/soundplayer.h diff --git a/samplecode/.gitignore b/samplecode/.gitignore new file mode 100644 index 0000000..dd07bff --- /dev/null +++ b/samplecode/.gitignore @@ -0,0 +1 @@ +build-* diff --git a/samplecode/playclicker/.gitignore b/samplecode/playclicker/.gitignore new file mode 100644 index 0000000..75c107b --- /dev/null +++ b/samplecode/playclicker/.gitignore @@ -0,0 +1 @@ +*.pro.user diff --git a/samplecode/playclicker/main.cpp b/samplecode/playclicker/main.cpp new file mode 100644 index 0000000..b48f94e --- /dev/null +++ b/samplecode/playclicker/main.cpp @@ -0,0 +1,11 @@ +#include "mainwindow.h" +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + w.show(); + + return a.exec(); +} diff --git a/samplecode/playclicker/mainwindow.cpp b/samplecode/playclicker/mainwindow.cpp new file mode 100644 index 0000000..6f625ca --- /dev/null +++ b/samplecode/playclicker/mainwindow.cpp @@ -0,0 +1,23 @@ +#include "mainwindow.h" +#include "ui_mainwindow.h" + +#include "../../app/gui/oven_control/soundplayer.h" + +MainWindow::MainWindow(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::MainWindow) +{ + ui->setupUi(this); + + showFullScreen(); +} + +MainWindow::~MainWindow() +{ + delete ui; +} + +void MainWindow::on_pushButton_clicked() +{ + SoundPlayer::playClick(); +} diff --git a/samplecode/playclicker/mainwindow.h b/samplecode/playclicker/mainwindow.h new file mode 100644 index 0000000..ed42168 --- /dev/null +++ b/samplecode/playclicker/mainwindow.h @@ -0,0 +1,25 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include + +namespace Ui { +class MainWindow; +} + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + explicit MainWindow(QWidget *parent = 0); + ~MainWindow(); + +private slots: + void on_pushButton_clicked(); + +private: + Ui::MainWindow *ui; +}; + +#endif // MAINWINDOW_H diff --git a/samplecode/playclicker/mainwindow.ui b/samplecode/playclicker/mainwindow.ui new file mode 100644 index 0000000..3c37b55 --- /dev/null +++ b/samplecode/playclicker/mainwindow.ui @@ -0,0 +1,52 @@ + + + MainWindow + + + + 0 + 0 + 400 + 300 + + + + MainWindow + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + PushButton + + + + + + + + + + diff --git a/samplecode/playclicker/playclicker.pro b/samplecode/playclicker/playclicker.pro new file mode 100644 index 0000000..8a3d155 --- /dev/null +++ b/samplecode/playclicker/playclicker.pro @@ -0,0 +1,22 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2017-06-26T16:55:47 +# +#------------------------------------------------- + +QT += core gui multimedia + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TARGET = playclicker +TEMPLATE = app + + +SOURCES += main.cpp\ + mainwindow.cpp \ + soundplayer.cpp + +HEADERS += mainwindow.h \ + soundplayer.h + +FORMS += mainwindow.ui diff --git a/samplecode/playclicker/soundplayer.cpp b/samplecode/playclicker/soundplayer.cpp new file mode 100644 index 0000000..d040ea7 --- /dev/null +++ b/samplecode/playclicker/soundplayer.cpp @@ -0,0 +1,160 @@ +#include "soundplayer.h" +#include "unistd.h" + +namespace { +QThread playThread; +} + +SoundPlayWorker::SoundPlayWorker() +{ + repeat_ = false; + proc = new QProcess(this); + + connect(proc, SIGNAL(finished(int)), SLOT(onFinished())); +} + +void SoundPlayWorker::play(const QString &filename) +{ + if (proc->state() != QProcess::NotRunning) + { + proc->terminate(); + proc->waitForFinished(); + } + + proc->start(QString("aplay"), QStringList(filename)); + proc->waitForStarted(); +} + +void SoundPlayWorker::playClick() +{ + play("/falinux/sounds/button.wav"); +} + +void SoundPlayWorker::setVolume(int volume) +{ +} + +void SoundPlayWorker::repeat(const QString &filename) +{ + repeat_ = true; + play(filename); +} + +void SoundPlayWorker::stop() +{ + repeat_ = false; + if (proc->state() != QProcess::NotRunning) + { + proc->terminate(); + proc->waitForFinished(); + } +} + +void SoundPlayWorker::onFinished() +{ + if (repeat_) + proc->start(); +} + +SoundPlayer *SoundPlayer::instance = 0; +SoundPlayer::SoundPlayer() +{ + instance = this; + + SoundPlayWorker *w = new SoundPlayWorker; + w->moveToThread(&playThread); + 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(); +} + +void SoundPlayer::play(const QString &filename) +{ + + emit operate(filename); +} + +void SoundPlayer::emitClick() +{ + + emit click(); +} + +void SoundPlayer::repeat(const QString &filename) +{ + + emit operateRepeat(filename); +} + +void SoundPlayer::stopPlay() +{ + emit operateStop(); +} + +void SoundPlayer::playClick() +{ + if (instance == 0) + instance = new SoundPlayer; + + instance->emitClick(); +} + +void SoundPlayer::playStart() +{ + if (instance == 0) + instance = new SoundPlayer; + + instance->play("/falinux/sounds/start.wav"); +} + +void SoundPlayer::playStop() +{ + if (instance == 0) + instance = new SoundPlayer; + + instance->play("/falinux/sounds/stop.wav"); +} + +void SoundPlayer::playError1() +{ + if (instance == 0) + instance = new SoundPlayer; + + instance->play("/falinux/sounds/error1.wav"); +} + +void SoundPlayer::playError2() +{ + if (instance == 0) + instance = new SoundPlayer; + + 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/samplecode/playclicker/soundplayer.h b/samplecode/playclicker/soundplayer.h new file mode 100644 index 0000000..ef54d4b --- /dev/null +++ b/samplecode/playclicker/soundplayer.h @@ -0,0 +1,68 @@ +#ifndef SOUNDPLAYER_H +#define SOUNDPLAYER_H + +#include +#include +#include +#include +#include +#include + +class SoundPlayWorker : public QObject +{ + Q_OBJECT + + bool repeat_; + +public: + explicit SoundPlayWorker(); + +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 +{ + Q_OBJECT + + explicit SoundPlayer(); + void play(const QString &filename); + void emitClick(); + void repeat(const QString &filename); + void stopPlay(); + + + static SoundPlayer *instance; + +public: + static void playClick(); + static void playStart(); + 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