• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdegames API Reference
  • KDE Home
  • Contact Us
 

kgoldrunner

  • sources
  • kde-4.14
  • kdegames
  • kgoldrunner
  • src
kgrsounds.cpp
Go to the documentation of this file.
1 /****************************************************************************
2  * Copyright 2011 Ian Wadham <iandw.au at gmail dot com>
3  * Copyright 2007 Luciano Montanaro <mikelima@cirulla.net> *
4  * *
5  * This program is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU General Public License as *
7  * published by the Free Software Foundation; either version 2 of *
8  * the License, or (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
17  ****************************************************************************/
18 
19 #include "kgrsounds.h"
20 
21 #include <KDebug>
22 
23 KGrSounds::KGrSounds() :
24  QObject(),
25  sounds()
26 {
27  t.start();
28 }
29 
30 KGrSounds::~KGrSounds()
31 {
32 }
33 
34 int KGrSounds::loadSound (const QString &fileName)
35 {
36  kDebug() << "Loading sound" << fileName;
37  sounds << (new KgSound (fileName));
38  startTime << 0;
39  return sounds.count() - 1;
40 }
41 
42 void KGrSounds::setTimedSound (int i)
43 {
44  startTime[i] = 1;
45 }
46 
47 void KGrSounds::stopAllSounds()
48 {
49  for (int i = 0; i < sounds.count(); i++) {
50  sounds[i]->stop();
51  }
52 }
53 
54 void KGrSounds::reset()
55 {
56  stopAllSounds();
57  sounds.clear();
58 }
59 
60 int KGrSounds::play (int effect)
61 {
62  if (muted) return -1;
63 
64  // Delete all previously playing instances of this sound, but allow gold and
65  // dig sounds to play for > 1 sec, so that rapid sequences of digging or
66  // gold collection will have properly overlapping sounds.
67 
68  int started = startTime[effect];
69  bool timedSound = (started != 0);
70  int current = timedSound ? t.elapsed() : 0;
71 
72  if ((! timedSound) || ((current - started) > 1000)) {
73  sounds[effect]->stop();
74  }
75 
76  sounds[effect]->start();
77 
78  if (timedSound) {
79  startTime[effect] = current;
80  }
81  return effect;
82 }
83 
84 void KGrSounds::stop (int effect)
85 {
86  if (muted) return;
87 
88  sounds[effect]->stop();
89 }
90 
91 void KGrSounds::setMuted (bool mute)
92 {
93  muted = mute;
94  if (mute) {
95  stopAllSounds();
96  }
97 }
98 
99 void KGrSounds::setVolume (int effect, qreal volume)
100 {
101  sounds[effect]->setVolume (volume);
102 }
103 
104 #include "kgrsounds.moc"
KGrSounds::stop
void stop(int token)
Stop playing the sound associated with the given token.
Definition: kgrsounds.cpp:84
KGrSounds::KGrSounds
KGrSounds()
Construct the KGrSounds class.
Definition: kgrsounds.cpp:23
QVector::clear
void clear()
QTime::elapsed
int elapsed() const
QObject
KGrSounds::~KGrSounds
~KGrSounds()
Definition: kgrsounds.cpp:30
kgrsounds.h
QString
KGrSounds::play
int play(int effect)
Play a sound effect.
Definition: kgrsounds.cpp:60
KGrSounds::setMuted
void setMuted(bool mute)
Definition: kgrsounds.cpp:91
KGrSounds::stopAllSounds
void stopAllSounds()
Stop all sounds currently playing.
Definition: kgrsounds.cpp:47
QVector::count
int count(const T &value) const
KGrSounds::setTimedSound
void setTimedSound(int i)
Set up a sound to have its latest start-time recorded.
Definition: kgrsounds.cpp:42
QTime::start
void start()
KGrSounds::reset
void reset()
Stop sound and discard the loaded sound effects.
Definition: kgrsounds.cpp:54
KGrSounds::loadSound
int loadSound(const QString &fileName)
Load a sound sample.
Definition: kgrsounds.cpp:34
KGrSounds::setVolume
void setVolume(int effect, qreal volume)
Change the volume of one type of sound (e.g.
Definition: kgrsounds.cpp:99
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:18:24 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kgoldrunner

Skip menu "kgoldrunner"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdegames API Reference

Skip menu "kdegames API Reference"
  • granatier
  • kapman
  • kblackbox
  • kgoldrunner
  • kigo
  • kmahjongg
  • KShisen
  • ksquares
  • libkdegames
  •   highscore
  •   libkdegamesprivate
  •     kgame
  • libkmahjongg
  • palapeli
  •   libpala

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal