Cannot open source file BinaryData.h

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));
            }
        }
    }
}

Answered, recently, here:

However, this aspect leaves me with a question:

I have enabled the BinaryData namespace and included it in the JuceHeader all in the Projucer.

Did you save and re-generate your project in the Projucer? This is where BinaryData.h/.cpp gets updated with the new contents. You don’t have to do anything manual (besides #include “BinaryData.h”) … but you should be sure to renerate after adding a resource in Projucer (and marking it as 'included in Binary Resources") …

It looks like the sample I had was deleted by trying out different things and I forgot to include it again, then the BinaryData is not recognised if there aren’t any binary resources within the folder. Thank you very much for the quick reply! I’m working on my dissertation right now so you’ll probably see me a lot around here :slight_smile: