Commit 04299ad6fb42143b32ee436da94eda3d66dcfab3
1 parent
35b968d1b1
Exists in
master
and in
2 other branches
테스트 프로그램 작성
Showing
9 changed files
with
363 additions
and
0 deletions
Show diff stats
samplecode/.gitignore
... | ... | @@ -0,0 +1 @@ |
1 | +build-* | ... | ... |
samplecode/playclicker/.gitignore
... | ... | @@ -0,0 +1 @@ |
1 | +*.pro.user | ... | ... |
samplecode/playclicker/main.cpp
samplecode/playclicker/mainwindow.cpp
... | ... | @@ -0,0 +1,23 @@ |
1 | +#include "mainwindow.h" | |
2 | +#include "ui_mainwindow.h" | |
3 | + | |
4 | +#include "../../app/gui/oven_control/soundplayer.h" | |
5 | + | |
6 | +MainWindow::MainWindow(QWidget *parent) : | |
7 | + QMainWindow(parent), | |
8 | + ui(new Ui::MainWindow) | |
9 | +{ | |
10 | + ui->setupUi(this); | |
11 | + | |
12 | + showFullScreen(); | |
13 | +} | |
14 | + | |
15 | +MainWindow::~MainWindow() | |
16 | +{ | |
17 | + delete ui; | |
18 | +} | |
19 | + | |
20 | +void MainWindow::on_pushButton_clicked() | |
21 | +{ | |
22 | + SoundPlayer::playClick(); | |
23 | +} | ... | ... |
samplecode/playclicker/mainwindow.h
... | ... | @@ -0,0 +1,25 @@ |
1 | +#ifndef MAINWINDOW_H | |
2 | +#define MAINWINDOW_H | |
3 | + | |
4 | +#include <QMainWindow> | |
5 | + | |
6 | +namespace Ui { | |
7 | +class MainWindow; | |
8 | +} | |
9 | + | |
10 | +class MainWindow : public QMainWindow | |
11 | +{ | |
12 | + Q_OBJECT | |
13 | + | |
14 | +public: | |
15 | + explicit MainWindow(QWidget *parent = 0); | |
16 | + ~MainWindow(); | |
17 | + | |
18 | +private slots: | |
19 | + void on_pushButton_clicked(); | |
20 | + | |
21 | +private: | |
22 | + Ui::MainWindow *ui; | |
23 | +}; | |
24 | + | |
25 | +#endif // MAINWINDOW_H | ... | ... |
samplecode/playclicker/mainwindow.ui
... | ... | @@ -0,0 +1,52 @@ |
1 | +<?xml version="1.0" encoding="UTF-8"?> | |
2 | +<ui version="4.0"> | |
3 | + <class>MainWindow</class> | |
4 | + <widget class="QMainWindow" name="MainWindow"> | |
5 | + <property name="geometry"> | |
6 | + <rect> | |
7 | + <x>0</x> | |
8 | + <y>0</y> | |
9 | + <width>400</width> | |
10 | + <height>300</height> | |
11 | + </rect> | |
12 | + </property> | |
13 | + <property name="windowTitle"> | |
14 | + <string>MainWindow</string> | |
15 | + </property> | |
16 | + <widget class="QWidget" name="centralWidget"> | |
17 | + <layout class="QHBoxLayout" name="horizontalLayout"> | |
18 | + <property name="spacing"> | |
19 | + <number>0</number> | |
20 | + </property> | |
21 | + <property name="leftMargin"> | |
22 | + <number>0</number> | |
23 | + </property> | |
24 | + <property name="topMargin"> | |
25 | + <number>0</number> | |
26 | + </property> | |
27 | + <property name="rightMargin"> | |
28 | + <number>0</number> | |
29 | + </property> | |
30 | + <property name="bottomMargin"> | |
31 | + <number>0</number> | |
32 | + </property> | |
33 | + <item> | |
34 | + <widget class="QPushButton" name="pushButton"> | |
35 | + <property name="sizePolicy"> | |
36 | + <sizepolicy hsizetype="Minimum" vsizetype="Minimum"> | |
37 | + <horstretch>0</horstretch> | |
38 | + <verstretch>0</verstretch> | |
39 | + </sizepolicy> | |
40 | + </property> | |
41 | + <property name="text"> | |
42 | + <string>PushButton</string> | |
43 | + </property> | |
44 | + </widget> | |
45 | + </item> | |
46 | + </layout> | |
47 | + </widget> | |
48 | + </widget> | |
49 | + <layoutdefault spacing="6" margin="11"/> | |
50 | + <resources/> | |
51 | + <connections/> | |
52 | +</ui> | ... | ... |
samplecode/playclicker/playclicker.pro
... | ... | @@ -0,0 +1,22 @@ |
1 | +#------------------------------------------------- | |
2 | +# | |
3 | +# Project created by QtCreator 2017-06-26T16:55:47 | |
4 | +# | |
5 | +#------------------------------------------------- | |
6 | + | |
7 | +QT += core gui multimedia | |
8 | + | |
9 | +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets | |
10 | + | |
11 | +TARGET = playclicker | |
12 | +TEMPLATE = app | |
13 | + | |
14 | + | |
15 | +SOURCES += main.cpp\ | |
16 | + mainwindow.cpp \ | |
17 | + soundplayer.cpp | |
18 | + | |
19 | +HEADERS += mainwindow.h \ | |
20 | + soundplayer.h | |
21 | + | |
22 | +FORMS += mainwindow.ui | ... | ... |
samplecode/playclicker/soundplayer.cpp
... | ... | @@ -0,0 +1,160 @@ |
1 | +#include "soundplayer.h" | |
2 | +#include "unistd.h" | |
3 | + | |
4 | +namespace { | |
5 | +QThread playThread; | |
6 | +} | |
7 | + | |
8 | +SoundPlayWorker::SoundPlayWorker() | |
9 | +{ | |
10 | + repeat_ = false; | |
11 | + proc = new QProcess(this); | |
12 | + | |
13 | + connect(proc, SIGNAL(finished(int)), SLOT(onFinished())); | |
14 | +} | |
15 | + | |
16 | +void SoundPlayWorker::play(const QString &filename) | |
17 | +{ | |
18 | + if (proc->state() != QProcess::NotRunning) | |
19 | + { | |
20 | + proc->terminate(); | |
21 | + proc->waitForFinished(); | |
22 | + } | |
23 | + | |
24 | + proc->start(QString("aplay"), QStringList(filename)); | |
25 | + proc->waitForStarted(); | |
26 | +} | |
27 | + | |
28 | +void SoundPlayWorker::playClick() | |
29 | +{ | |
30 | + play("/falinux/sounds/button.wav"); | |
31 | +} | |
32 | + | |
33 | +void SoundPlayWorker::setVolume(int volume) | |
34 | +{ | |
35 | +} | |
36 | + | |
37 | +void SoundPlayWorker::repeat(const QString &filename) | |
38 | +{ | |
39 | + repeat_ = true; | |
40 | + play(filename); | |
41 | +} | |
42 | + | |
43 | +void SoundPlayWorker::stop() | |
44 | +{ | |
45 | + repeat_ = false; | |
46 | + if (proc->state() != QProcess::NotRunning) | |
47 | + { | |
48 | + proc->terminate(); | |
49 | + proc->waitForFinished(); | |
50 | + } | |
51 | +} | |
52 | + | |
53 | +void SoundPlayWorker::onFinished() | |
54 | +{ | |
55 | + if (repeat_) | |
56 | + proc->start(); | |
57 | +} | |
58 | + | |
59 | +SoundPlayer *SoundPlayer::instance = 0; | |
60 | +SoundPlayer::SoundPlayer() | |
61 | +{ | |
62 | + instance = this; | |
63 | + | |
64 | + SoundPlayWorker *w = new SoundPlayWorker; | |
65 | + w->moveToThread(&playThread); | |
66 | + connect(this, SIGNAL(setVolume(int)), w, SLOT(setVolume(int))); | |
67 | + connect(this, SIGNAL(operate(QString)), w, SLOT(play(QString))); | |
68 | + connect(this, SIGNAL(click()), w, SLOT(playClick())); | |
69 | + connect(this, SIGNAL(operateRepeat(QString)), w, SLOT(repeat(QString))); | |
70 | + connect(this, SIGNAL(operateStop()), w, SLOT(stop())); | |
71 | + | |
72 | + playThread.start(); | |
73 | +} | |
74 | + | |
75 | +void SoundPlayer::play(const QString &filename) | |
76 | +{ | |
77 | + | |
78 | + emit operate(filename); | |
79 | +} | |
80 | + | |
81 | +void SoundPlayer::emitClick() | |
82 | +{ | |
83 | + | |
84 | + emit click(); | |
85 | +} | |
86 | + | |
87 | +void SoundPlayer::repeat(const QString &filename) | |
88 | +{ | |
89 | + | |
90 | + emit operateRepeat(filename); | |
91 | +} | |
92 | + | |
93 | +void SoundPlayer::stopPlay() | |
94 | +{ | |
95 | + emit operateStop(); | |
96 | +} | |
97 | + | |
98 | +void SoundPlayer::playClick() | |
99 | +{ | |
100 | + if (instance == 0) | |
101 | + instance = new SoundPlayer; | |
102 | + | |
103 | + instance->emitClick(); | |
104 | +} | |
105 | + | |
106 | +void SoundPlayer::playStart() | |
107 | +{ | |
108 | + if (instance == 0) | |
109 | + instance = new SoundPlayer; | |
110 | + | |
111 | + instance->play("/falinux/sounds/start.wav"); | |
112 | +} | |
113 | + | |
114 | +void SoundPlayer::playStop() | |
115 | +{ | |
116 | + if (instance == 0) | |
117 | + instance = new SoundPlayer; | |
118 | + | |
119 | + instance->play("/falinux/sounds/stop.wav"); | |
120 | +} | |
121 | + | |
122 | +void SoundPlayer::playError1() | |
123 | +{ | |
124 | + if (instance == 0) | |
125 | + instance = new SoundPlayer; | |
126 | + | |
127 | + instance->play("/falinux/sounds/error1.wav"); | |
128 | +} | |
129 | + | |
130 | +void SoundPlayer::playError2() | |
131 | +{ | |
132 | + if (instance == 0) | |
133 | + instance = new SoundPlayer; | |
134 | + | |
135 | + instance->play("/falinux/sounds/error2.wav"); | |
136 | +} | |
137 | + | |
138 | +void SoundPlayer::repeatError1() | |
139 | +{ | |
140 | + if (instance == 0) | |
141 | + instance = new SoundPlayer; | |
142 | + | |
143 | + instance->repeat("/falinux/sounds/error1.wav"); | |
144 | +} | |
145 | + | |
146 | +void SoundPlayer::repeatError2() | |
147 | +{ | |
148 | + if (instance == 0) | |
149 | + instance = new SoundPlayer; | |
150 | + | |
151 | + instance->repeat("/falinux/sounds/error2.wav"); | |
152 | +} | |
153 | + | |
154 | +void SoundPlayer::stop() | |
155 | +{ | |
156 | + if (instance == 0) | |
157 | + instance = new SoundPlayer; | |
158 | + | |
159 | + instance->stopPlay(); | |
160 | +} | ... | ... |
samplecode/playclicker/soundplayer.h
... | ... | @@ -0,0 +1,68 @@ |
1 | +#ifndef SOUNDPLAYER_H | |
2 | +#define SOUNDPLAYER_H | |
3 | + | |
4 | +#include <QObject> | |
5 | +#include <QSound> | |
6 | +#include <QSoundEffect> | |
7 | +#include <QThread> | |
8 | +#include <QMap> | |
9 | +#include <QProcess> | |
10 | + | |
11 | +class SoundPlayWorker : public QObject | |
12 | +{ | |
13 | + Q_OBJECT | |
14 | + | |
15 | + bool repeat_; | |
16 | + | |
17 | +public: | |
18 | + explicit SoundPlayWorker(); | |
19 | + | |
20 | +public slots: | |
21 | + void play(const QString &filename); | |
22 | + void playClick(); | |
23 | + void setVolume(int volume); | |
24 | + void repeat(const QString &filename); | |
25 | + void stop(); | |
26 | + | |
27 | +private: | |
28 | + QMap<QString, QSound *> map; | |
29 | + QSound *current; | |
30 | + QSoundEffect *click; | |
31 | + QProcess *proc; | |
32 | + | |
33 | +private slots: | |
34 | + void onFinished(); | |
35 | +}; | |
36 | + | |
37 | +class SoundPlayer : public QObject | |
38 | +{ | |
39 | + Q_OBJECT | |
40 | + | |
41 | + explicit SoundPlayer(); | |
42 | + void play(const QString &filename); | |
43 | + void emitClick(); | |
44 | + void repeat(const QString &filename); | |
45 | + void stopPlay(); | |
46 | + | |
47 | + | |
48 | + static SoundPlayer *instance; | |
49 | + | |
50 | +public: | |
51 | + static void playClick(); | |
52 | + static void playStart(); | |
53 | + static void playStop(); | |
54 | + static void playError1(); | |
55 | + static void playError2(); | |
56 | + static void repeatError1(); | |
57 | + static void repeatError2(); | |
58 | + static void stop(); | |
59 | + | |
60 | +signals: | |
61 | + void setVolume(int); | |
62 | + void operate(const QString &); | |
63 | + void click(); | |
64 | + void operateRepeat(const QString &); | |
65 | + void operateStop(); | |
66 | +}; | |
67 | + | |
68 | +#endif // SOUNDPLAYER_H | ... | ... |