1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010-2019 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2010 Matt RAYKOWSKI (sfb) <matt.raykowski@gmail.com>
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "nel/sound/sample_bank_manager.h"
26 #include "nel/misc/path.h"
27 #include "nel/misc/file.h"
30 #include "nel/sound/driver/sound_driver.h"
31 #include "nel/sound/driver/buffer.h"
32 #include "nel/sound/sample_bank.h"
33 #include "nel/sound/async_file_manager_sound.h"
34 #include "nel/sound/background_sound_manager.h"
35 #include "nel/sound/sound_bank.h"
38 using namespace NLMISC
;
42 CSampleBankManager::CSampleBankManager(CAudioMixerUser
*audioMixer
) : m_AudioMixer(audioMixer
), m_LoadedSize(0)
47 CSampleBankManager::~CSampleBankManager()
53 void CSampleBankManager::init(NLGEORGES::UFormElm
*mixerConfig
)
58 NLGEORGES::UFormElm
*virtualBanks
;
59 mixerConfig
->getNodeByName(&virtualBanks
, ".VirtualBanks");
60 if (virtualBanks
== 0)
64 virtualBanks
->getArraySize(size
);
66 for (uint i
=0; i
<size
; ++i
)
68 NLGEORGES::UFormElm
*virtualBank
;
69 virtualBanks
->getArrayNode(&virtualBank
, i
);
73 std::vector
<TFilteredBank
> vfb
;
74 std::string virtualName
;
75 virtualBank
->getValueByName(virtualName
, ".VirtualName");
76 NLGEORGES::UFormElm
*realBanks
;
77 virtualBank
->getNodeByName(&realBanks
, ".FilteredBank");
81 realBanks
->getArraySize(size2
);
83 for (uint j
=0; j
<size2
; ++j
)
87 NLGEORGES::UFormElm
*realBank
= NULL
;
88 realBanks
->getArrayNode(&realBank
, j
);
91 realBank
->getValueByName(bankName
, ".SampleBank");
92 fb
.BankName
= CStringMapper::map(bankName
);
93 realBank
->getValueByName(fb
.Filter
, ".Filter");
101 TStringId virtualNameId
= CStringMapper::map(virtualName
);
102 m_VirtualBanks
.insert(std::make_pair(virtualNameId
, vfb
));
103 // create the sample bank
104 CSampleBank
*sampleBank
= new CSampleBank(virtualNameId
, this);
110 void CSampleBankManager::releaseAll()
112 // nldebug("SampleBanks: Releasing...");
113 while (!m_Banks
.empty())
115 delete m_Banks
.begin()->second
;
117 // nldebug("SampleBanks: Released");
120 CSampleBank
*CSampleBankManager::findSampleBank(const NLMISC::TStringId
&filename
)
122 TSampleBankContainer::iterator
it(m_Banks
.find(filename
));
124 if (it
!= m_Banks
.end())
130 IBuffer
*CSampleBankManager::get(const NLMISC::TStringId
&name
)
133 TSampleBankContainer::iterator iter
;
135 for (iter
= m_Banks
.begin(); iter
!= m_Banks
.end(); ++iter
)
137 buffer
= iter
->second
->getSample(name
);
144 //nlwarning ("Try to get an unknown sample '%s'", name);
148 void CSampleBankManager::reload(bool async
)
150 TSampleBankContainer::iterator
first(m_Banks
.begin()), last(m_Banks
.end());
152 for (; first
!= last
; ++first
)
154 first
->second
->unload();
155 first
->second
->load(async
);
160 void CSampleBankManager::getLoadedSampleBankInfo(std::vector
<std::pair
<std::string
, uint
> > &result
)
164 TSampleBankContainer::iterator
first(m_Banks
.begin()), last(m_Banks
.end());
165 for (; first
!= last
; ++first
)
167 std::pair
<std::string
, uint
> p
;
168 if (first
->second
->isLoaded())
170 p
.first
= NLMISC::CStringMapper::unmap(first
->first
);
171 p
.second
= first
->second
->getSize();
177 } /* namespace NLSOUND */