summaryrefslogtreecommitdiffstats
path: root/examples/sound/sound.cpp
diff options
context:
space:
mode:
authorTimothy Pearson <[email protected]>2011-11-08 12:31:36 -0600
committerTimothy Pearson <[email protected]>2011-11-08 12:31:36 -0600
commitd796c9dd933ab96ec83b9a634feedd5d32e1ba3f (patch)
tree6e3dcca4f77e20ec8966c666aac7c35bd4704053 /examples/sound/sound.cpp
downloadtqt3-d796c9dd933ab96ec83b9a634feedd5d32e1ba3f.tar.gz
tqt3-d796c9dd933ab96ec83b9a634feedd5d32e1ba3f.zip
Test conversion to TQt3 from Qt3 8c6fc1f8e35fd264dd01c582ca5e7549b32ab731
Diffstat (limited to 'examples/sound/sound.cpp')
-rw-r--r--examples/sound/sound.cpp102
1 files changed, 102 insertions, 0 deletions
diff --git a/examples/sound/sound.cpp b/examples/sound/sound.cpp
new file mode 100644
index 000000000..45ce61563
--- /dev/null
+++ b/examples/sound/sound.cpp
@@ -0,0 +1,102 @@
+/****************************************************************************
+**
+** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of an example program for TQt. This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+//
+// Very simple example of TQSound::play(filename)
+//
+// 99% of this program is just boilerplate TQt code to put up a nice
+// window so you think something special is happening.
+//
+
+#include "sound.h"
+#include <qapplication.h>
+#include <qmessagebox.h>
+#include <qmenubar.h>
+
+SoundPlayer::SoundPlayer() :
+ TQMainWindow(),
+ bucket3("sounds/3.wav"),
+ bucket4("sounds/4.wav")
+{
+ if (!TQSound::isAvailable()) {
+ // Bail out. Programs in which sound is not critical
+ // could just silently (hehe) ignore the lack of a server.
+ //
+ TQMessageBox::warning(this,"No Sound",
+ "<p><b>Sorry, you are not running the Network Audio System.</b>"
+ "<p>If you have the `au' command, run it in the background before this program. "
+ "The latest release of the Network Audio System can be obtained from:"
+ "<pre>\n"
+ " &nbsp;\n"
+ " ftp.ncd.com:/pub/ncd/technology/src/nas\n"
+ " ftp.x.org:/contrib/audio/nas\n"
+ "</pre>"
+ "<p>Release 1.2 of NAS is also included with the X11R6"
+ "contrib distribution."
+ "<p>After installing NAS, you will then need to reconfigure TQt with NAS sound support");
+ }
+
+ TQPopupMenu *file = new TQPopupMenu;
+ file->insertItem("Play &1", this, SLOT(doPlay1()), CTRL+Key_1);
+ file->insertItem("Play &2", this, SLOT(doPlay2()), CTRL+Key_2);
+ file->insertItem("Play from bucket &3", this, SLOT(doPlay3()), CTRL+Key_3);
+ file->insertItem("Play from bucket &4", this, SLOT(doPlay4()), CTRL+Key_4);
+ file->insertSeparator();
+ file->insertItem("Play 3 and 4 together", this, SLOT(doPlay34()));
+ file->insertItem("Play all together", this, SLOT(doPlay1234()));
+ file->insertSeparator();
+ file->insertItem("E&xit", qApp, SLOT(tquit()));
+ menuBar()->insertItem("&File", file);
+}
+
+void SoundPlayer::doPlay1()
+{
+ TQSound::play("sounds/1.wav");
+}
+
+void SoundPlayer::doPlay2()
+{
+ TQSound::play("sounds/2.wav");
+}
+
+void SoundPlayer::doPlay3()
+{
+ bucket3.play();
+}
+
+void SoundPlayer::doPlay4()
+{
+ bucket4.play();
+}
+
+void SoundPlayer::doPlay34()
+{
+ // Some sound platforms will only play one sound at a time
+ bucket3.play();
+ bucket4.play();
+}
+
+void SoundPlayer::doPlay1234()
+{
+ // Some sound platforms will only play one sound at a time
+ TQSound::play("sounds/1.wav");
+ TQSound::play("sounds/2.wav");
+ bucket3.play();
+ bucket4.play();
+}
+
+int main(int argc, char** argv)
+{
+ TQApplication app(argc,argv);
+ SoundPlayer sp;
+ app.setMainWidget(&sp);
+ sp.setCaption("TQt Example - Sounds");
+ sp.show();
+ return app.exec();
+}
+