~keith-penguin/kdegames/trunk

« back to all changes in this revision

Viewing changes to kgoldrunner/src/kgrsoundbank.h

  • Committer: Keith Worrell
  • Date: 2009-03-18 05:35:28 UTC
  • Revision ID: keith.worrell@gmail.com-20090318053528-mx6x9c0ngmg0kg6p
imported project

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright 2007 Luciano Montanaro <mikelima@cirulla.net>
 
3
 
 
4
    This program is free software; you can redistribute it and/or modify
 
5
    it under the terms of the GNU General Public License as published by
 
6
    the Free Software Foundation; either version 2 of the License, or
 
7
    (at your option) any later version.
 
8
 
 
9
    This program is distributed in the hope that it will be useful,
 
10
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
    GNU General Public License for more details.
 
13
 
 
14
    You should have received a copy of the GNU General Public License
 
15
    along with this program; if not, write to the 
 
16
    Free Software Foundation, Inc., 
 
17
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
18
*/
 
19
 
 
20
#ifndef KGRSOUNDBANK_H
 
21
#define KGRSOUNDBANK_H
 
22
 
 
23
#include <Phonon/MediaObject>
 
24
#include <Phonon/MediaSource>
 
25
 
 
26
class KGrSoundBank : public QObject
 
27
{
 
28
    Q_OBJECT
 
29
public:
 
30
 
 
31
    /**
 
32
     * Construct the KGrSoundBank class.
 
33
     * \param number - how many audio channels are required
 
34
     */
 
35
    KGrSoundBank(int number);
 
36
    ~KGrSoundBank();
 
37
 
 
38
    /**
 
39
     * Play a sound effect. 
 
40
     * This method returns a token that can be used to stop the sound if it is
 
41
     * still playing. Trying to stop a completed sound has no effect.
 
42
     */
 
43
    int play (int effect, bool looping = false);
 
44
 
 
45
    /**
 
46
     * Stop playing the sound associated with the given token.
 
47
     */
 
48
    void stop (int token);
 
49
 
 
50
    /** 
 
51
     * Load a sound sample.
 
52
     * A token is returned to use to play back the sample.
 
53
     */
 
54
    int loadSound (const QString &fileName);
 
55
 
 
56
    /** 
 
57
     * Stop sound and discard the loaded sound effects.
 
58
     */
 
59
    void reset();
 
60
 
 
61
    /**
 
62
     * Stop all sounds currently playing.
 
63
     */
 
64
    void stopAllSounds();
 
65
 
 
66
    /**
 
67
     * Set volume for the sound effects.
 
68
     * \param volume the playing volume. 0.0 means mute, 1.0 means full volume.
 
69
     */
 
70
    void setEffectsVolume (double volume);
 
71
   
 
72
    /**
 
73
     * Set volume for the background music.
 
74
     * \param volume the playing volume. 0.0 means mute, 1.0 means full volume.
 
75
     */
 
76
    void setMusicVolume (double volume);
 
77
   
 
78
    void setMuted (bool mute);
 
79
 
 
80
private slots:
 
81
    void freeChannels();
 
82
private:
 
83
    int freeAChannel();
 
84
 
 
85
private:
 
86
    QVector< Phonon::MediaSource > soundSamples;
 
87
    QVector< Phonon::MediaObject * > channels;
 
88
    QVector< int > tokens;
 
89
 
 
90
    int currentToken;
 
91
    bool muted;
 
92
};
 
93
 
 
94
#endif // KGRSOUNDBANK_H
 
95
// vi: set sw=4 cino=\:0g0 :