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!
//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);
break;
}
}
jassert(data != nullptr); //File not found
}
const char* data = nullptr;
int size = 0;
};
I put RawData constructor definition in one of my JUCE modules cpp, which includes <JuceHeader.h>
The case is perfectly matched. I can confirmed it by printing via DBG the String object from XmlElement::getStringAttribute, and the const char* fileToFind inside RawData constructor.
DBGV (fileName);
DBGV (fileToFind);
if (fileName == fileToFind)
{
data = BinaryData::getNamedResource(binaryName, size);
break;
}
fileName and fileToFind printed identically in DBG console output. But fileName == fileToFind comparison always return false, hence it always return nullptr.
EDIT: I managed to solve the issue, by changing the condition using strcmp.
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 (strcmp (fileName, fileToFind) == 0)
{
data = getNamedResource (binaryName, size);
break;
}
}
jassert (data != nullptr); //File not found
}
const char* data = nullptr;
int size = 0;
};