diff options
Diffstat (limited to 'utils/gen_adldata/file_formats')
-rw-r--r-- | utils/gen_adldata/file_formats/common.h | 27 | ||||
-rw-r--r-- | utils/gen_adldata/file_formats/load_ail.h | 137 | ||||
-rw-r--r-- | utils/gen_adldata/file_formats/load_bisqwit.h | 30 | ||||
-rw-r--r-- | utils/gen_adldata/file_formats/load_bnk.h | 17 | ||||
-rw-r--r-- | utils/gen_adldata/file_formats/load_bnk2.h | 42 | ||||
-rw-r--r-- | utils/gen_adldata/file_formats/load_ea.h | 29 | ||||
-rw-r--r-- | utils/gen_adldata/file_formats/load_ibk.h | 24 | ||||
-rw-r--r-- | utils/gen_adldata/file_formats/load_jv.h | 23 | ||||
-rw-r--r-- | utils/gen_adldata/file_formats/load_op2.h | 26 | ||||
-rw-r--r-- | utils/gen_adldata/file_formats/load_tmb.h | 24 | ||||
-rw-r--r-- | utils/gen_adldata/file_formats/load_wopl.h | 71 |
11 files changed, 393 insertions, 57 deletions
diff --git a/utils/gen_adldata/file_formats/common.h b/utils/gen_adldata/file_formats/common.h index d06059e..a03ca5d 100644 --- a/utils/gen_adldata/file_formats/common.h +++ b/utils/gen_adldata/file_formats/common.h @@ -18,6 +18,14 @@ inline int16_t toSint16BE(const uint8_t *arr) return num; } +inline int16_t toSint16LE(const uint8_t *arr) +{ + int16_t num = *reinterpret_cast<const int8_t *>(&arr[1]); + num *= 1 << 8; + num |= static_cast<int16_t>(arr[0]) & 0x00FF; + return num; +} + inline uint16_t toUint16LE(const uint8_t *arr) { uint16_t num = arr[0]; @@ -25,4 +33,23 @@ inline uint16_t toUint16LE(const uint8_t *arr) return num; } +inline uint32_t toUint32LE(const uint8_t *arr) +{ + uint32_t num = arr[0]; + num |= (static_cast<uint32_t>(arr[1] << 8) & 0x0000FF00); + num |= (static_cast<uint32_t>(arr[2] << 16) & 0x00FF0000); + num |= (static_cast<uint32_t>(arr[3] << 24) & 0xFF000000); + return num; +} + +inline int32_t toSint32LE(const uint8_t *arr) +{ + int32_t num = *reinterpret_cast<const int8_t *>(&arr[3]); + num *= 1 << 24; + num |= (static_cast<int32_t>(arr[2]) << 16) & 0x00FF0000; + num |= (static_cast<int32_t>(arr[1]) << 8) & 0x0000FF00; + num |= static_cast<int32_t>(arr[0]) & 0x000000FF; + return num; +} + #endif // COMMON_H diff --git a/utils/gen_adldata/file_formats/load_ail.h b/utils/gen_adldata/file_formats/load_ail.h index 80ca8ad..a12789b 100644 --- a/utils/gen_adldata/file_formats/load_ail.h +++ b/utils/gen_adldata/file_formats/load_ail.h @@ -3,8 +3,17 @@ #include "../progs_cache.h" #include "../midi_inst_list.h" +#include "common.h" -static bool LoadMiles(const char *fn, unsigned bank, const char *prefix) +struct GTL_Head // GTL file header entry structure +{ + uint8_t patch = 0; + uint8_t bank = 0; + uint32_t offset = 0; +}; + +bool BankFormats::LoadMiles(BanksDump &db, const char *fn, unsigned bank, + const std::string &bankTitle, const char *prefix) { #ifdef HARD_BANKS writeIni("AIL", fn, prefix, bank, INI_Both); @@ -13,7 +22,7 @@ static bool LoadMiles(const char *fn, unsigned bank, const char *prefix) if(!fp) return false; std::fseek(fp, 0, SEEK_END); - std::vector<unsigned char> data(size_t(std::ftell(fp))); + std::vector<uint8_t> data(size_t(std::ftell(fp))); std::rewind(fp); if(std::fread(&data[0], 1, data.size(), fp) != data.size()) { @@ -22,33 +31,74 @@ static bool LoadMiles(const char *fn, unsigned bank, const char *prefix) } std::fclose(fp); - for(unsigned a = 0; a < 2000; ++a) + GTL_Head head; + std::vector<GTL_Head> heads; + uint_fast8_t max_bank_number = 0; + heads.reserve(256); + uint8_t *data_pos = data.data(); + uint8_t *data_end = data.data() + data.size(); + do { - unsigned gm_patch = data[a * 6 + 0]; - unsigned gm_bank = data[a * 6 + 1]; - unsigned offset = *(unsigned *)&data[a * 6 + 2]; + if((data_end - data_pos) < 6) + return false; - if(gm_patch == 0xFF) + head.patch = data_pos[0]; + head.bank = data_pos[1]; + head.offset = toUint32LE(data_pos + 2); + + if((head.patch == 0xFF) || (head.bank == 0xFF)) break; - int gmno = gm_bank == 0x7F ? int(gm_patch + 0x80) : int(gm_patch); + if(head.patch > 127)//Patch ID is more than 127 + return false; + + if((head.bank != 0x7F) && (head.bank > max_bank_number) ) + max_bank_number = head.bank; + + heads.push_back(head); + data_pos += 6; + } + while(data_pos < data_end); + + size_t bankDb = db.initBank(bank, bankTitle, BanksDump::BankEntry::SETUP_AIL); + + std::vector<BanksDump::MidiBank> bnkMelodic; + bnkMelodic.resize(max_bank_number + 1, BanksDump::MidiBank()); + BanksDump::MidiBank bnkPercussion; + + { + uint8_t bank_lsb_counter = 0; + uint8_t bank_msb_counter = 0; + for(BanksDump::MidiBank &b : bnkMelodic) + { + b.lsb = bank_lsb_counter++; + b.msb = bank_msb_counter; + if(bank_lsb_counter == 0) + bank_msb_counter++; + } + } + + uint32_t totalInsts = static_cast<uint32_t>(heads.size()); + for(uint32_t i = 0; i < totalInsts; i++) + { + GTL_Head &h = heads[i]; + bool isPerc = (h.bank == 0x7F); + // int gmPatchId = isPerc ? h.patch : (h.patch + (h.bank * 128)); + unsigned offset = h.offset; + + BanksDump::MidiBank &bnk = isPerc ? bnkPercussion : bnkMelodic[h.bank]; + + int gmno = isPerc ? int(h.patch + 0x80) : int(h.patch); int midi_index = gmno < 128 ? gmno : gmno < 128 + 35 ? -1 : gmno < 128 + 88 ? gmno - 35 : -1; + unsigned length = data[offset] + data[offset + 1] * 256; signed char notenum = ((signed char)data[offset + 2]); - /*printf("%02X %02X %08X ", gmnumber,gmnumber2, offset); - for(unsigned b=0; b<length; ++b) - { - if(b > 3 && (b-3)%11 == 0) printf("\n "); - printf("%02X ", data[offset+b]); - } - printf("\n");*/ - - if(gm_bank != 0 && gm_bank != 0x7F) - continue; + BanksDump::InstrumentEntry inst; + BanksDump::Operator ops[5]; char name2[512]; sprintf(name2, "%s%c%u", prefix, @@ -61,27 +111,40 @@ static bool LoadMiles(const char *fn, unsigned bank, const char *prefix) for(unsigned i = 0; i < inscount; ++i) { + if(i >= 2) + break; unsigned o = offset + 3 + i * 11; tmp[i].finetune = (gmno < 128 && i == 0) ? notenum : 0; tmp[i].diff = (i == 1); - tmp[i].data[0] = data[o + 0]; // 20 - tmp[i].data[8] = data[o + 1]; // 40 (vol) - tmp[i].data[2] = data[o + 2]; // 60 - tmp[i].data[4] = data[o + 3]; // 80 - tmp[i].data[6] = data[o + 4]; // E0 - tmp[i].data[1] = data[o + 6]; // 23 - tmp[i].data[9] = data[o + 7]; // 43 (vol) - tmp[i].data[3] = data[o + 8]; // 63 - tmp[i].data[5] = data[o + 9]; // 83 - tmp[i].data[7] = data[o + 10]; // E3 + + uint8_t temp[11] = {0}; + if(o < data.size()) + { + size_t count = data.size() - o; + count = (count > sizeof(temp)) ? sizeof(temp) : count; + std::memcpy(temp, &data[o], count); + } + + tmp[i].data[0] = temp[0]; // 20 + tmp[i].data[8] = temp[1]; // 40 (vol) + tmp[i].data[2] = temp[2]; // 60 + tmp[i].data[4] = temp[3]; // 80 + tmp[i].data[6] = temp[4]; // E0 + tmp[i].data[1] = temp[6]; // 23 + tmp[i].data[9] = temp[7]; // 43 (vol) + tmp[i].data[3] = temp[8]; // 63 + tmp[i].data[5] = temp[9]; // 83 + tmp[i].data[7] = temp[10]; // E3 unsigned fb_c = data[offset + 3 + 5]; tmp[i].data[10] = uint8_t(fb_c); if(i == 1) { + inst.instFlags |= BanksDump::InstrumentEntry::WOPL_Ins_4op; tmp[0].data[10] = fb_c & 0x0F; tmp[1].data[10] = uint8_t((fb_c & 0x0E) | (fb_c >> 7)); } + db.toOps(tmp[i], ops, i * 2); } if(inscount <= 2) @@ -95,8 +158,18 @@ static bool LoadMiles(const char *fn, unsigned bank, const char *prefix) tmp2.rhythmModeDrum = 0; std::string name; if(midi_index >= 0) name = std::string(1, '\377') + MidiInsName[midi_index]; - size_t resno = InsertIns(tmp[0], tmp[1], tmp2, name, name2, twoOp); - SetBank(bank, (unsigned int)gmno, resno); + if(h.bank == 0 || h.bank == 0x7F) + { + size_t resno = InsertIns(tmp[0], tmp[1], tmp2, name, name2, twoOp); + SetBank(bank, (unsigned int)gmno, resno); + } + //--------------------------------------------------------------- + inst.percussionKeyNumber = isPerc ? static_cast<uint_fast8_t>(notenum) : 0; + inst.noteOffset1 = isPerc ? 0 : notenum; + unsigned fb_c = data[offset + 3 + 5]; + inst.fbConn = (static_cast<uint_fast16_t>(fb_c & 0x0F)) | + (static_cast<uint_fast16_t>((fb_c & 0x0E) | (fb_c >> 7)) << 8); + db.addInstrument(bnk, h.patch, inst, ops, fn); } } @@ -107,6 +180,10 @@ static bool LoadMiles(const char *fn, unsigned bank, const char *prefix) setup.scaleModulators = false; SetBankSetup(bank, setup); + for(auto &b : bnkMelodic) + db.addMidiBank(bankDb, false, b); + db.addMidiBank(bankDb, true, bnkPercussion); + return true; } diff --git a/utils/gen_adldata/file_formats/load_bisqwit.h b/utils/gen_adldata/file_formats/load_bisqwit.h index 9749a76..7ea3a38 100644 --- a/utils/gen_adldata/file_formats/load_bisqwit.h +++ b/utils/gen_adldata/file_formats/load_bisqwit.h @@ -4,7 +4,7 @@ #include "../progs_cache.h" #include "../midi_inst_list.h" -static bool LoadBisqwit(const char *fn, unsigned bank, const char *prefix) +bool BankFormats::LoadBisqwit(BanksDump &db, const char *fn, unsigned bank, const std::string &bankTitle, const char *prefix) { #ifdef HARD_BANKS writeIni("Bisqwit", fn, prefix, bank, INI_Both); @@ -13,14 +13,25 @@ static bool LoadBisqwit(const char *fn, unsigned bank, const char *prefix) if(!fp) return false; - for(uint32_t a = 0; a < 256; ++a) + size_t bankDb = db.initBank(bank, bankTitle, BanksDump::BankEntry::SETUP_Generic); + BanksDump::MidiBank bnkMelodique; + BanksDump::MidiBank bnkPercussion; + + for(uint32_t a = 0, patchId = 0; a < 256; ++a, patchId++) { //unsigned offset = a * 25; uint32_t gmno = a; + bool isPercussion = gmno >= 128; int32_t midi_index = gmno < 128 ? int32_t(gmno) : gmno < 128 + 35 ? -1 : gmno < 128 + 88 ? int32_t(gmno - 35) : -1; + if(patchId == 128) + patchId = 0; + + BanksDump::MidiBank &bnk = isPercussion ? bnkPercussion : bnkMelodique; + BanksDump::InstrumentEntry inst; + BanksDump::Operator ops[5]; struct ins tmp2; tmp2.notenum = (uint8_t)std::fgetc(fp); @@ -49,9 +60,24 @@ static bool LoadBisqwit(const char *fn, unsigned bank, const char *prefix) tmp2.real4op = tmp[1].diff; size_t resno = InsertIns(tmp[0], tmp[1], tmp2, name, name2, (tmp[0] == tmp[1])); SetBank(bank, gmno, resno); + + db.toOps(tmp[0], ops, 0); + if(tmp[0] != tmp[1]) + { + inst.instFlags |= BanksDump::InstrumentEntry::WOPL_Ins_4op; + db.toOps(tmp[1], ops, 2); + } + + inst.fbConn = uint_fast16_t(tmp[0].data[10]) | (uint_fast16_t(tmp[1].data[10]) << 8); + inst.percussionKeyNumber = a >= 128 ? tmp2.notenum : 0; + inst.noteOffset1 = a < 128 ? tmp2.notenum : 0; + db.addInstrument(bnk, patchId, inst, ops, fn); } std::fclose(fp); + db.addMidiBank(bankDb, false, bnkMelodique); + db.addMidiBank(bankDb, true, bnkPercussion); + AdlBankSetup setup; setup.volumeModel = VOLUME_Generic; setup.deepTremolo = true; diff --git a/utils/gen_adldata/file_formats/load_bnk.h b/utils/gen_adldata/file_formats/load_bnk.h index f1412ba..9379de5 100644 --- a/utils/gen_adldata/file_formats/load_bnk.h +++ b/utils/gen_adldata/file_formats/load_bnk.h @@ -7,7 +7,9 @@ #include <cstdint> #include <string> -static bool LoadBNK(const char *fn, unsigned bank, const char *prefix, bool is_fat, bool percussive) +bool BankFormats::LoadBNK(BanksDump &db, const char *fn, unsigned bank, + const std::string &bankTitle, const char *prefix, + bool is_fat, bool percussive) { #ifdef HARD_BANKS writeIni("HMI", fn, prefix, bank, percussive ? INI_Drums : INI_Melodic); @@ -25,6 +27,9 @@ static bool LoadBNK(const char *fn, unsigned bank, const char *prefix, bool is_f } std::fclose(fp); + size_t bankDb = db.initBank(bank, bankTitle, BanksDump::BankEntry::SETUP_Generic); + BanksDump::MidiBank bnk; + /*printf("%s:\n", fn);*/ //unsigned short version = *(short*)&data[0]; // major,minor (2 bytes) // "ADLIB-" (6 bytes) @@ -80,6 +85,9 @@ static bool LoadBNK(const char *fn, unsigned bank, const char *prefix, bool is_f else sprintf(name2, "%s%u", prefix, n); + BanksDump::InstrumentEntry inst; + BanksDump::Operator ops[5]; + insdata tmp; tmp.data[0] = uint8_t( (op1[ 9] << 7) // TREMOLO FLAG @@ -115,11 +123,16 @@ static bool LoadBNK(const char *fn, unsigned bank, const char *prefix, bool is_f if(is_fat) tmp.data[10] ^= 1; + db.toOps(tmp, ops, 0); + inst.percussionKeyNumber = is_fat ? voice_num : (percussive ? usage_flag : 0); + inst.setFbConn(op1[2] * 2 + op1[12]); + size_t resno = InsertIns(tmp, tmp2, std::string(1, '\377') + name, name2); if(!is_fat) { SetBank(bank, (unsigned int)gmno, resno); + db.addInstrument(bnk, n & 127, inst, ops, fn); } else { @@ -151,6 +164,8 @@ static bool LoadBNK(const char *fn, unsigned bank, const char *prefix, bool is_f */ } + db.addMidiBank(bankDb, percussive, bnk); + AdlBankSetup setup; setup.volumeModel = VOLUME_Generic; setup.deepTremolo = false; diff --git a/utils/gen_adldata/file_formats/load_bnk2.h b/utils/gen_adldata/file_formats/load_bnk2.h index 072712c..5468cb5 100644 --- a/utils/gen_adldata/file_formats/load_bnk2.h +++ b/utils/gen_adldata/file_formats/load_bnk2.h @@ -8,9 +8,10 @@ inline int stdstoi(const std::string& str) return std::atoi(str.c_str()); } -static bool LoadBNK2(const char *fn, unsigned bank, const char *prefix, - const std::string &melo_filter, - const std::string &perc_filter) +bool BankFormats::LoadBNK2(BanksDump &db, const char *fn, unsigned bank, + const std::string &bankTitle, const char *prefix, + const std::string &melo_filter, + const std::string &perc_filter) { #ifdef HARD_BANKS writeIni("AdLibGold", fn, prefix, bank, INI_Both, melo_filter.c_str(), perc_filter.c_str()); @@ -28,6 +29,10 @@ static bool LoadBNK2(const char *fn, unsigned bank, const char *prefix, } std::fclose(fp); + size_t bankDb = db.initBank(bank, bankTitle, BanksDump::BankEntry::SETUP_Generic); + BanksDump::MidiBank bnkMelodic; + BanksDump::MidiBank bnkPercussion; + unsigned short ins_entries = *(unsigned short *)&data[28 + 2 + 10]; unsigned char *records = &data[48]; @@ -47,13 +52,24 @@ static bool LoadBNK2(const char *fn, unsigned bank, const char *prefix, } int gmno = 0; + int patchId = 0; + bool isPercussion = false; if(name.substr(0, melo_filter.size()) == melo_filter) - gmno = stdstoi(name.substr(melo_filter.size())); + { + gmno = patchId = stdstoi(name.substr(melo_filter.size())); + isPercussion = false; + } else if(name.substr(0, perc_filter.size()) == perc_filter) - gmno = stdstoi(name.substr(perc_filter.size())) + 128; + { + patchId = stdstoi(name.substr(perc_filter.size())); + gmno = patchId + 128; + isPercussion = true; + } else continue; + BanksDump::MidiBank &bnk = isPercussion ? bnkPercussion : bnkMelodic; + const unsigned char *insdata = &data[size_t(offset2)]; const unsigned char *ops[4] = { insdata + 0, insdata + 6, insdata + 12, insdata + 18 }; unsigned char C4xxxFFFC = insdata[24]; @@ -64,6 +80,9 @@ static bool LoadBNK2(const char *fn, unsigned bank, const char *prefix, char name2[512]; sprintf(name2, "%s%c%u", prefix, (gmno & 128) ? 'P' : 'M', gmno & 127); + BanksDump::InstrumentEntry inst; + BanksDump::Operator opsD[5]; + struct insdata tmp[2]; for(unsigned a = 0; a < 2; ++a) { @@ -79,6 +98,7 @@ static bool LoadBNK2(const char *fn, unsigned bank, const char *prefix, tmp[a].data[9] = ops[a * 2 + 1][1]; tmp[a].finetune = (int8_t)TTTTTTTT; tmp[a].diff = false; + db.toOps(tmp[a], opsD, a * 2); } tmp[0].data[10] = C4xxxFFFC & 0x0F; tmp[1].data[10] = (tmp[0].data[10] & 0x0E) | (C4xxxFFFC >> 7); @@ -91,6 +111,10 @@ static bool LoadBNK2(const char *fn, unsigned bank, const char *prefix, tmp2.midi_velocity_offset = 0; tmp2.rhythmModeDrum = 0; + inst.setFbConn(C4xxxFFFC & 0x0F, (tmp[0].data[10] & 0x0E) | (C4xxxFFFC >> 7)); + inst.noteOffset1 = (int8_t)TTTTTTTT; + inst.percussionKeyNumber = (gmno & 128) ? 35 : 0; + if(xxP24NNN & 8) { // dual-op @@ -98,15 +122,23 @@ static bool LoadBNK2(const char *fn, unsigned bank, const char *prefix, tmp[1].diff = true; size_t resno = InsertIns(tmp[0], tmp[1], tmp2, std::string(1, '\377') + name, name2); SetBank(bank, (unsigned int)gmno, resno); + + inst.instFlags |= BanksDump::InstrumentEntry::WOPL_Ins_4op; + db.addInstrument(bnk, patchId, inst, opsD, fn); } else { // single-op size_t resno = InsertIns(tmp[0], tmp2, std::string(1, '\377') + name, name2); SetBank(bank, (unsigned int)gmno, resno); + + db.addInstrument(bnk, patchId, inst, opsD, fn); } } + db.addMidiBank(bankDb, false, bnkMelodic); + db.addMidiBank(bankDb, true, bnkPercussion); + AdlBankSetup setup; setup.volumeModel = VOLUME_Generic; setup.deepTremolo = false; diff --git a/utils/gen_adldata/file_formats/load_ea.h b/utils/gen_adldata/file_formats/load_ea.h index c217c09..4b40b0f 100644 --- a/utils/gen_adldata/file_formats/load_ea.h +++ b/utils/gen_adldata/file_formats/load_ea.h @@ -4,12 +4,17 @@ #include "../progs_cache.h" #include "../midi_inst_list.h" -static bool LoadEA(const char *fn, unsigned bank, const char *prefix) +bool BankFormats::LoadEA(BanksDump &db, const char *fn, unsigned bank, + const std::string &bankTitle, const char *prefix) { FILE *fp = std::fopen(fn, "rb"); if(!fp) return false; + size_t bankDb = db.initBank(bank, bankTitle, BanksDump::BankEntry::SETUP_CMF); + BanksDump::MidiBank bnkMelodic = db.midiBanks[db.banks[0].melodic[0]]; + BanksDump::MidiBank bnkPercussion = db.midiBanks[db.banks[0].percussion[0]]; + // Copy all instruments from bank 0 for(unsigned gmno = 0; gmno < 128; ++gmno) progs[bank][gmno] = progs[0][gmno]; @@ -61,6 +66,9 @@ static bool LoadEA(const char *fn, unsigned bank, const char *prefix) return false; } + BanksDump::InstrumentEntry inst; + BanksDump::Operator ops[5]; + insdata tmp; tmp.data[0] = bytes[0]; // reg 0x20: modulator AM/VIG/EG/KSR tmp.data[8] = bytes[1]; // reg 0x40: modulator ksl/attenuation @@ -82,12 +90,16 @@ static bool LoadEA(const char *fn, unsigned bank, const char *prefix) tmp.data[6] = 0; // reg 0xE0: modulator, never seems to be set tmp.data[7] = 0; // reg 0xE0: carrier, never seems to be set - ins tmp2{}; + ins tmp2; tmp2.notenum = 0; tmp2.pseudo4op = false; tmp2.real4op = false; tmp2.rhythmModeDrum = 0; + db.toOps(tmp, ops, 0); + inst.setFbConn(bytes[8]); + inst.noteOffset1 = int8_t(bytes[9] + 12); + std::string name; char name2[512]; if(gmno < 20) @@ -101,28 +113,38 @@ static bool LoadEA(const char *fn, unsigned bank, const char *prefix) size_t resno = InsertIns(tmp, tmp2, std::string(1, '\377') + name, name2); SetBank(bank, gmno, resno); + db.addInstrument(bnkMelodic, gmno, inst, ops, fn); + if(gmno == 10) { /*tmp.finetune=0;*/ tmp2.notenum = 0x49; SetBank(bank, 0x80 + 0x36, InsertIns(tmp, tmp2, std::string(1, '\377') + MidiInsName[0x80 + 0x36 - 35], std::string(1, '\377') + prefix + "P54")); + inst.percussionKeyNumber = 0x49; + db.addInstrument(bnkPercussion, 0x36, inst, ops, fn); } if(gmno == 18) { /*tmp.finetune=0;*/ tmp2.notenum = 0x17; SetBank(bank, 0x80 + 0x2A, InsertIns(tmp, tmp2, std::string(1, '\377') + MidiInsName[0x80 + 0x2A - 35], std::string(1, '\377') + prefix + "P42")); + inst.percussionKeyNumber = 0x17; + db.addInstrument(bnkPercussion, 0x2A, inst, ops, fn); } if(gmno == 16) { /*tmp.finetune=0;*/ tmp2.notenum = 0x0C; SetBank(bank, 0x80 + 0x24, InsertIns(tmp, tmp2, std::string(1, '\377') + MidiInsName[0x80 + 0x24 - 35], std::string(1, '\377') + prefix + "P36")); + inst.percussionKeyNumber = 0x0C; + db.addInstrument(bnkPercussion, 0x24, inst, ops, fn); } if(gmno == 17) { /*tmp.finetune=0;*/ tmp2.notenum = 0x01; SetBank(bank, 0x80 + 0x26, InsertIns(tmp, tmp2, std::string(1, '\377') + MidiInsName[0x80 + 0x26 - 35], std::string(1, '\377') + prefix + "P38")); + inst.percussionKeyNumber = 0x01; + db.addInstrument(bnkPercussion, 0x26, inst, ops, fn); } } @@ -135,6 +157,9 @@ static bool LoadEA(const char *fn, unsigned bank, const char *prefix) setup.scaleModulators = false; SetBankSetup(bank, setup); + db.addMidiBank(bankDb, false, bnkMelodic); + db.addMidiBank(bankDb, true, bnkPercussion); + return true; } diff --git a/utils/gen_adldata/file_formats/load_ibk.h b/utils/gen_adldata/file_formats/load_ibk.h index 28177c7..d4b54f6 100644 --- a/utils/gen_adldata/file_formats/load_ibk.h +++ b/utils/gen_adldata/file_formats/load_ibk.h @@ -3,7 +3,9 @@ #include "../progs_cache.h" -static bool LoadIBK(const char *fn, unsigned bank, const char *prefix, bool percussive, bool noRhythmMode = false) +bool BankFormats::LoadIBK(BanksDump &db, const char *fn, unsigned bank, + const std::string &bankTitle, const char *prefix, + bool percussive, bool noRhythmMode) { #ifdef HARD_BANKS writeIni("IBK", fn, prefix, bank, percussive ? INI_Drums : INI_Melodic); @@ -21,6 +23,9 @@ static bool LoadIBK(const char *fn, unsigned bank, const char *prefix, bool perc } std::fclose(fp); + size_t bankDb = db.initBank(bank, bankTitle, BanksDump::BankEntry::SETUP_Generic); + BanksDump::MidiBank bnk; + unsigned offs1_base = 0x804, offs1_len = 9; unsigned offs2_base = 0x004, offs2_len = 16; @@ -43,6 +48,9 @@ static bool LoadIBK(const char *fn, unsigned bank, const char *prefix, bool perc sprintf(name2, "%s%c%u", prefix, (gmno < 128 ? 'M' : 'P'), gmno & 127); + BanksDump::InstrumentEntry inst; + BanksDump::Operator ops[5]; + insdata tmp; tmp.data[0] = data[offset2 + 0]; tmp.data[1] = data[offset2 + 1]; @@ -66,6 +74,11 @@ static bool LoadIBK(const char *fn, unsigned bank, const char *prefix, bool perc tmp2.voice2_fine_tune = 0.0; tmp2.midi_velocity_offset = 0; + db.toOps(tmp, ops, 0); + inst.noteOffset1 = percussive ? 0 : data[offset2 + 12]; + inst.percussionKeyNumber = percussive ? data[offset2 + 13] : 0; + inst.setFbConn(data[offset2 + 10]); + tmp2.rhythmModeDrum = 0; if(percussive && !noRhythmMode) { @@ -74,18 +87,23 @@ static bool LoadIBK(const char *fn, unsigned bank, const char *prefix, bool perc { case 6: tmp2.rhythmModeDrum = ins::Flag_RM_BassDrum; + inst.instFlags |= BanksDump::InstrumentEntry::WOPL_RM_BassDrum; break; case 7: tmp2.rhythmModeDrum = ins::Flag_RM_Snare; + inst.instFlags |= BanksDump::InstrumentEntry::WOPL_RM_Snare; break; case 8: tmp2.rhythmModeDrum = ins::Flag_RM_TomTom; + inst.instFlags |= BanksDump::InstrumentEntry::WOPL_RM_TomTom; break; case 9: tmp2.rhythmModeDrum = ins::Flag_RM_Cymbal; + inst.instFlags |= BanksDump::InstrumentEntry::WOPL_RM_Cymbal; break; case 10: tmp2.rhythmModeDrum = ins::Flag_RM_HiHat; + inst.instFlags |= BanksDump::InstrumentEntry::WOPL_RM_HiHat; break; default: // IBK logic: make non-percussion instrument be silent @@ -96,8 +114,12 @@ static bool LoadIBK(const char *fn, unsigned bank, const char *prefix, bool perc size_t resno = InsertIns(tmp, tmp2, std::string(1, '\377') + name, name2); SetBank(bank, (unsigned int)gmno, resno); + + db.addInstrument(bnk, a, inst, ops, fn); } + db.addMidiBank(bankDb, percussive, bnk); + AdlBankSetup setup; setup.volumeModel = VOLUME_Generic; setup.deepTremolo = false; diff --git a/utils/gen_adldata/file_formats/load_jv.h b/utils/gen_adldata/file_formats/load_jv.h index a498bb6..bb4fbdb 100644 --- a/utils/gen_adldata/file_formats/load_jv.h +++ b/utils/gen_adldata/file_formats/load_jv.h @@ -4,7 +4,7 @@ #include "../progs_cache.h" #include "../midi_inst_list.h" -static bool LoadJunglevision(const char *fn, unsigned bank, const char *prefix) +bool BankFormats::LoadJunglevision(BanksDump &db, const char *fn, unsigned bank, const std::string &bankTitle, const char *prefix) { #ifdef HARD_BANKS writeIni("Junglevision", fn, prefix, bank, INI_Both); @@ -22,6 +22,10 @@ static bool LoadJunglevision(const char *fn, unsigned bank, const char *prefix) } std::fclose(fp); + size_t bankDb = db.initBank(bank, bankTitle, BanksDump::BankEntry::SETUP_Win9X); + BanksDump::MidiBank bnkMelodique; + BanksDump::MidiBank bnkPercussion; + uint16_t ins_count = uint16_t(data[0x20] + (data[0x21] << 8)); uint16_t drum_count = uint16_t(data[0x22] + (data[0x23] << 8)); uint16_t first_ins = uint16_t(data[0x24] + (data[0x25] << 8)); @@ -38,6 +42,12 @@ static bool LoadJunglevision(const char *fn, unsigned bank, const char *prefix) : gmno < 128 + 88 ? int(gmno - 35) : -1; + bool isPercussion = a >= ins_count; + size_t patchId = (a < ins_count) ? (a + first_ins) : ((a - ins_count) + first_drum); + BanksDump::MidiBank &bnk = isPercussion ? bnkPercussion : bnkMelodique; + BanksDump::InstrumentEntry inst; + BanksDump::Operator ops[5]; + insdata tmp[2]; tmp[0].data[0] = data[offset + 2]; @@ -83,6 +93,13 @@ static bool LoadJunglevision(const char *fn, unsigned bank, const char *prefix) tmp[1].finetune -= 12; } + if(data[offset] != 0) + inst.instFlags |= BanksDump::InstrumentEntry::WOPL_Ins_4op; + inst.percussionKeyNumber = data[offset + 1]; + inst.setFbConn(data[offset + 7], data[offset + 7 + 11]); + db.toOps(tmp[0], ops, 0); + db.toOps(tmp[1], ops, 2); + std::string name; if(midi_index >= 0) name = std::string(1, '\377') + MidiInsName[midi_index]; @@ -100,8 +117,12 @@ static bool LoadJunglevision(const char *fn, unsigned bank, const char *prefix) size_t resno = InsertIns(tmp[0], tmp[1], tmp2, name, name2); SetBank(bank, gmno, resno); } + db.addInstrument(bnk, patchId, inst, ops, fn); } + db.addMidiBank(bankDb, false, bnkMelodique); + db.addMidiBank(bankDb, true, bnkPercussion); + AdlBankSetup setup; setup.volumeModel = VOLUME_9X; setup.deepTremolo = true; diff --git a/utils/gen_adldata/file_formats/load_op2.h b/utils/gen_adldata/file_formats/load_op2.h index feb85ed..e31a803 100644 --- a/utils/gen_adldata/file_formats/load_op2.h +++ b/utils/gen_adldata/file_formats/load_op2.h @@ -49,7 +49,7 @@ struct Doom_opl_instr #endif -static bool LoadDoom(const char *fn, unsigned bank, const char *prefix) +bool BankFormats::LoadDoom(BanksDump &db, const char *fn, unsigned bank, const std::string &bankTitle, const char *prefix) { #ifdef HARD_BANKS writeIni("OP2", fn, prefix, bank, INI_Both); @@ -68,11 +68,17 @@ static bool LoadDoom(const char *fn, unsigned bank, const char *prefix) } std::fclose(fp); + size_t bankDb = db.initBank(bank, bankTitle, BanksDump::BankEntry::SETUP_DMX); + BanksDump::MidiBank bnkMelodique; + BanksDump::MidiBank bnkPercussion; + for(unsigned a = 0; a < 175; ++a) { const size_t offset1 = 0x18A4 + a * 32; const size_t offset2 = 8 + a * 36; - + BanksDump::MidiBank &bnk = a < 128 ? bnkMelodique : bnkPercussion; + BanksDump::InstrumentEntry inst; + BanksDump::Operator ops[5]; std::string name; for(unsigned p = 0; p < 32; ++p) if(data[offset1] != '\0') @@ -80,6 +86,7 @@ static bool LoadDoom(const char *fn, unsigned bank, const char *prefix) //printf("%3d %3d %3d %8s: ", a,b,c, name.c_str()); int gmno = int(a < 128 ? a : ((a | 128) + 35)); + size_t patchId = a < 128 ? a : ((a - 128) + 35); char name2[512]; snprintf(name2, 512, "%s%c%u", prefix, (gmno < 128 ? 'M' : 'P'), gmno & 127); @@ -104,6 +111,8 @@ static bool LoadDoom(const char *fn, unsigned bank, const char *prefix) tmp[index].data[9] = src.scale_2 | src.level_2; tmp[index].data[10] = src.feedback; tmp[index].finetune = int8_t(src.basenote + 12); + inst.fbConn |= (uint_fast16_t(src.feedback) << (a == 1 ? 8 : 0)); + db.toOps(tmp[index], ops, index * 2); } struct ins tmp2; tmp2.notenum = ins.note; @@ -120,6 +129,14 @@ static bool LoadDoom(const char *fn, unsigned bank, const char *prefix) tmp[1].finetune -= 12; } + inst.noteOffset1 = int8_t(tmp[0].finetune); + inst.noteOffset2 = int8_t(tmp[1].finetune); + + if((ins.flags & FL_DOUBLE_VOICE) != 0) + inst.instFlags |= BanksDump::InstrumentEntry::WOPL_Ins_4op | BanksDump::InstrumentEntry::WOPL_Ins_Pseudo4op; + inst.percussionKeyNumber = tmp2.notenum; + inst.secondVoiceDetune = static_cast<char>(static_cast<int>(ins.finetune) - 128); + if(!(ins.flags & FL_DOUBLE_VOICE)) { size_t resno = InsertIns(tmp[0], tmp2, std::string(1, '\377') + name, name2); @@ -138,6 +155,8 @@ static bool LoadDoom(const char *fn, unsigned bank, const char *prefix) SetBank(bank, (unsigned int)gmno, resno); } + db.addInstrument(bnk, patchId, inst, ops, fn); + /*const Doom_OPL2instrument& A = ins.patchdata[0]; const Doom_OPL2instrument& B = ins.patchdata[1]; printf( @@ -159,6 +178,9 @@ static bool LoadDoom(const char *fn, unsigned bank, const char *prefix) printf("------------------------------------------------------------\n");*/ } + db.addMidiBank(bankDb, false, bnkMelodique); + db.addMidiBank(bankDb, true, bnkPercussion); + AdlBankSetup setup; setup.volumeModel = VOLUME_DMX; setup.deepTremolo = false; diff --git a/utils/gen_adldata/file_formats/load_tmb.h b/utils/gen_adldata/file_formats/load_tmb.h index 4417b02..d9d57dd 100644 --- a/utils/gen_adldata/file_formats/load_tmb.h +++ b/utils/gen_adldata/file_formats/load_tmb.h @@ -4,7 +4,7 @@ #include "../progs_cache.h" #include "../midi_inst_list.h" -static bool LoadTMB(const char *fn, unsigned bank, const char *prefix) +bool BankFormats::LoadTMB(BanksDump &db, const char *fn, unsigned bank, const std::string &bankTitle, const char *prefix) { #ifdef HARD_BANKS writeIni("TMB", fn, prefix, bank, INI_Both); @@ -22,7 +22,11 @@ static bool LoadTMB(const char *fn, unsigned bank, const char *prefix) } std::fclose(fp); - for(unsigned a = 0; a < 256; ++a) + size_t bankDb = db.initBank(bank, bankTitle, BanksDump::BankEntry::SETUP_Apogee); + BanksDump::MidiBank bnkMelodique; + BanksDump::MidiBank bnkPercussion; + + for(unsigned a = 0, patchId = 0; a < 256; ++a, patchId++) { unsigned offset = a * 0x0D; unsigned gmno = a; @@ -30,6 +34,12 @@ static bool LoadTMB(const char *fn, unsigned bank, const char *prefix) : gmno < 128 + 35 ? -1 : gmno < 128 + 88 ? int(gmno - 35) : -1; + if(patchId == 128) + patchId = 0; + bool isPercussion = a >= 128; + BanksDump::MidiBank &bnk = isPercussion ? bnkPercussion : bnkMelodique; + BanksDump::InstrumentEntry inst; + BanksDump::Operator ops[5]; insdata tmp; @@ -55,6 +65,11 @@ static bool LoadTMB(const char *fn, unsigned bank, const char *prefix) tmp2.midi_velocity_offset = (int8_t)data[offset + 12]; tmp2.rhythmModeDrum = 0; + inst.percussionKeyNumber = data[offset + 11]; + inst.midiVelocityOffset = (int8_t)data[offset + 12]; + inst.fbConn = data[offset + 10]; + db.toOps(tmp, ops, 0); + std::string name; if(midi_index >= 0) name = std::string(1, '\377') + MidiInsName[midi_index]; @@ -64,8 +79,13 @@ static bool LoadTMB(const char *fn, unsigned bank, const char *prefix) size_t resno = InsertIns(tmp, tmp2, name, name2); SetBank(bank, gmno, resno); + + db.addInstrument(bnk, patchId, inst, ops, fn); } + db.addMidiBank(bankDb, false, bnkMelodique); + db.addMidiBank(bankDb, true, bnkPercussion); + AdlBankSetup setup; setup.volumeModel = VOLUME_APOGEE; setup.deepTremolo = false; diff --git a/utils/gen_adldata/file_formats/load_wopl.h b/utils/gen_adldata/file_formats/load_wopl.h index cd8765e..047ed7b 100644 --- a/utils/gen_adldata/file_formats/load_wopl.h +++ b/utils/gen_adldata/file_formats/load_wopl.h @@ -18,7 +18,7 @@ enum class WOPL_Flags WOPL_RhythmModeMask = 0x38, }; -static bool LoadWopl(const char *fn, unsigned bank, const char *prefix) +bool BankFormats::LoadWopl(BanksDump &db, const char *fn, unsigned bank, const std::string bankTitle, const char *prefix) { FILE *fp = std::fopen(fn, "rb"); if(!fp) @@ -27,6 +27,7 @@ static bool LoadWopl(const char *fn, unsigned bank, const char *prefix) std::fflush(stderr); return false; } + std::fseek(fp, 0, SEEK_END); std::vector<unsigned char> data(size_t(std::ftell(fp))); std::rewind(fp); @@ -63,6 +64,8 @@ static bool LoadWopl(const char *fn, unsigned bank, const char *prefix) setup.volumeModel = (int)data[0x12]; setup.scaleModulators = false; + size_t bankDb = db.initBank(bank, bankTitle, static_cast<uint_fast16_t>((static_cast<unsigned>(data[0x11]) << 8) | static_cast<unsigned>(data[0x12]))); + // Validate file format by size calculation if(version == 1) { @@ -91,28 +94,51 @@ static bool LoadWopl(const char *fn, unsigned bank, const char *prefix) uint32_t melodic_offset = 0; uint32_t percussion_offset = 0; + uint32_t melodic_meta_offset = 0; + uint32_t percussion_meta_offset = 0; + if(version < 2) + { melodic_offset = 0x13; + melodic_meta_offset = 0; + } else + { melodic_offset = 0x13 + 34 * mbanks_count + 34 * pbanks_count; + melodic_meta_offset = 0x13; + percussion_meta_offset = 0x13 + 34 * mbanks_count; + } percussion_offset = melodic_offset + (insSize * 128 * mbanks_count); - uint32_t root_offsets[2] = {melodic_offset, percussion_offset}; + uint32_t root_sizes[2] = {mbanks_count, pbanks_count}; + uint32_t root_offsets[2] = {melodic_offset, percussion_offset}; + uint32_t root_meta_offsets[2] = {melodic_meta_offset, percussion_meta_offset}; for(size_t bset = 0; bset < 2; bset++) { bool is_percussion = (bset == 1); - for(uint32_t bankno = 0; bankno < 1; bankno++) // only first melodic bank (Until multi-banks support will be implemented) + for(uint32_t bankno = 0; bankno < root_sizes[bset]; bankno++) // only first melodic bank (Until multi-banks support will be implemented) { uint32_t bank_offset = root_offsets[bset] + (bankno * insSize * 128); + BanksDump::MidiBank bnk; + if(version >= 2) + { + uint32_t meta_offset = root_meta_offsets[bset] + (bankno * 34); + bnk.lsb = data[meta_offset + 32 + 0]; + bnk.msb = data[meta_offset + 32 + 1]; + } + for(uint32_t i = 0; i < 128; i++) { uint32_t offset = bank_offset + uint32_t(i * insSize); std::string name; insdata tmp[2]; + BanksDump::InstrumentEntry inst; + BanksDump::Operator ops[5]; + name.resize(32); std::memcpy(&name[0], data.data() + offset, 32); name.resize(std::strlen(&name[0])); @@ -160,6 +186,9 @@ static bool LoadWopl(const char *fn, unsigned bank, const char *prefix) * Those fields are made for hot-loading while runtime, but not * for generation of embedded banks database. */ + db.toOps(tmp[0], ops, 0); + db.toOps(tmp[1], ops, 2); + tmp[0].finetune = int8_t(toSint16BE((const uint8_t *)data.data() + offset + 32)); tmp[1].finetune = int8_t(toSint16BE((const uint8_t *)data.data() + offset + 34)); @@ -175,6 +204,21 @@ static bool LoadWopl(const char *fn, unsigned bank, const char *prefix) tmp2.rhythmModeDrum = (flags & (uint8_t)WOPL_Flags::WOPL_RhythmModeMask); tmp[0].diff = false; tmp[1].diff = real4op && !tmp2.pseudo4op; + //---------------- + inst.instFlags = flags; + inst.percussionKeyNumber = is_percussion ? data[offset + 38] : 0; + inst.noteOffset1 = int8_t(toSint16BE((const uint8_t *)data.data() + offset + 32)); + inst.noteOffset2 = int8_t(toSint16BE((const uint8_t *)data.data() + offset + 34)); + inst.secondVoiceDetune = static_cast<int_fast8_t>(data[offset + 37]); + inst.midiVelocityOffset = static_cast<int_fast8_t>(data[offset + 36]); + inst.fbConn = (static_cast<uint_fast16_t>(data[offset + 40])) | + (static_cast<uint_fast16_t>(data[offset + 41]) << 8); + if(version >= 2) + { + inst.delay_on_ms = toUint16BE((const uint8_t *)data.data() + offset + 62); + inst.delay_off_ms = toUint16BE((const uint8_t *)data.data() + offset + 64); + } + //---------------- int8_t fine_tune = (int8_t)data[offset + 37]; if(fine_tune != 0) @@ -214,17 +258,22 @@ static bool LoadWopl(const char *fn, unsigned bank, const char *prefix) else snprintf(name2, 512, "%sM%u", prefix, i); - if(!real4op && !tmp2.pseudo4op) + if(bankno == 0) { - size_t resno = InsertIns(tmp[0], tmp2, name, name2); - SetBank(bank, gmno, resno); - } - else - { - size_t resno = InsertIns(tmp[0], tmp[1], tmp2, name, name2); - SetBank(bank, gmno, resno); + if(!real4op && !tmp2.pseudo4op) + { + size_t resno = InsertIns(tmp[0], tmp2, name, name2); + SetBank(bank, gmno, resno); + } + else + { + size_t resno = InsertIns(tmp[0], tmp[1], tmp2, name, name2); + SetBank(bank, gmno, resno); + } } + db.addInstrument(bnk, i, inst, ops, fn); } + db.addMidiBank(bankDb, is_percussion, bnk); } } |