GYBv1/2 working

This commit is contained in:
James Alan Nguyen 2022-04-30 16:00:29 +10:00
parent df1cb0e7fa
commit f720e0af47

View file

@ -1081,8 +1081,10 @@ void DivEngine::loadGYB(SafeReader& reader, std::vector<DivInstrument*>& ret, St
ins->fm.alg = tmp & 0x3; ins->fm.alg = tmp & 0x3;
ins->fm.fb = ((tmp>>3) & 0x3); ins->fm.fb = ((tmp>>3) & 0x3);
if (!readRegB4) { // PAN if (!readRegB4) { // PAN / PMS / AMS
reader.readC(); // skip as not kept in Furnace instrument tmp = reader.readC();
ins->fm.fms = tmp & 0x7;
ins->fm.ams = ((tmp>>4) & 0x3);
} }
return ins; return ins;
}; };
@ -1098,6 +1100,10 @@ void DivEngine::loadGYB(SafeReader& reader, std::vector<DivInstrument*>& ret, St
insMelodyCount = reader.readC(); insMelodyCount = reader.readC();
insDrumCount = reader.readC(); insDrumCount = reader.readC();
if (insMelodyCount > 128 || insDrumCount > 128) {
throw std::invalid_argument(fmt::sprintf("GYBv1/2 patch count is out of bounds."));
}
if (!reader.seek(0x100, SEEK_CUR)) { // skip MIDI instrument mapping if (!reader.seek(0x100, SEEK_CUR)) { // skip MIDI instrument mapping
throw EndOfFileException(&reader, reader.tell() + 0x100); throw EndOfFileException(&reader, reader.tell() + 0x100);
} }
@ -1108,27 +1114,24 @@ void DivEngine::loadGYB(SafeReader& reader, std::vector<DivInstrument*>& ret, St
// Instrument data // Instrument data
for (int i = 0; i < (insMelodyCount+insDrumCount); ++i) { for (int i = 0; i < (insMelodyCount+insDrumCount); ++i) {
// Note: melody and drum patches are interleaved... // TODO determine if a patch is 'empty' -> ignore and move on
bool isDrum = (i >= insMelodyCount);
DivInstrument* newIns = readInstrument(reader, (version==2)); DivInstrument* newIns = readInstrument(reader, (version==2));
reader.readC(); // skip transpose reader.readC(); // skip transpose
if (version == 2) { if (version == 2) {
reader.readC(); // skip padding reader.readC(); // skip padding
} }
uint8_t nameLen = reader.readC();
String insName = (nameLen > 0) ? reader.readString(nameLen) : fmt::sprintf("%s [%d]", stripPath, readCount);
newIns->name = insName;
insList.push_back(newIns); insList.push_back(newIns);
++readCount; ++readCount;
} }
// Instrument name // Map to note assignment currently not supported.
for (int i = 0; i < (insMelodyCount+insDrumCount); ++i) {
uint8_t nameLen = reader.readC();
String insName = (nameLen > 0) ? reader.readString(nameLen) : fmt::sprintf("%s [%d]", stripPath, readCount);
// TODO determine if a patch is 'empty' -> ignore and move on
if (insList[i] == NULL) {
continue;
}
insList[i]->name = insName;
}
} else { // GYBv3+ } else { // GYBv3+
reader.readC(); // skip LFO speed (chip-global) reader.readC(); // skip LFO speed (chip-global)
uint32_t fileSize = reader.readI(); uint32_t fileSize = reader.readI();
@ -1175,6 +1178,12 @@ void DivEngine::loadGYB(SafeReader& reader, std::vector<DivInstrument*>& ret, St
delete insList[i]; delete insList[i];
} }
is_failed = true; is_failed = true;
} catch (std::invalid_argument& e) {
lastError = fmt::sprintf("Invalid value found in patch file. %s", e.what());
logE("Invalid value found in patch file.");
logE(e.what());
is_failed = true;
} }
if (!is_failed) { if (!is_failed) {