Hi there, sorry if this is a basic question but just starting with JUCE. I’m developing a synth and have included the different samples as BinaryData in Projucer. I have enabled the BinaryData namespace and included it in the JuceHeader all in the Projucer. I’m trying different ways to load all of my samples in a neat and clean way instead of individually one by one. My idea was to do something like the following however I can’t include BinaryData.h or nor is it recognised if I don’t include it. The error when using BinaryData is “name followed by :: must be a class or a namespace name” which supposedly should be a namespace as set in the projucer. This is my code if anyone can help me, thank you very much in advance.
SampleLoader::SampleLoader(juce::AudioFormatManager& fm) : formatManager(fm) {}
void SampleLoader::loadSamples(juce::Synthesiser& synthesiser)
{
for (int midiNote = 21; midiNote <= 108; ++midiNote)
{
juce::String fileName = "note" + juce::String(midiNote) + ".wav";
if (auto* data = BinaryData::getNamedResource(fileName.toRawUTF8(), fileName.length()))
{
auto size = BinaryData::getNamedResourceSize(fileName.toRawUTF8());
auto inputStream = std::make_unique<juce::MemoryInputStream>(data, size, false);
std::unique_ptr<juce::AudioFormatReader> formatReader(formatManager.createReaderFor(std::move(inputStream)));
if (formatReader != nullptr)
{
juce::BigInteger allNotes;
allNotes.setBit(midiNote);
synthesiser.addSound(new juce::SamplerSound("Sample",
*formatReader,
allNotes,
midiNote,
0.1,
0.1,
10.0));
}
}
}
}
