From c2fc31f43b29d26b59ea8979c7d4b6079947e4ee Mon Sep 17 00:00:00 2001 From: Johannes Schultz Date: Sat, 30 Nov 2024 13:50:41 +0000 Subject: [PATCH] [Ref] Pass ModChannel instead of whole PlayState to GetChannelPlugin/GetBestPlugin. git-svn-id: https://source.openmpt.org/svn/openmpt/trunk/OpenMPT@22356 56274372-70c3-4bfc-bfc3-4c3a0b034d27 --- mptrack/EffectInfo.cpp | 2 +- mptrack/Moddoc.cpp | 25 ++++++++++++------------- soundlib/Fastmix.cpp | 2 +- soundlib/Snd_fx.cpp | 35 ++++++++++++++--------------------- soundlib/Sndfile.h | 4 ++-- soundlib/Sndmix.cpp | 2 +- 6 files changed, 31 insertions(+), 39 deletions(-) diff --git a/mptrack/EffectInfo.cpp b/mptrack/EffectInfo.cpp index 70793193cdd..9ecc535ac6b 100644 --- a/mptrack/EffectInfo.cpp +++ b/mptrack/EffectInfo.cpp @@ -680,7 +680,7 @@ bool EffectInfo::GetEffectNameEx(CString &pszName, const ModCommand &m, uint32 p if(chn != CHANNELINDEX_INVALID) { const uint8 macroIndex = sndFile.m_PlayState.Chn[chn].nActiveMacro; - const PLUGINDEX plugin = sndFile.GetBestPlugin(sndFile.m_PlayState, chn, PrioritiseChannel, EvenIfMuted) - 1; + const PLUGINDEX plugin = sndFile.GetBestPlugin(sndFile.m_PlayState.Chn[chn], chn, PrioritiseChannel, EvenIfMuted) - 1; IMixPlugin *pPlugin = (plugin < MAX_MIXPLUGINS ? sndFile.m_MixPlugins[plugin].pMixPlugin : nullptr); pszName.Format(_T("SFx MIDI Macro z=%d (SF%X: %s)"), param, macroIndex, sndFile.m_MidiCfg.GetParameteredMacroName(macroIndex, pPlugin).GetString()); } else diff --git a/mptrack/Moddoc.cpp b/mptrack/Moddoc.cpp index ba80170cf2a..4ddeb27249c 100644 --- a/mptrack/Moddoc.cpp +++ b/mptrack/Moddoc.cpp @@ -1329,25 +1329,24 @@ bool CModDoc::UpdateChannelMuteStatus(CHANNELINDEX nChn) { const ChannelFlags muteType = CSoundFile::GetChannelMuteFlag(); - if (nChn >= m_SndFile.GetNumChannels()) - { + if(nChn >= m_SndFile.GetNumChannels()) return false; - } + ModChannel &chn = m_SndFile.m_PlayState.Chn[nChn]; const bool doMute = m_SndFile.ChnSettings[nChn].dwFlags[CHN_MUTE]; - - // Mute pattern channel - if (doMute) + if(doMute) { - m_SndFile.m_PlayState.Chn[nChn].dwFlags.set(muteType); - if(m_SndFile.m_opl) m_SndFile.m_opl->NoteCut(nChn); + // Mute pattern channel + chn.dwFlags.set(muteType); + if(m_SndFile.m_opl) + m_SndFile.m_opl->NoteCut(nChn); // Kill VSTi notes on muted channel. - PLUGINDEX nPlug = m_SndFile.GetBestPlugin(m_SndFile.m_PlayState, nChn, PrioritiseInstrument, EvenIfMuted); - if ((nPlug) && (nPlug<=MAX_MIXPLUGINS)) + PLUGINDEX nPlug = m_SndFile.GetBestPlugin(chn, nChn, PrioritiseInstrument, EvenIfMuted); + if(nPlug > 0 && nPlug <= MAX_MIXPLUGINS) { IMixPlugin *pPlug = m_SndFile.m_MixPlugins[nPlug - 1].pMixPlugin; - const ModInstrument* pIns = m_SndFile.m_PlayState.Chn[nChn].pModInstrument; - if (pPlug && pIns) + const ModInstrument* pIns = chn.pModInstrument; + if(pPlug && pIns) { pPlug->MidiCommand(*pIns, NOTE_KEYOFF, 0, nChn); } @@ -1355,7 +1354,7 @@ bool CModDoc::UpdateChannelMuteStatus(CHANNELINDEX nChn) } else { // On unmute alway cater for both mute types - this way there's no probs if user changes mute mode. - m_SndFile.m_PlayState.Chn[nChn].dwFlags.reset(CHN_SYNCMUTE | CHN_MUTE); + chn.dwFlags.reset(CHN_SYNCMUTE | CHN_MUTE); } // Mute any NNA'd channels diff --git a/soundlib/Fastmix.cpp b/soundlib/Fastmix.cpp index 84a029bd478..3e3e026e7be 100644 --- a/soundlib/Fastmix.cpp +++ b/soundlib/Fastmix.cpp @@ -353,7 +353,7 @@ void CSoundFile::CreateStereoMix(int count) //Look for plugins associated with this implicit tracker channel. #ifndef NO_PLUGINS - PLUGINDEX nMixPlugin = GetBestPlugin(m_PlayState, m_PlayState.ChnMix[nChn], PrioritiseInstrument, RespectMutes); + PLUGINDEX nMixPlugin = GetBestPlugin(chn, m_PlayState.ChnMix[nChn], PrioritiseInstrument, RespectMutes); if ((nMixPlugin > 0) && (nMixPlugin <= MAX_MIXPLUGINS) && m_MixPlugins[nMixPlugin - 1].pMixPlugin != nullptr) { diff --git a/soundlib/Snd_fx.cpp b/soundlib/Snd_fx.cpp index c7482326ffc..4c935ed25d3 100644 --- a/soundlib/Snd_fx.cpp +++ b/soundlib/Snd_fx.cpp @@ -2449,7 +2449,7 @@ CHANNELINDEX CSoundFile::CheckNNA(CHANNELINDEX nChn, uint32 instr, int note, boo IMixPlugin *pPlugin = nullptr; if(srcChn.HasMIDIOutput() && ModCommand::IsNote(srcChn.nNote)) // instro sends to a midi chan { - PLUGINDEX plugin = GetBestPlugin(m_PlayState, nChn, PrioritiseInstrument, RespectMutes); + PLUGINDEX plugin = GetBestPlugin(m_PlayState.Chn[nChn], nChn, PrioritiseInstrument, RespectMutes); if(plugin > 0 && plugin <= MAX_MIXPLUGINS) { @@ -5515,7 +5515,7 @@ void CSoundFile::ParseMIDIMacro(PlayState &playState, CHANNELINDEX nChn, bool is isNibble = true; data = 0xFF; #ifndef NO_PLUGINS - const PLUGINDEX plug = (plugin != 0) ? plugin : GetBestPlugin(playState, nChn, PrioritiseChannel, EvenIfMuted); + const PLUGINDEX plug = (plugin != 0) ? plugin : GetBestPlugin(chn, nChn, PrioritiseChannel, EvenIfMuted); if(plug > 0 && plug <= MAX_MIXPLUGINS) { auto midiPlug = dynamic_cast(m_MixPlugins[plug - 1u].pMixPlugin); @@ -5751,7 +5751,7 @@ void CSoundFile::SendMIDIData(PlayState &playState, CHANNELINDEX nChn, bool isSm } else if(macroCode == 0x03 && !isExtended) { // F0.F0.03.xx: Set plug dry/wet - PLUGINDEX plug = (plugin != 0) ? plugin : GetBestPlugin(playState, nChn, PrioritiseChannel, EvenIfMuted); + PLUGINDEX plug = (plugin != 0) ? plugin : GetBestPlugin(chn, nChn, PrioritiseChannel, EvenIfMuted); if(plug > 0 && plug <= MAX_MIXPLUGINS && param < 0x80) { plug--; @@ -5769,7 +5769,7 @@ void CSoundFile::SendMIDIData(PlayState &playState, CHANNELINDEX nChn, bool isSm } else if((macroCode & 0x80) || isExtended) { // F0.F0.{80|n}.xx / F0.F1.n.xx: Set VST effect parameter n to xx - PLUGINDEX plug = (plugin != 0) ? plugin : GetBestPlugin(playState, nChn, PrioritiseChannel, EvenIfMuted); + PLUGINDEX plug = (plugin != 0) ? plugin : GetBestPlugin(chn, nChn, PrioritiseChannel, EvenIfMuted); if(plug > 0 && plug <= MAX_MIXPLUGINS && param < 0x80) { plug--; @@ -5797,7 +5797,7 @@ void CSoundFile::SendMIDIData(PlayState &playState, CHANNELINDEX nChn, bool isSm PLUGINDEX plug = 0; if(!chn.dwFlags[CHN_NOFX]) { - plug = (plugin != 0) ? plugin : GetBestPlugin(playState, nChn, PrioritiseChannel, EvenIfMuted); + plug = (plugin != 0) ? plugin : GetBestPlugin(chn, nChn, PrioritiseChannel, EvenIfMuted); } if(plug > 0 && plug <= MAX_MIXPLUGINS) @@ -6776,35 +6776,30 @@ uint32 CSoundFile::GetFreqFromPeriod(uint32 period, uint32 c5speed, int32 nPerio } -PLUGINDEX CSoundFile::GetBestPlugin(const PlayState &playState, CHANNELINDEX nChn, PluginPriority priority, PluginMutePriority respectMutes) const +PLUGINDEX CSoundFile::GetBestPlugin(const ModChannel &channel, CHANNELINDEX nChn, PluginPriority priority, PluginMutePriority respectMutes) const { - if (nChn >= playState.Chn.size()) //Check valid channel number - { - return 0; - } - //Define search source order PLUGINDEX plugin = 0; - switch (priority) + switch(priority) { case ChannelOnly: - plugin = GetChannelPlugin(playState, nChn, respectMutes); + plugin = GetChannelPlugin(channel, nChn, respectMutes); break; case InstrumentOnly: - plugin = GetActiveInstrumentPlugin(playState.Chn[nChn], respectMutes); + plugin = GetActiveInstrumentPlugin(channel, respectMutes); break; case PrioritiseInstrument: - plugin = GetActiveInstrumentPlugin(playState.Chn[nChn], respectMutes); + plugin = GetActiveInstrumentPlugin(channel, respectMutes); if(!plugin || plugin > MAX_MIXPLUGINS) { - plugin = GetChannelPlugin(playState, nChn, respectMutes); + plugin = GetChannelPlugin(channel, nChn, respectMutes); } break; case PrioritiseChannel: - plugin = GetChannelPlugin(playState, nChn, respectMutes); + plugin = GetChannelPlugin(channel, nChn, respectMutes); if(!plugin || plugin > MAX_MIXPLUGINS) { - plugin = GetActiveInstrumentPlugin(playState.Chn[nChn], respectMutes); + plugin = GetActiveInstrumentPlugin(channel, respectMutes); } break; } @@ -6813,10 +6808,8 @@ PLUGINDEX CSoundFile::GetBestPlugin(const PlayState &playState, CHANNELINDEX nCh } -PLUGINDEX CSoundFile::GetChannelPlugin(const PlayState &playState, CHANNELINDEX nChn, PluginMutePriority respectMutes) const +PLUGINDEX CSoundFile::GetChannelPlugin(const ModChannel &channel, CHANNELINDEX nChn, PluginMutePriority respectMutes) const { - const ModChannel &channel = playState.Chn[nChn]; - PLUGINDEX plugin; if((respectMutes == RespectMutes && channel.dwFlags[CHN_MUTE | CHN_SYNCMUTE]) || channel.dwFlags[CHN_NOFX]) { diff --git a/soundlib/Sndfile.h b/soundlib/Sndfile.h index eede9546ff6..c303fce242f 100644 --- a/soundlib/Sndfile.h +++ b/soundlib/Sndfile.h @@ -1271,12 +1271,12 @@ class CSoundFile void ProcessStereoSeparation(samplecount_t countChunk); private: - PLUGINDEX GetChannelPlugin(const PlayState &playState, CHANNELINDEX nChn, PluginMutePriority respectMutes) const; + PLUGINDEX GetChannelPlugin(const ModChannel &channel, CHANNELINDEX nChn, PluginMutePriority respectMutes) const; static PLUGINDEX GetActiveInstrumentPlugin(const ModChannel &chn, PluginMutePriority respectMutes); IMixPlugin *GetChannelInstrumentPlugin(const ModChannel &chn) const; public: - PLUGINDEX GetBestPlugin(const PlayState &playState, CHANNELINDEX nChn, PluginPriority priority, PluginMutePriority respectMutes) const; + PLUGINDEX GetBestPlugin(const ModChannel &channel, CHANNELINDEX nChn, PluginPriority priority, PluginMutePriority respectMutes) const; PlaybackTest CreatePlaybackTest(PlaybackTestSettings settings); }; diff --git a/soundlib/Sndmix.cpp b/soundlib/Sndmix.cpp index dd2a9502d2d..ed077630afb 100644 --- a/soundlib/Sndmix.cpp +++ b/soundlib/Sndmix.cpp @@ -2645,7 +2645,7 @@ void CSoundFile::ProcessMidiOut(CHANNELINDEX nChn) } // Check instrument plugins - const PLUGINDEX nPlugin = GetBestPlugin(m_PlayState, nChn, PrioritiseInstrument, RespectMutes); + const PLUGINDEX nPlugin = GetBestPlugin(chn, nChn, PrioritiseInstrument, RespectMutes); IMixPlugin *pPlugin = nullptr; if(nPlugin > 0 && nPlugin <= MAX_MIXPLUGINS) {