Update InstrumentDescription to receive the image name

This commit is contained in:
Jean Pierre Cimalando 2021-04-03 23:31:45 +02:00
parent 0bcfbc5495
commit bbac05281d
5 changed files with 26 additions and 1 deletions

View file

@ -98,6 +98,8 @@ std::string getDescriptionBlob(sfizz_synth_t* handle)
synth.sendMessage(*client, 0, "/num_masters", "", nullptr);
synth.sendMessage(*client, 0, "/num_curves", "", nullptr);
synth.sendMessage(*client, 0, "/num_samples", "", nullptr);
synth.sendMessage(*client, 0, "/root_path", "", nullptr);
synth.sendMessage(*client, 0, "/image", "", nullptr);
synth.sendMessage(*client, 0, "/key/slots", "", nullptr);
synth.sendMessage(*client, 0, "/sw/last/slots", "", nullptr);
synth.sendMessage(*client, 0, "/cc/slots", "", nullptr);
@ -140,6 +142,10 @@ InstrumentDescription parseDescriptionBlob(absl::string_view blob)
desc.numCurves = uint32_t(args[0].i);
else if (Messages::matchOSC("/num_samples", path, indices) && !strcmp(sig, "i"))
desc.numSamples = uint32_t(args[0].i);
else if (Messages::matchOSC("/root_path", path, indices) && !strcmp(sig, "s"))
desc.rootPath = args[0].s;
else if (Messages::matchOSC("/image", path, indices) && !strcmp(sig, "s"))
desc.image = args[0].s;
else if (Messages::matchOSC("/key/slots", path, indices) && !strcmp(sig, "b"))
copyArgToBitSpan(args[0], desc.keyUsed.span());
else if (Messages::matchOSC("/sw/last/slots", path, indices) && !strcmp(sig, "b"))
@ -172,6 +178,9 @@ std::ostream& operator<<(std::ostream& os, const InstrumentDescription& desc)
os << " curves: " << desc.numCurves << "\n";
os << " samples: " << desc.numSamples << "\n";
os << " root_path: " << desc.rootPath << "\n";
os << " image: " << desc.image << "\n";
os << " keys:\n";
for (unsigned i = 0; i < 128; ++i) {
if (desc.keyUsed.test(i)) {

View file

@ -22,6 +22,8 @@ struct InstrumentDescription {
uint32_t numMasters {};
uint32_t numCurves {};
uint32_t numSamples {};
std::string rootPath;
std::string image;
BitArray<128> keyUsed {};
BitArray<128> keyswitchUsed {};
BitArray<sfz::config::numCCs> ccUsed {};

View file

@ -246,6 +246,7 @@ void Synth::Impl::clear()
effectBuses_[0]->setSampleRate(sampleRate_);
effectBuses_[0]->clearInputs(samplesPerBlock_);
resources_.clear();
rootPath_.clear();
numGroups_ = 0;
numMasters_ = 0;
currentSwitch_ = absl::nullopt;
@ -547,7 +548,11 @@ bool Synth::loadSfzString(const fs::path& path, absl::string_view text)
void Synth::Impl::finalizeSfzLoad()
{
resources_.filePool.setRootDirectory(parser_.originalDirectory());
const fs::path& rootDirectory = parser_.originalDirectory();
resources_.filePool.setRootDirectory(rootDirectory);
// a string representation used for OSC purposes
rootPath_ = rootDirectory.u8string();
size_t currentRegionIndex = 0;
size_t currentRegionCount = layers_.size();

View file

@ -76,10 +76,16 @@ void sfz::Synth::dispatchMessage(Client& client, int delay, const char* path, co
//----------------------------------------------------------------------
MATCH("/root_path", "") {
client.receive<'s'>(delay, path, impl.rootPath_.c_str());
} break;
MATCH("/image", "") {
client.receive<'s'>(delay, path, impl.image_.c_str());
} break;
//----------------------------------------------------------------------
MATCH("/sw/last/slots", "") {
const BitArray<128>& switches = impl.swLastSlots_;
sfizz_blob_t blob { switches.data(), static_cast<uint32_t>(switches.byte_size()) };

View file

@ -278,6 +278,9 @@ struct Synth::Impl final: public Parser::Listener {
// Singletons passed as references to the voices
Resources resources_;
// Root path
std::string rootPath_;
// Control opcodes
std::string defaultPath_ { "" };
std::string image_ { "" };