| 4826 | } |
| 4827 | |
| 4828 | var ScriptingApi::Sampler::importSamples(var fileNameList, bool skipExistingSamples) |
| 4829 | { |
| 4830 | #if HI_ENABLE_EXPANSION_EDITING |
| 4831 | if (fileNameList.isArray() && fileNameList.getArray()->size() == 0) |
| 4832 | return fileNameList; |
| 4833 | |
| 4834 | WARN_IF_AUDIO_THREAD(true, ScriptGuard::IllegalApiCall); |
| 4835 | |
| 4836 | ModulatorSampler *s = static_cast<ModulatorSampler*>(sampler.get()); |
| 4837 | |
| 4838 | if (s != nullptr) |
| 4839 | { |
| 4840 | auto start = Time::getMillisecondCounter(); |
| 4841 | |
| 4842 | SuspendHelpers::ScopedTicket ticket(s->getMainController()); |
| 4843 | |
| 4844 | s->getMainController()->getKillStateHandler().killVoicesAndWait(); |
| 4845 | |
| 4846 | LockHelpers::SafeLock sl(s->getMainController(), LockHelpers::Type::SampleLock); |
| 4847 | |
| 4848 | auto sampleExists = [s](PoolReference r) |
| 4849 | { |
| 4850 | auto fileName = r.getFile().getFullPathName(); |
| 4851 | |
| 4852 | for (int i = 0; i < s->getNumSounds(); i++) |
| 4853 | { |
| 4854 | if (auto sound = dynamic_cast<ModulatorSamplerSound*>(s->getSound(i))) |
| 4855 | { |
| 4856 | auto f = sound->getPropertyAsString(SampleIds::FileName); |
| 4857 | |
| 4858 | if (f == fileName) |
| 4859 | return true; |
| 4860 | } |
| 4861 | } |
| 4862 | |
| 4863 | return false; |
| 4864 | }; |
| 4865 | |
| 4866 | if (auto ar = fileNameList.getArray()) |
| 4867 | { |
| 4868 | StringArray list; |
| 4869 | |
| 4870 | for (auto& newSample : *ar) |
| 4871 | { |
| 4872 | PoolReference ref(s->getMainController(), newSample, FileHandlerBase::Samples); |
| 4873 | |
| 4874 | if (skipExistingSamples && sampleExists(ref)) |
| 4875 | continue; |
| 4876 | |
| 4877 | list.add(ref.getFile().getFullPathName()); |
| 4878 | } |
| 4879 | |
| 4880 | BigInteger rootNotes; |
| 4881 | // start at note number 0 |
| 4882 | rootNotes.setRange(0, jmin(127, list.size()), true); |
| 4883 | |
| 4884 | int startIndex = s->getNumSounds(); |
| 4885 |
nothing calls this directly
no test coverage detected