1 | /****************************************************************************
|
---|
2 | ** $Id: sound.cpp 48 2006-01-08 15:39:36Z dmik $
|
---|
3 | **
|
---|
4 | ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
|
---|
5 | **
|
---|
6 | ** This file is part of an example program for Qt. This example
|
---|
7 | ** program may be used, distributed and modified without limitation.
|
---|
8 | **
|
---|
9 | *****************************************************************************/
|
---|
10 | //
|
---|
11 | // Very simple example of QSound::play(filename)
|
---|
12 | //
|
---|
13 | // 99% of this program is just boilerplate Qt code to put up a nice
|
---|
14 | // window so you think something special is happening.
|
---|
15 | //
|
---|
16 |
|
---|
17 | #include "sound.h"
|
---|
18 | #include <qapplication.h>
|
---|
19 | #include <qmessagebox.h>
|
---|
20 | #include <qmenubar.h>
|
---|
21 |
|
---|
22 | SoundPlayer::SoundPlayer() :
|
---|
23 | QMainWindow(),
|
---|
24 | bucket3("sounds/3.wav"),
|
---|
25 | bucket4("sounds/4.wav")
|
---|
26 | {
|
---|
27 | if (!QSound::isAvailable()) {
|
---|
28 | // Bail out. Programs in which sound is not critical
|
---|
29 | // could just silently (hehe) ignore the lack of a server.
|
---|
30 | //
|
---|
31 | QMessageBox::warning(this,"No Sound",
|
---|
32 | "<p><b>Sorry, you are not running the Network Audio System.</b>"
|
---|
33 | "<p>If you have the `au' command, run it in the background before this program. "
|
---|
34 | "The latest release of the Network Audio System can be obtained from:"
|
---|
35 | "<pre>\n"
|
---|
36 | " \n"
|
---|
37 | " ftp.ncd.com:/pub/ncd/technology/src/nas\n"
|
---|
38 | " ftp.x.org:/contrib/audio/nas\n"
|
---|
39 | "</pre>"
|
---|
40 | "<p>Release 1.2 of NAS is also included with the X11R6"
|
---|
41 | "contrib distribution."
|
---|
42 | "<p>After installing NAS, you will then need to reconfigure Qt with NAS sound support");
|
---|
43 | }
|
---|
44 |
|
---|
45 | QPopupMenu *file = new QPopupMenu;
|
---|
46 | file->insertItem("Play &1", this, SLOT(doPlay1()), CTRL+Key_1);
|
---|
47 | file->insertItem("Play &2", this, SLOT(doPlay2()), CTRL+Key_2);
|
---|
48 | file->insertItem("Play from bucket &3", this, SLOT(doPlay3()), CTRL+Key_3);
|
---|
49 | file->insertItem("Play from bucket &4", this, SLOT(doPlay4()), CTRL+Key_4);
|
---|
50 | file->insertSeparator();
|
---|
51 | file->insertItem("Play 3 and 4 together", this, SLOT(doPlay34()));
|
---|
52 | file->insertItem("Play all together", this, SLOT(doPlay1234()));
|
---|
53 | file->insertSeparator();
|
---|
54 | file->insertItem("E&xit", qApp, SLOT(quit()));
|
---|
55 | menuBar()->insertItem("&File", file);
|
---|
56 | }
|
---|
57 |
|
---|
58 | void SoundPlayer::doPlay1()
|
---|
59 | {
|
---|
60 | QSound::play("sounds/1.wav");
|
---|
61 | }
|
---|
62 |
|
---|
63 | void SoundPlayer::doPlay2()
|
---|
64 | {
|
---|
65 | QSound::play("sounds/2.wav");
|
---|
66 | }
|
---|
67 |
|
---|
68 | void SoundPlayer::doPlay3()
|
---|
69 | {
|
---|
70 | bucket3.play();
|
---|
71 | }
|
---|
72 |
|
---|
73 | void SoundPlayer::doPlay4()
|
---|
74 | {
|
---|
75 | bucket4.play();
|
---|
76 | }
|
---|
77 |
|
---|
78 | void SoundPlayer::doPlay34()
|
---|
79 | {
|
---|
80 | // Some sound platforms will only play one sound at a time
|
---|
81 | bucket3.play();
|
---|
82 | bucket4.play();
|
---|
83 | }
|
---|
84 |
|
---|
85 | void SoundPlayer::doPlay1234()
|
---|
86 | {
|
---|
87 | // Some sound platforms will only play one sound at a time
|
---|
88 | QSound::play("sounds/1.wav");
|
---|
89 | QSound::play("sounds/2.wav");
|
---|
90 | bucket3.play();
|
---|
91 | bucket4.play();
|
---|
92 | }
|
---|
93 |
|
---|
94 | int main(int argc, char** argv)
|
---|
95 | {
|
---|
96 | QApplication app(argc,argv);
|
---|
97 | SoundPlayer sp;
|
---|
98 | app.setMainWidget(&sp);
|
---|
99 | sp.setCaption("Qt Example - Sounds");
|
---|
100 | sp.show();
|
---|
101 | return app.exec();
|
---|
102 | }
|
---|
103 |
|
---|