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
35 pythonSetGlobal("Music", this);
40 if (musicInst
&& musicInst
->playing())
44 std::string
Music::getIntro()
49 std::string
Music::getLoop()
54 void Music::setIntro(const std::string
& filename
)
56 if (newIntro
== filename
)
63 setState(CHANGED_INTRO
);
67 Resourcer
* rc
= Resourcer::instance();
70 // Optimize XXX: Don't load until played.
71 introMusic
= filename
.size() ?
72 rc
->getSong(filename
) : SongRef();
75 void Music::setLoop(const std::string
& filename
)
77 if (newLoop
== filename
)
84 setState(CHANGED_LOOP
);
88 Resourcer
* rc
= Resourcer::instance();
91 // Optimize XXX: Don't load until played.
92 loopMusic
= filename
.size() ?
93 rc
->getSong(filename
) : SongRef();
96 double Music::getVolume()
101 void Music::setVolume(double level
)
105 musicInst
->changeVolume(level
);
108 bool Music::isPaused()
113 void Music::setPaused(bool p
)
141 if (musicInst
&& musicInst
->playing())
145 if (!musicInst
->playing()) {
146 if (newLoop
.size() && loopMusic
)
149 setState(NOT_PLAYING
);
155 if (newIntro
.size() && introMusic
)
157 else if (newLoop
.size() && newLoop
!= curLoop
)
158 setState(CHANGED_LOOP
);
159 else if (newLoop
.size())
160 setState(PLAYING_LOOP
);
162 setState(NOT_PLAYING
);
165 if (newIntro
.size() && loopMusic
)
167 else if (newLoop
.size() && loopMusic
)
170 setState(NOT_PLAYING
);
175 void Music::playIntro()
177 if (musicInst
&& musicInst
->playing())
180 introMusic
->play(false);
181 introMusic
->changeVolume(volume
);
182 musicInst
= introMusic
;
183 setState(PLAYING_INTRO
);
186 void Music::playLoop()
188 if (musicInst
&& musicInst
->playing())
191 loopMusic
->play(true);
192 loopMusic
->changeVolume(volume
);
193 musicInst
= loopMusic
;
194 setState(PLAYING_LOOP
);
198 static const char* stateStr(MUSIC_STATE state)
202 return "NOT_PLAYING";
204 return "PLAYING_INTRO";
206 return "PLAYING_LOOP";
208 return "CHANGED_INTRO";
210 return "CHANGED_LOOP";
217 void Music::setState(MUSIC_STATE state
)
219 // printf("State changed from %s to %s.\n", stateStr(this->state), stateStr(state));
225 boost::python::class_
<Music
>("MusicManager", boost::python::no_init
)
226 .add_property("intro", &Music::getIntro
, &Music::setIntro
)
227 .add_property("loop", &Music::getLoop
, &Music::setLoop
)
228 .add_property("volume", &Music::getVolume
, &Music::setVolume
)
229 .add_property("paused", &Music::isPaused
, &Music::setPaused
)
230 .def("stop", &Music::stop
)