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
Audio::RenderableSource Class Referenceabstract

#include <RenderableSource.h>

Inheritance diagram for Audio::RenderableSource:
Audio::UserData Audio::OpenALRenderableSource Audio::OpenALRenderableStreamingSource

Public Types

enum  UpdateFlags {
  UPDATE_ALL = 0x0F, UPDATE_LOCATION = 0x01, UPDATE_ATTRIBUTES = 0x02, UPDATE_EFFECTS = 0x04,
  UPDATE_GAIN = 0x08
}
 

Public Member Functions

virtual ~RenderableSource ()
 
void startPlaying (Timestamp start=0) throw (Exception)
 
void stopPlaying () throw ()
 
bool isPlaying () const throw ()
 
Timestamp getPlayingTime () const throw (Exception)
 
SourcegetSource () const throw ()
 
void seek (Timestamp time) throw (Exception)
 
void update (int flags, const Listener &sceneListener) throw ()
 
- Public Member Functions inherited from Audio::UserData
virtual ~UserData ()
 

Protected Member Functions

 RenderableSource (Source *source) throw ()
 
virtual void startPlayingImpl (Timestamp start)=0 throw (Exception)
 
virtual void stopPlayingImpl ()=0 throw (Exception)
 
virtual bool isPlayingImpl () const =0 throw (Exception)
 
virtual Timestamp getPlayingTimeImpl () const =0 throw (Exception)
 
virtual void updateImpl (int flags, const Listener &sceneListener)=0 throw (Exception)
 
virtual void seekImpl (Timestamp time)=0 throw (Exception)
 

Detailed Description

Renderable Source abstract class

Remarks
This is the interface to renderer-specific sources. All abstract sources must get attached to a renderable source. And each renderable source is attached to an abstract source.
All attributes come from the abstract source, so this class only has renderer-specific
state and resources, plus implementation functions. Since it is intended to be attached to abstract sources as any user data would, it is a subclass of UserData.
Note
Since this mutual attachment would create circular references, it is implemented on this side with raw pointers. No problem should arise since the smart pointer used in abstract sources already handles everything correctly, but care must be had not to have detached renderable sources around.

Definition at line 34 of file RenderableSource.h.

Member Enumeration Documentation

Enumerator
UPDATE_ALL 
UPDATE_LOCATION 
UPDATE_ATTRIBUTES 
UPDATE_EFFECTS 
UPDATE_GAIN 

Definition at line 46 of file RenderableSource.h.

46  {
47  UPDATE_ALL = 0x0F,
48  UPDATE_LOCATION = 0x01,
49  UPDATE_ATTRIBUTES = 0x02,
50  UPDATE_EFFECTS = 0x04,
51  UPDATE_GAIN = 0x08
52  };

Constructor & Destructor Documentation

Audio::RenderableSource::RenderableSource ( Source source)
throw (
)
protected

Internal constructor used by derived classes

Definition at line 11 of file RenderableSource.cpp.

11  :
12  source(_source)
13  {
14  }
Audio::RenderableSource::~RenderableSource ( )
virtual

Definition at line 16 of file RenderableSource.cpp.

17  {
18  // Just in case.
19  source = 0;
20  }

Member Function Documentation

Timestamp Audio::RenderableSource::getPlayingTime ( ) const
throw (Exception
)

Get the playing position of a playing source

Remarks
Will throw if it's not playing!

Definition at line 57 of file RenderableSource.cpp.

References getPlayingTimeImpl().

59  {
60  return getPlayingTimeImpl();
61  }
virtual Timestamp Audio::RenderableSource::getPlayingTimeImpl ( ) const
throw (Exception
)
protectedpure virtual
Source* Audio::RenderableSource::getSource ( ) const
throw (
)
inline
bool Audio::RenderableSource::isPlaying ( ) const
throw (
)

Is the source still playing?

Definition at line 45 of file RenderableSource.cpp.

References e, and isPlayingImpl().

Referenced by stopPlaying().

47  {
48  try {
49  return isPlayingImpl();
50  } catch(Exception e) {
51  // Cannot be playing if an exception rises,
52  // as that implies a problem with the underlying API
53  return false;
54  }
55  }
virtual bool Audio::RenderableSource::isPlayingImpl ( ) const
throw (Exception
)
protectedpure virtual
void Audio::RenderableSource::seek ( Timestamp  time)
throw (Exception
)

Seek to the specified position

Note
It may not be supported by the renderer on all sources. Streaming sources are guaranteed to perform a rough seek on a best effort basis, meaning the effective time after the seek may be off a bit, and the process may be costly. Seeking in non-streaming sources may not be supported at all.
Exceptions
EndOfStreamExceptionif you try to seek past the end

Definition at line 73 of file RenderableSource.cpp.

75  {
76  seekImpl(time);
77  }
virtual void Audio::RenderableSource::seekImpl ( Timestamp  time)
throw (Exception
)
protectedpure virtual
void Audio::RenderableSource::startPlaying ( Timestamp  start = 0)
throw (Exception
)

Play the source from the specified timestamp

Parameters
startThe starting position. Defaults to the beginning.
Remarks
It just plays. Will not synchronize attributes with the underlying API. That must be done through a separate update() call.

Definition at line 22 of file RenderableSource.cpp.

References start.

24  {
25  try {
27  } catch(EndOfStreamException) {
28  // Silently discard EOS, results in the more transparent
29  // behavior of simply notifying listeners of source
30  // termination ASAP, which is also accurate.
31  };
32  }
virtual void Audio::RenderableSource::startPlayingImpl ( Timestamp  start)
throw (Exception
)
protectedpure virtual
See Also
startPlaying
Parameters
startThe starting position.

Implemented in Audio::OpenALRenderableStreamingSource, and Audio::OpenALRenderableSource.

void Audio::RenderableSource::stopPlaying ( )
throw (
)

Stop a playing source

Remarks
If the source is playing, stop it. Otherwise, do nothing.

Definition at line 34 of file RenderableSource.cpp.

References e, isPlaying(), and stopPlayingImpl().

36  {
37  // Cannot be playing if an exception rises,
38  // as that implies a problem with the underlying API
39  try {
40  if (isPlaying())
42  } catch(Exception e) {}
43  }
virtual void Audio::RenderableSource::stopPlayingImpl ( )
throw (Exception
)
protectedpure virtual
void Audio::RenderableSource::update ( int  flags,
const Listener sceneListener 
)
throw (
)

Update the underlying API with dirty attributes

Parameters
flagsYou may specify which attributes to update. Not all attributes are equally costly, so you'll want to ease up on some, pump up some others. You may or-combine flags.
sceneListenerA reference listener. If it is the root listener attached to the renderer, no special translation is done, but if it is not, coordinates will be first translated to listener-space.
Remarks
Although the implementation may throw exceptions, the interface will ignore them (just log them or something like that). Updates are non-critical and may fail silently.

Definition at line 63 of file RenderableSource.cpp.

References e, fprintf, and Audio::Exception::what().

65  {
66  try {
67  updateImpl(flags, sceneListener);
68  } catch(Exception e) {
69  fprintf(stderr, "Ignoring exception in renderable update: %s", e.what());
70  }
71  }
virtual void Audio::RenderableSource::updateImpl ( int  flags,
const Listener sceneListener 
)
throw (Exception
)
protectedpure virtual

The documentation for this class was generated from the following files: