From: <sv...@op...> - 2024-05-31 18:40:44
|
Author: sagamusix Date: Fri May 31 20:40:32 2024 New Revision: 20886 URL: https://source.openmpt.org/browse/openmpt/?op=revision&rev=20886 Log: [Fix] FTM: Don't look for command to run new effect on work track but the exact channel we are evaluating. [Fix] FTM: Trying to trigger an undefined effect executed the effect with the next higher ID instead. Modified: trunk/OpenMPT/soundlib/InstrumentSynth.cpp trunk/OpenMPT/soundlib/Load_ftm.cpp Modified: trunk/OpenMPT/soundlib/InstrumentSynth.cpp ============================================================================== --- trunk/OpenMPT/soundlib/InstrumentSynth.cpp Fri May 31 19:31:28 2024 (r20885) +++ trunk/OpenMPT/soundlib/InstrumentSynth.cpp Fri May 31 20:40:32 2024 (r20886) @@ -860,8 +860,7 @@ for(CHANNELINDEX chn = 0; chn < sndFile.GetNumChannels(); chn++) { auto &state = states[chn]; - CHANNELINDEX realChn = state.FTMRealChannel(chn, sndFile); - auto &modChn = playState.Chn[realChn]; + auto &modChn = playState.Chn[chn]; if(modChn.rowCommand.command == CMD_MED_SYNTH_JUMP && modChn.isFirstTick) states[chn].JumpToPosition(sndFile.m_globalScript, modChn.rowCommand.param); int32 period = 0; Modified: trunk/OpenMPT/soundlib/Load_ftm.cpp ============================================================================== --- trunk/OpenMPT/soundlib/Load_ftm.cpp Fri May 31 19:31:28 2024 (r20885) +++ trunk/OpenMPT/soundlib/Load_ftm.cpp Fri May 31 20:40:32 2024 (r20886) @@ -179,14 +179,17 @@ } auto &events = m_globalScript; + constexpr uint16 STOP_INDEX = uint16_max - 1; std::map<uint16, uint16> offsetToIndex; + std::bitset<64> effectDefined; for(uint8 effect = 0; effect < fileHeader.numEffects; effect++) { const auto [numLines, index] = file.ReadArray<uint16be, 2>(); if(numLines > 0x200 || index > 63 || offsetToIndex.count(index << 10)) return false; - events.reserve(5 + numLines); - events.push_back(InstrumentSynth::Event::StopScript()); + effectDefined.set(index); + events.reserve(events.size() + 4 + numLines); + events.push_back(InstrumentSynth::Event::Jump(STOP_INDEX)); events.push_back(InstrumentSynth::Event::JumpMarker(index)); events.push_back(InstrumentSynth::Event::FTM_SetWorkTrack(uint8_max, false)); events.push_back(InstrumentSynth::Event::FTM_SetInterrupt(uint16_max, uint8_max)); @@ -223,8 +226,7 @@ events.push_back(InstrumentSynth::Event::Jump(static_cast<uint16>((u12hi << 10) | (jumpTarget & 0x3FF)))); break; case 5: // END OF EFFECT [......] - events.push_back(InstrumentSynth::Event::FTM_SetInterrupt(uint16_max, uint8_max)); - events.push_back(InstrumentSynth::Event::StopScript()); + events.push_back(InstrumentSynth::Event::Jump(STOP_INDEX)); break; case 6: // IF PITCH=v GOTO l [ppplll] case 7: // IF PITCH<v GOTO l [ppplll] @@ -334,6 +336,11 @@ break; } } + } + if(fileHeader.numEffects) + { + events.push_back(InstrumentSynth::Event::JumpMarker(64)); + offsetToIndex[STOP_INDEX] = static_cast<uint16>(events.size()); events.push_back(InstrumentSynth::Event::FTM_SetInterrupt(uint16_max, uint8_max)); } for(auto &event : events) @@ -390,7 +397,7 @@ m.instr = param; break; case 0xB0: // SEL effect - m.SetEffectCommand(CMD_MED_SYNTH_JUMP, param); + m.SetEffectCommand(CMD_MED_SYNTH_JUMP, (param < effectDefined.size() && effectDefined[param]) ? param : 64); break; case 0xC0: // Pitch bend m.SetEffectCommand(CMD_TONEPORTA_DURATION, param); |