2 * \file source_music_channel.cpp
3 * \brief CSourceMusicChannel
4 * \date 2012-04-11 16:08GMT
5 * \author Jan Boon (Kaetemi)
9 // NeL - MMORPG Framework <https://wiki.ryzom.dev/>
10 // Copyright (C) 2012 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
12 // This program is free software: you can redistribute it and/or modify
13 // it under the terms of the GNU Affero General Public License as
14 // published by the Free Software Foundation, either version 3 of the
15 // License, or (at your option) any later version.
17 // This program is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU Affero General Public License for more details.
22 // You should have received a copy of the GNU Affero General Public License
23 // along with this program. If not, see <http://www.gnu.org/licenses/>.
26 #include <nel/sound/source_music_channel.h>
31 // #include <nel/misc/debug.h>
32 #include <nel/sound/stream_file_source.h>
37 // using namespace NLMISC;
41 CSourceMusicChannel::CSourceMusicChannel() : m_Source(NULL
), m_Gain(1.0f
)
46 CSourceMusicChannel::~CSourceMusicChannel()
53 bool CSourceMusicChannel::play(const std::string
&filepath
, bool async
, bool loop
)
55 // delete previous source if any
56 // note that this waits for the source's thread to finish if the source was still playing
60 m_Sound
.setMusicFilePath(filepath
, async
, loop
);
62 m_Source
= new CStreamFileSource(&m_Sound
, false, NULL
, NULL
, NULL
, NULL
);
63 m_Source
->setSourceRelativeMode(true);
64 m_Source
->setPos(NLMISC::CVector::Null
);
65 m_Source
->setRelativeGain(m_Gain
);
69 return m_Source
->isPlaying();
72 void CSourceMusicChannel::stop()
74 // stop but don't delete the source, deleting source may cause waiting for thread
79 void CSourceMusicChannel::reset()
81 // forces the source to be deleted, happens when audio mixer is reset
86 void CSourceMusicChannel::pause()
92 void CSourceMusicChannel::resume()
98 bool CSourceMusicChannel::isEnded()
102 if (m_Source
->isEnded())
104 // we can delete the source now without worrying about thread wait
114 bool CSourceMusicChannel::isLoadingAsync()
117 return m_Source
->isLoadingAsync();
121 float CSourceMusicChannel::getLength()
124 return m_Source
->getLength();
128 void CSourceMusicChannel::setVolume(float gain
)
132 m_Source
->setRelativeGain(gain
);
135 } /* namespace NLSOUND */