diff --git a/src/Band.c b/src/Band.c index f7b2809..9cd66a1 100644 --- a/src/Band.c +++ b/src/Band.c @@ -52,16 +52,16 @@ DmDlsInstrument* DmInstrument_getDlsInstrument(DmInstrument* slf) { uint32_t patch = slf->patch & 0xFFU; DmDlsInstrument* ins = NULL; - for (size_t i = 0; i < slf->dls->instrument_count; ++i) { + for (long long i = slf->dls->instrument_count; i >= 0; --i) { ins = &slf->dls->instruments[i]; - // TODO(lmichaelis): We need to ignore drum kits for now since I don't know how to handle them properly - if (ins->bank & DmDls_DRUM_KIT) { - continue; - } - // If it's the correct instrument, return it. - if (ins->bank == bank && ins->patch == patch) { + // TODO(lmichaelis): Dirty fix for drum kit problems. Instead of choosing the first valid DLS instrument, we + // chose the last valid one. This acts as if later instruments override previous ones and + // thus prevents problems where the same channel is re-used multiple times, specifically in + // Gothic 1, which assigns a drum kit and melodic instrument to the same channel. This works + // in conjunction with the TSF creation in Dm_createHydra to prevent drum kit issues in G1. + if ((ins->bank & 127) == bank && ins->patch == patch) { return ins; } } diff --git a/src/util/Tsf.c b/src/util/Tsf.c index be6e839..3c17e3c 100644 --- a/src/util/Tsf.c +++ b/src/util/Tsf.c @@ -287,14 +287,14 @@ static DmResult Dm_createHydra(DmDls* dls, struct tsf_hydra* hydra, float** pcm, uint32_t imod_ndx = 0; uint32_t shdr_ndx = 0; for (size_t i = 0; i < dls->instrument_count; ++i) { - DmDlsInstrument* ins = &dls->instruments[i]; + // TODO(lmichaelis): Dirty fix for drum kit problems. We add the instruments in reverse, so that TSF always + // behaves as-if instruments later in the sequence override previous instruments. This allows + // Gothic 2 to use drum kits as intended and prevents Gothic 1 from playing from the + // Metronom.dls file when it shouldn't. This works in conjunction with the channel selection + // from DmInstrument_getDlsInstrument. + DmDlsInstrument* ins = &dls->instruments[dls->instrument_count - 1 - i]; uint32_t bank = ins->bank; - // Ignore drum kits for now. - if (ins->bank & DmDls_DRUM_KIT) { - bank = 999; - } - strncpy(hydra->phdrs[i].presetName, ins->info.inam, 19); hydra->phdrs[i].bank = bank; hydra->phdrs[i].preset = ins->patch;