Merge branch 'ryzom/ark-features' into main/gingo-test
[ryzomcore.git] / nel / src / sound / music_sound.cpp
bloba2b61c5adf178cfccd2e782d0a0eedfb2811a0cc
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_sound.h"
24 #include "nel/misc/path.h"
25 #include "nel/georges/u_form_elm.h"
27 #if NLSOUND_SHEET_VERSION_BUILT < 2
28 # include "nel/sound/group_controller_root.h"
29 #endif
31 using namespace std;
32 using namespace NLMISC;
34 namespace NLSOUND {
37 // ***************************************************************************
38 CMusicSound::CMusicSound()
40 // init with NULL in case of unexcepted access
41 _FileName= NULL;
42 _FadeInLength= 2000;
43 _FadeOutLength= 2000;
44 _MinimumPlayTime= 10000;
45 _TimeBeforeCanReplay= 0;
46 LastStopTime= INT_MIN;
49 // ***************************************************************************
50 CMusicSound::~CMusicSound()
55 // ***************************************************************************
56 void CMusicSound::importForm(const std::string& filename, NLGEORGES::UFormElm& root)
58 NLGEORGES::UFormElm *psoundType;
59 std::string dfnName;
61 // some basic checking.
62 root.getNodeByName(&psoundType, ".SoundType");
63 nlassert(psoundType != NULL);
64 psoundType->getDfnName(dfnName);
65 nlassert(dfnName == "music_sound.dfn");
67 // Call the base class
68 CSound::importForm(filename, root);
70 // fileName
71 std::string musicFileName;
72 root.getValueByName(musicFileName, ".SoundType.FileName");
73 musicFileName = CFile::getFilename(musicFileName);
74 _FileName = CStringMapper::map(musicFileName);
76 // Other params
77 root.getValueByName(_FadeInLength, ".SoundType.FadeInLength");
78 root.getValueByName(_FadeOutLength, ".SoundType.FadeOutLength");
79 root.getValueByName(_MinimumPlayTime, ".SoundType.MinimumPlayTime");
80 root.getValueByName(_TimeBeforeCanReplay, ".SoundType.TimeBeforeCanReplay");
82 #if NLSOUND_SHEET_VERSION_BUILT < 2
83 _GroupController = CGroupControllerRoot::getInstance()->getGroupController(NLSOUND_SHEET_V1_DEFAULT_SOUND_MUSIC_GROUP_CONTROLLER);
84 #endif
88 // ***************************************************************************
89 uint32 CMusicSound::getDuration()
91 // Cannot know the length of this music sound.
92 // Since its not really a sound (played in another "channel"), suppose 0
93 return 0;
96 // ***************************************************************************
97 void CMusicSound::getSubSoundList(std::vector<std::pair<std::string, CSound*> > &subsounds) const
99 subsounds.clear();
102 // ***************************************************************************
103 void CMusicSound::serial(NLMISC::IStream &s)
105 s.serialVersion(0);
106 CSound::serial(s);
108 CStringMapper::serialString(s, _FileName);
109 s.serial(_FadeInLength, _FadeOutLength);
110 s.serial(_MinimumPlayTime, _TimeBeforeCanReplay);
112 #if NLSOUND_SHEET_VERSION_BUILT < 2
113 if (s.isReading()) _GroupController = CGroupControllerRoot::getInstance()->getGroupController(NLSOUND_SHEET_V1_DEFAULT_SOUND_MUSIC_GROUP_CONTROLLER);
114 #endif
118 // ***************************************************************************
119 float CMusicSound::getMaxDistance() const
121 // used in background_sound_manager, since 2D sound, return 0 because
122 // the sound must be cut once out of the patat
123 return 0.f;
126 // ***************************************************************************
127 bool CMusicSound::isDetailed() const
129 return false;
134 } // NLSOUND