Use string to load BinaryData files?

Is it possible to convert a string to a type that might be able to directly load BinaryData files?

I’ve built a binaural panner but, due to some assertion errors while reading in WAV files, decided binary is a better option.

It’s working now when hard-coded with a particular file (BinaryData::thisFile), but I’m looking for a way of converting the existing string file names “H-10e000a.wav” into something that can produce the same result (“H-10e000a.wav” → BinaryData::H-10e000a_wav).

Hoping I don’t have to completely rework the switch statements I currently have. Thanks for your help!

Switch statements usually don’t work with strings, only integral types.

However there is a method in BinaryData that allows to retrieve the filenames, so you can iterate through the available files.

for (int i = 0; i < BinaryData::namedResourceListSize; ++i)
    if (juce::String::fromUTF8 (BinaryData::namedResourceList [i])) == name)
        // ...

I use something like this:

//Represents a binary data object:
struct RawData
    explicit RawData(const char* fileToFind)
        using namespace BinaryData;

        for (int index = 0; index < namedResourceListSize; ++index)
            auto binaryName = namedResourceList[index];
            auto fileName = getNamedResourceOriginalFilename(binaryName);

            if (fileName == fileToFind)
                data = BinaryData::getNamedResource(binaryName, size);

        jassert(data != nullptr); //File not found

    const char* data = nullptr;
    int size = 0;

Then when you need something:

RawData binary ("File.wav");
doSomethingWithData(, binary.size);
1 Like

Thanks @Daniel and @eyalamir - I’ll look into those now!

I’ve been passing the file path, determined by GUI parameters, as a string previously. This makes a lot more sense.

All sorted - works really well now. Thanks again!