Fix "no remove aqua speed" bug when player leaves the water
[ryzomcore.git] / nel / src / sound / music_source.cpp
blobf77052d4eeab5ed7c8bd8d83edadbe318148f809
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2010 Matt RAYKOWSKI (sfb) <matt.raykowski@gmail.com>
6 // Copyright (C) 2012 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
7 //
8 // This program is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU Affero General Public License as
10 // published by the Free Software Foundation, either version 3 of the
11 // License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU Affero General Public License for more details.
18 // You should have received a copy of the GNU Affero General Public License
19 // along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "stdsound.h"
23 #include "nel/sound/music_source.h"
24 #include "nel/sound/music_sound.h"
25 #include "nel/sound/audio_mixer_user.h"
26 #include "nel/sound/music_sound_manager.h"
29 namespace NLSOUND {
32 // ***************************************************************************
33 CMusicSource::CMusicSource(CMusicSound *musicSound, bool spawn, TSpawnEndCallback cb, void *cbUserParam, NL3D::CCluster *cluster, CGroupController *groupController)
34 : CSourceCommon(musicSound, spawn, cb, cbUserParam, cluster, groupController)
36 _MusicSound= musicSound;
39 // ***************************************************************************
40 CMusicSource::~CMusicSource()
42 if(isPlaying())
43 stop();
45 // avoid any bug, ensure the source is removed
46 CAudioMixerUser::instance()->getBackgroundMusicManager()->removeMusicSourcePlaying(this);
49 // ***************************************************************************
50 TSoundId CMusicSource::getSound()
52 return _MusicSound;
55 // ***************************************************************************
56 void CMusicSource::play()
58 // if already playing, no-op (don't restart)
59 if(isPlaying())
60 return;
62 // append and play common
63 CAudioMixerUser::instance()->getBackgroundMusicManager()->addMusicSourcePlaying(this);
64 CSourceCommon::play();
67 // ***************************************************************************
68 void CMusicSource::stop()
70 // if already non-playing, no-op (don't restop)
71 if(!isPlaying())
72 return;
74 // remove and stop common
75 CAudioMixerUser::instance()->getBackgroundMusicManager()->removeMusicSourcePlaying(this);
76 CSourceCommon::stop();
80 } // NLSOUND