1 /*********************************
2 ** Tsunagari Tile Engine **
4 ** Copyright 2011-2012 OmegaSDG **
5 *********************************/
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to
10 // deal in the Software without restriction, including without limitation the
11 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12 // sell copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
27 #include <boost/shared_ptr.hpp>
30 #include "resourcer.h"
33 SoundInstance::SoundInstance(boost::optional
<Gosu::SampleInstance
> inst
)
34 : inst(inst
), volume(1.0), pan(0.0), speed(1.0)
39 bool SoundInstance::isPlaying()
41 return inst
&& inst
->playing();
44 void SoundInstance::stop()
51 bool SoundInstance::isPaused()
53 return inst
? inst
->paused() : false;
56 void SoundInstance::setPaused(bool paused
)
67 double SoundInstance::getVolume()
72 void SoundInstance::setVolume(double volume
)
74 this->volume
= volume
;
76 inst
->changeVolume(volume
);
80 double SoundInstance::getPan()
85 void SoundInstance::setPan(double pan
)
93 double SoundInstance::getSpeed()
98 void SoundInstance::setSpeed(double speed
)
102 inst
->changeSpeed(speed
);
108 Sound::Sound(Gosu::Sample
* source
)
113 SoundInstance
Sound::play()
115 return SoundInstance(source
->play());
118 // Helper class for Python.
122 SoundInstance
play(const std::string
& path
);
125 SoundInstance
SoundManager::play(const std::string
& path
)
130 rc
= Resourcer::instance();
131 sample
= rc
->getSample(path
);
133 return sample
->play();
135 return SoundInstance(NULL
);
140 boost::python::class_
<SoundInstance
>
141 ("SoundInstance", boost::python::no_init
)
142 .add_property("paused",
143 &SoundInstance::isPaused
, &SoundInstance::setPaused
)
144 .add_property("volume",
145 &SoundInstance::getVolume
, &SoundInstance::setVolume
)
147 &SoundInstance::getPan
, &SoundInstance::setPan
)
148 .add_property("speed",
149 &SoundInstance::getSpeed
, &SoundInstance::setSpeed
)
150 .add_property("playing", &SoundInstance::isPlaying
)
151 .def("stop", &SoundInstance::stop
)
153 boost::python::class_
<SoundManager
>
154 ("SoundManager", boost::python::no_init
)
155 .def("play", &SoundManager::play
)
157 pythonSetGlobal("Sound", new SoundManager
);