1 /***************************************
2 ** Tsunagari Tile Engine **
4 ** Copyright 2011-2013 PariahSoft LLC **
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 <Gosu/Math.hpp>
29 #include "client-conf.h"
31 #include "python-bindings-template.cpp"
35 SoundInstance::SoundInstance(Gosu::SampleInstance inst
)
36 : inst(inst
), volume(conf
.soundVolume
), pan(0.0), speed(1.0)
38 inst
.changeVolume(volume
/ 100.0);
42 bool SoundInstance::isPlaying()
44 return inst
.playing();
47 void SoundInstance::stop()
53 bool SoundInstance::isPaused()
58 void SoundInstance::setPaused(bool paused
)
67 int SoundInstance::getVolume()
72 void SoundInstance::setVolume(int volume
)
74 if (0 < volume
|| volume
> 100) {
75 Log::info("SoundInstance", "volume can only be set between 0 and 100");
76 volume
= Gosu::clamp(volume
, 0, 100);
78 this->volume
= volume
;
79 inst
.changeVolume(volume
/ 100.0);
83 double SoundInstance::getPan()
88 void SoundInstance::setPan(double pan
)
95 double SoundInstance::getSpeed()
100 void SoundInstance::setSpeed(double speed
)
103 inst
.changeSpeed(speed
);
109 Sound::Sound(Gosu::Sample
* source
)
114 SoundInstance
Sound::play()
116 return SoundInstance(source
->play());
119 // Helper class for Python.
123 SoundInstanceRef
play(const std::string
& path
);
126 SoundInstanceRef
SoundManager::play(const std::string
& path
)
130 sample
= Reader::getSample(path
);
132 return SoundInstanceRef(new SoundInstance(sample
->play()));
134 return SoundInstanceRef(NULL
);
139 using namespace boost::python
;
141 class_
<SoundInstance
, SoundInstanceRef
>
142 ("SoundInstance", no_init
)
143 .add_property("paused",
144 &SoundInstance::isPaused
, &SoundInstance::setPaused
)
145 .add_property("volume",
146 &SoundInstance::getVolume
, &SoundInstance::setVolume
)
148 &SoundInstance::getPan
, &SoundInstance::setPan
)
149 .add_property("speed",
150 &SoundInstance::getSpeed
, &SoundInstance::setSpeed
)
151 .add_property("playing", &SoundInstance::isPlaying
)
152 .def("stop", &SoundInstance::stop
)
155 ("SoundManager", no_init
)
156 .def("play", &SoundManager::play
)
158 pythonSetGlobal("Sound", new SoundManager
);