]> git.tdb.fi Git - libs/al.git/blob - source/soundscape.cpp
Add more methods to Source
[libs/al.git] / source / soundscape.cpp
1 /* $Id$
2
3 This file is part of libmspal
4 Copyright © 2008 Mikko Rasa, Mikkosoft Productions
5 Diestributed under the LGPL
6 */
7
8 #include "source.h"
9 #include "soundscape.h"
10
11 using namespace std;
12
13 namespace Msp {
14 namespace AL {
15
16 SoundScape::~SoundScape()
17 {
18         for(list<Source *>::iterator i=sources.begin(); i!=sources.end(); ++i)
19                 delete *i;
20 }
21
22 void SoundScape::add_source(Source *src)
23 {
24         sources.push_back(src);
25 }
26
27 Source *SoundScape::play(const Buffer &buf, float x, float y, float z)
28 {
29         Source *src=new Source;
30         add_source(src);
31         src->set_buffer(buf);
32         src->set_position(x, y, z);
33         src->play();
34         return src;
35 }
36
37 void SoundScape::tick()
38 {
39         for(list<Source *>::iterator i=sources.begin(); i!=sources.end();)
40         {
41                 if((*i)->get_state()==STOPPED)
42                 {
43                         delete *i;
44                         i=sources.erase(i);
45                 }
46                 else
47                         ++i;
48         }
49 }
50
51 } // namespace AL
52 } // namespace Msp