Change Encyclo button name and macros icon
[ryzomcore.git] / nel / src / sound / source_music_channel.cpp
blob508521aa381dd1e916333f82c1c6fe97b30c101b
1 /**
2 * \file source_music_channel.cpp
3 * \brief CSourceMusicChannel
4 * \date 2012-04-11 16:08GMT
5 * \author Jan Boon (Kaetemi)
6 * CSourceMusicChannel
7 */
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/>.
25 #include "stdsound.h"
26 #include <nel/sound/source_music_channel.h>
28 // STL includes
30 // NeL includes
31 // #include <nel/misc/debug.h>
32 #include <nel/sound/stream_file_source.h>
34 // Project includes
36 using namespace std;
37 // using namespace NLMISC;
39 namespace NLSOUND {
41 CSourceMusicChannel::CSourceMusicChannel() : m_Source(NULL), m_Gain(1.0f)
46 CSourceMusicChannel::~CSourceMusicChannel()
48 nlassert(!m_Source);
49 delete m_Source;
50 m_Source = NULL;
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
57 if (m_Source)
58 delete m_Source;
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);
67 m_Source->play();
69 return m_Source->isPlaying();
72 void CSourceMusicChannel::stop()
74 // stop but don't delete the source, deleting source may cause waiting for thread
75 if (m_Source)
76 m_Source->stop();
79 void CSourceMusicChannel::reset()
81 // forces the source to be deleted, happens when audio mixer is reset
82 delete m_Source;
83 m_Source = NULL;
86 void CSourceMusicChannel::pause()
88 if (m_Source)
89 m_Source->pause();
92 void CSourceMusicChannel::resume()
94 if (m_Source)
95 m_Source->resume();
98 bool CSourceMusicChannel::isEnded()
100 if (m_Source)
102 if (m_Source->isEnded())
104 // we can delete the source now without worrying about thread wait
105 delete m_Source;
106 m_Source = NULL;
107 return true;
109 return false;
111 return true;
114 bool CSourceMusicChannel::isLoadingAsync()
116 if (m_Source)
117 return m_Source->isLoadingAsync();
118 return false;
121 float CSourceMusicChannel::getLength()
123 if (m_Source)
124 return m_Source->getLength();
125 return 0.0f;
128 void CSourceMusicChannel::setVolume(float gain)
130 m_Gain = gain;
131 if (m_Source)
132 m_Source->setRelativeGain(gain);
135 } /* namespace NLSOUND */
137 /* end of file */