VoltAir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Groups Pages
SoundEffectInstance.h
1 /*
2  * Copyright (C) 2014 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef SOUNDEFFECTINSTANCE_H
18 #define SOUNDEFFECTINSTANCE_H
19 
20 #include <QSharedPointer>
21 
22 class QSoundEffect;
23 
37 public:
50  explicit SoundEffectInstance(const QSharedPointer<QSoundEffect>& soundEffect);
61  SoundEffectInstance(const SoundEffectInstance& other) = delete;
62 
64 
76  SoundEffectInstance& operator=(const SoundEffectInstance& other) = delete;
77 
81  void reset();
87  void reset(SoundEffectInstance&& other);
92  void swap(SoundEffectInstance& other);
93 
99  void setLooped(bool value);
107  void setVolume(float value);
108 
112  bool isPlaying() const;
113 
121  void play();
129  void stop();
130 
131 private:
136  void stopIfNecessary(bool isStopped);
141  void updateVolume();
145  void applyPlay();
149  void applyStop();
150 
151  QSharedPointer<QSoundEffect> mSoundEffect;
152  bool mLooped = false;
153  float mVolume = 1.0f;
154 
155  // Indicates if this instance is currently playing, and is looped.
156  bool mPlayingLooped = false;
157 };
158 
159 #endif // SOUNDEFFECTINSTANCE_H
An instance of a sound effect.
Definition: SoundEffectInstance.h:36
bool isPlaying() const
Returns whether or not this sample is currently playing.
void play()
Starts playing this instance of the sound effect.
void setLooped(bool value)
Sets property to play looped or as a one-shot sound effect.
void reset()
Releases the reference to the shared QSoundEffect, stopping it if necessary.
SoundEffectInstance & operator=(SoundEffectInstance &&other)
Move assigns other to this SoundEffectInstance instance.
SoundEffectInstance()
Create a SoundEffectInstance referencing nothing.
void stop()
Stops the sample if it is currently playing.
void setVolume(float value)
Sets play volume property.
void swap(SoundEffectInstance &other)
Swaps QSoundEffect references and parameters with another SoundEffectInstance.