Skip to content

Commit

Permalink
[Ref] Pass ModChannel instead of whole PlayState to GetChannelPlugin/…
Browse files Browse the repository at this point in the history
…GetBestPlugin.

git-svn-id: https://source.openmpt.org/svn/openmpt/trunk/OpenMPT@22356 56274372-70c3-4bfc-bfc3-4c3a0b034d27
  • Loading branch information
sagamusix committed Nov 30, 2024
1 parent a55b743 commit c2fc31f
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 39 deletions.
2 changes: 1 addition & 1 deletion mptrack/EffectInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 12 additions & 13 deletions mptrack/Moddoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1329,33 +1329,32 @@ 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);
}
}
} 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
Expand Down
2 changes: 1 addition & 1 deletion soundlib/Fastmix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
35 changes: 14 additions & 21 deletions soundlib/Snd_fx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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<const IMidiPlugin *>(m_MixPlugins[plug - 1u].pMixPlugin);
Expand Down Expand Up @@ -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--;
Expand All @@ -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--;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}
Expand All @@ -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])
{
Expand Down
4 changes: 2 additions & 2 deletions soundlib/Sndfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down
2 changes: 1 addition & 1 deletion soundlib/Sndmix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit c2fc31f

Please sign in to comment.