Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Source.h
Go to the documentation of this file.
1 //
2 // C++ Interface: Audio::Source
3 //
4 #ifndef __AUDIO_SOURCE_H__INCLUDED__
5 #define __AUDIO_SOURCE_H__INCLUDED__
6 
7 #include "Exceptions.h"
8 #include "Types.h"
9 #include "Format.h"
10 #include "RenderableSource.h"
11 
12 namespace Audio {
13 
14  // Forward declarations
15 
16  class Sound;
17  class Listener;
18  class SourceListener;
19 
20 
36  class Source
37  {
38  private:
39  SharedPtr<Sound> soundPtr;
40  SharedPtr<RenderableSource> rendererDataPtr;
41  SharedPtr<UserData> userDataPtr;
42  long userDataLong;
43  SharedPtr<SourceListener> sourceListenerPtr;
44 
45  protected:
49 
51 
55 
57 
58  struct {
59  int looping : 1;
60  int attenuated : 1;
61  int relative : 1;
62  } flags;
63 
66 
71  struct {
73  int location : 1;
74 
76  int attributes : 1;
77 
79  int gain : 1;
80 
82  int soundPtr : 1;
83 
85  int soundAttributes : 1;
86 
87  void reset()
88  {
89  location = 0;
90  attributes = 0;
91  gain = 0;
92  soundPtr = 0;
93  soundAttributes = 0;
94  }
95 
96  void setAll()
97  {
98  location = 1;
99  attributes = 1;
100  gain = 1;
101  soundAttributes = 1;
102  }
103  } dirty;
104 
105  protected:
107  Source(SharedPtr<Sound> sound, bool looping = false) throw();
108 
109  public:
110  virtual ~Source();
111 
113  LVector3 getPosition() const throw() { return position; }
114 
116  void setPosition(LVector3 x) throw() { position = x; dirty.location = 1; }
117 
119  Vector3 getDirection() const throw() { return direction; }
120 
122  void setDirection(Vector3 x) throw() { direction = x; dirty.location = 1; }
123 
125  Vector3 getVelocity() const throw() { return velocity; }
126 
128  void setVelocity(Vector3 x) throw() { velocity = x; dirty.location = 1; }
129 
135  Range<Scalar> getAngleRange() const throw();
136 
138  void setAngleRange(Range<Scalar> r) throw();
139 
141  Range<Scalar> getCosAngleRange() const throw() { return cosAngleRange; }
142 
144  void setCosAngleRange(Range<Scalar> r) throw() { cosAngleRange = r; dirty.attributes = 1; }
145 
147  Scalar getRadius() const throw() { return radius; }
148 
150  void setRadius(Scalar r) throw() { radius = r; dirty.attributes = 1; }
151 
159 
163  void setPerFrequencyRadiusRatios(PerFrequency<Scalar> val) throw() { pfRadiusRatios = val; dirty.attributes = 1; }
164 
167 
169  void setReferenceFreqs(PerFrequency<Scalar> val) throw() { referenceFreqs = val; dirty.attributes = 1; }
170 
172  Scalar getGain() const throw() { return gain; }
173 
175  void setGain(Scalar g) throw() { gain = g; dirty.gain = 1; }
176 
178  bool isLooping() const throw() { return flags.looping != 0; }
179 
181  void setLooping(bool loop) throw() { flags.looping = loop ? 1 : 0; dirty.soundAttributes = 1; }
182 
184  bool isAttenuated() const throw() { return flags.attenuated != 0; }
185 
187  void setAttenuated(bool attenuated) throw() { flags.attenuated = attenuated ? 1 : 0; dirty.attributes = 1; }
188 
194  bool isRelative() const throw() { return flags.relative != 0; }
195 
197  void setRelative(bool relative) throw() { flags.relative = relative ? 1 : 0; dirty.attributes = 1; }
198 
204  void startPlaying(Timestamp start = 0) throw(Exception);
205 
211  void stopPlaying() throw();
212 
220  void pausePlaying() throw();
221 
226  void continuePlaying() throw(Exception);
227 
229  bool isPlaying() const throw();
230 
232  bool isActive() const throw();
233 
235  Timestamp getPlayingTime() const throw();
236 
240  Timestamp getWouldbePlayingTime() const throw();
241 
243  SharedPtr<RenderableSource> getRenderable() const throw() { return rendererDataPtr; }
244 
246  void setRenderable(SharedPtr<RenderableSource> ptr) throw();
247 
249  SharedPtr<UserData> getUserDataPtr() const throw() { return userDataPtr; }
250 
252  void setUserDataLong(SharedPtr<UserData> ptr) throw() { userDataPtr = ptr; }
253 
255  long getUserDataLong() const throw() { return userDataLong; }
256 
258  void setUserDataLong(long data) throw() { userDataLong = data; }
259 
261  SharedPtr<SourceListener> getSourceListener() const throw() { return sourceListenerPtr; }
262 
264  void setSourceListener(SharedPtr<SourceListener> ptr) throw() { sourceListenerPtr = ptr; }
265 
267  SharedPtr<Sound> getSound() const throw() { return soundPtr; }
268 
270  void setSound(SharedPtr<Sound> ptr) throw() { soundPtr = ptr; dirty.soundPtr = 1; }
271 
276  void updateRenderable(int flags, const Listener& sceneListener) throw();
277 
286  void seek(Timestamp time) throw(Exception);
287 
288  protected:
292  Timestamp setLastKnownPlayingTime(Timestamp timestamp) throw();
293 
294  // The following section contains all the virtual functions that need be implemented
295  // by a concrete Sound class. All are protected, so the stream interface is independent
296  // of implementations.
297  protected:
298 
302  virtual void startPlayingImpl(Timestamp start) throw(Exception) = 0;
303 
305  virtual void stopPlayingImpl() throw(Exception) = 0;
306 
308  virtual bool isPlayingImpl() const throw(Exception) = 0;
309 
310  // The following section contains package-private stuff
311  // They're intended for plugin developers, and not end users
312  public:
313 
326  void _notifyPlaying() throw();
327  };
328 
329 };
330 
331 #endif//__AUDIO_SOURCE_H__INCLUDED__