Nitpicky cruft cleanup.

This commit is contained in:
James Alan Nguyen 2022-04-15 11:57:57 +10:00
parent 2dc80e8d8e
commit c3ca175e46
1 changed files with 62 additions and 63 deletions

View File

@ -448,7 +448,8 @@ void DivEngine::loadS3I(SafeReader& reader, std::vector<DivInstrument*>& ret, St
// Skip more stuff we don't need
reader.seek(21, SEEK_CUR);
} else {
logE("S3I PCM samples currently not supported.");
lastError = "S3I PCM samples currently not supported.";
logE("S3I PCM samples currently not supported.\n");
}
ins->name = reader.readString(28);
ins->name = (ins->name.length() == 0) ? stripPath : ins->name;
@ -456,7 +457,8 @@ void DivEngine::loadS3I(SafeReader& reader, std::vector<DivInstrument*>& ret, St
int s3i_signature = reader.readI();
if (s3i_signature != 0x49524353) {
logW("S3I signature invalid.");
lastError = "S3I signature invalid.";
logW("S3I signature invalid.\n");
};
} catch (EndOfFileException& e) {
lastError = "premature end of file";
@ -622,6 +624,7 @@ void DivEngine::loadBNK(SafeReader& reader, std::vector<DivInstrument*>& ret, St
// First distinguish between GEMS BNK and Adlib BNK
uint64_t header = reader.readL();
bool is_adlib = ((header>>8) == 0x2d42494c444100L);
int readCount = 0;
if (is_adlib) {
// Caveat: Technically Adlib BNK can hold up to 0xFFFF instruments,
@ -644,40 +647,37 @@ void DivEngine::loadBNK(SafeReader& reader, std::vector<DivInstrument*>& ret, St
} bnkop_t;
typedef struct {
uint8_t mode, // version
percVoice; // perc
uint8_t mode,
percVoice;
bnkop_t op[2];
uint8_t wave0, // wave op1
wave1; // wave op2
uint8_t wave0,
wave1;
} bnktimbre_t;
int readCount = 0;
try {
// Seek to BNK patch names
reader.seek(0x0c, SEEK_SET);
uint32_t name_offset = reader.readI();
reader.seek(0x10, SEEK_SET);
uint32_t data_offset = reader.readI();
// Seek to BNK patch names
reader.seek(name_offset, SEEK_SET);
while (readCount < 256 && reader.tell() < data_offset) {
while (reader.tell() < data_offset) {
if (readCount >= 256) {
lastError = "BNK exceeds 256 presets. Only first 256 will be imported.";
logW("BNK exceeds 256 presets. Only first 256 will be imported.\n");
break;
}
reader.seek(3, SEEK_CUR);
instNames[readCount] = reader.readString(9);
++readCount;
}
if (readCount >= 256) {
logW("BNK exceeds 256 presets. Only first 256 will be imported.\n");
}
// Seek to BNK data
reader.seek(data_offset, SEEK_SET);
// Read until EOF
for (int i = 0; i < readCount && i < 256; ++i) {
try {
bnktimbre_t timbre;
insList[i] = new DivInstrument;
auto& ins = insList[i];
@ -720,14 +720,9 @@ void DivEngine::loadBNK(SafeReader& reader, std::vector<DivInstrument*>& ret, St
ins->fm.op[0].ws = reader.readC();
ins->fm.op[1].ws = reader.readC();
ins->name = instNames[i].length() > 0 ? instNames[i] : fmt::format("{0}[{1}]", stripPath, i);
}
reader.seek(0, SEEK_END);
ret.push_back(insList[i]);
} catch (EndOfFileException& e) {
// Reached end of BNK data
delete insList[i];
break;
}
}
} catch (EndOfFileException& e) {
lastError = "premature end of file";
logE("premature end of file!\n");
@ -742,6 +737,10 @@ void DivEngine::loadBNK(SafeReader& reader, std::vector<DivInstrument*>& ret, St
lastError = "GEMS BNK currently not supported.\n";
logE("GEMS BNK currently not supported.\n");
}
for (int i = 0; i < readCount; ++i) {
ret.push_back(insList[i]);
}
}