From: <sv...@op...> - 2024-05-06 18:17:44
|
Author: sagamusix Date: Mon May 6 20:17:31 2024 New Revision: 20712 URL: https://source.openmpt.org/browse/openmpt/?op=revision&rev=20712 Log: [Imp] Expanded mix now also works with plugins that have no inputs. [Imp] All mix modes are now available for instrument plugins as well. The old plugin mixing behaviour for instrument plugins is emulated with the new "instrument mix mode" (https://forum.openmpt.org/index.php?topic=7178.0). [Mod] OpenMPT: Version is now 1.32.00.11 Modified: trunk/OpenMPT/common/versionNumber.h trunk/OpenMPT/mptrack/SelectPluginDialog.cpp trunk/OpenMPT/mptrack/View_gen.cpp trunk/OpenMPT/soundlib/Sndfile.cpp trunk/OpenMPT/soundlib/plugins/PlugInterface.cpp trunk/OpenMPT/soundlib/plugins/PluginStructs.h Modified: trunk/OpenMPT/common/versionNumber.h ============================================================================== --- trunk/OpenMPT/common/versionNumber.h Mon May 6 18:58:40 2024 (r20711) +++ trunk/OpenMPT/common/versionNumber.h Mon May 6 20:17:31 2024 (r20712) @@ -18,6 +18,6 @@ #define VER_MAJORMAJOR 1 #define VER_MAJOR 32 #define VER_MINOR 00 -#define VER_MINORMINOR 10 +#define VER_MINORMINOR 11 OPENMPT_NAMESPACE_END Modified: trunk/OpenMPT/mptrack/SelectPluginDialog.cpp ============================================================================== --- trunk/OpenMPT/mptrack/SelectPluginDialog.cpp Mon May 6 18:58:40 2024 (r20711) +++ trunk/OpenMPT/mptrack/SelectPluginDialog.cpp Mon May 6 20:17:31 2024 (r20712) @@ -166,7 +166,7 @@ { // Enable drymix by default for these known plugins case Vst::FourCC("Scop"): - m_pPlugin->SetWetMix(); + m_pPlugin->SetDryMix(); break; } } @@ -189,6 +189,8 @@ { m_pPlugin->Info.szName = mpt::ToCharset(mpt::Charset::Locale, name); } + m_pPlugin->SetDryMix(p->IsInstrument()); + // Check if plugin slot is already assigned to any instrument, and if not, create one. if(p->IsInstrument() && m_pModDoc->HasInstrumentForPlugin(m_nPlugSlot) == INSTRUMENTINDEX_INVALID) { Modified: trunk/OpenMPT/mptrack/View_gen.cpp ============================================================================== --- trunk/OpenMPT/mptrack/View_gen.cpp Mon May 6 18:58:40 2024 (r20711) +++ trunk/OpenMPT/mptrack/View_gen.cpp Mon May 6 20:17:31 2024 (r20712) @@ -227,6 +227,7 @@ m_CbnSpecialMixProcessing.AddString(_T("Mix Subtract")); m_CbnSpecialMixProcessing.AddString(_T("Middle Subtract")); m_CbnSpecialMixProcessing.AddString(_T("LR Balance")); + m_CbnSpecialMixProcessing.AddString(_T("Instrument")); m_SpinMixGain.SetRange(0, 80); m_SpinMixGain.SetPos(10); SetDlgItemText(IDC_EDIT16, _T("Gain: x1.0")); @@ -448,7 +449,7 @@ SetDlgItemText(IDC_EDIT13, mpt::ToCString(plugin.GetName())); CheckDlgButton(IDC_CHECK9, plugin.IsMasterEffect() ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(IDC_CHECK10, plugin.IsBypassed() ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(IDC_CHECK11, plugin.IsWetMix() ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(IDC_CHECK11, plugin.IsDryMix() ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(IDC_CHECK13, plugin.IsAutoSuspendable() ? BST_CHECKED : BST_UNCHECKED); IMixPlugin *pPlugin = plugin.pMixPlugin; m_BtnEdit.EnableWindow((pPlugin != nullptr && (pPlugin->HasEditor() || pPlugin->GetNumParameters())) ? TRUE : FALSE); @@ -457,17 +458,8 @@ GetDlgItem(IDC_CLONEPLUG)->EnableWindow((pPlugin) ? TRUE : FALSE); UpdateDryWetDisplay(); - if(pPlugin && pPlugin->IsInstrument()) - { - m_CbnSpecialMixProcessing.EnableWindow(FALSE); - GetDlgItem(IDC_CHECK12)->EnableWindow(FALSE); - } else - { - m_CbnSpecialMixProcessing.EnableWindow(TRUE); - GetDlgItem(IDC_CHECK12)->EnableWindow(TRUE); - m_CbnSpecialMixProcessing.SetCurSel(plugin.GetMixMode()); - CheckDlgButton(IDC_CHECK12, plugin.IsExpandedMix() ? BST_CHECKED : BST_UNCHECKED); - } + m_CbnSpecialMixProcessing.SetCurSel(static_cast<int>(plugin.GetMixMode())); + CheckDlgButton(IDC_CHECK12, plugin.IsExpandedMix() ? BST_CHECKED : BST_UNCHECKED); int gain = plugin.GetGain(); if(gain == 0) gain = 10; float value = 0.1f * (float)gain; @@ -1342,7 +1334,7 @@ CModDoc *pModDoc = GetDocument(); if ((m_nCurrentPlugin >= MAX_MIXPLUGINS) || (!pModDoc)) return; - pModDoc->GetSoundFile().m_MixPlugins[m_nCurrentPlugin].SetMixMode((uint8)m_CbnSpecialMixProcessing.GetCurSel()); + pModDoc->GetSoundFile().m_MixPlugins[m_nCurrentPlugin].SetMixMode(static_cast<PluginMixMode>(m_CbnSpecialMixProcessing.GetCurSel())); SetPluginModified(); } @@ -1352,7 +1344,7 @@ CModDoc *pModDoc = GetDocument(); if ((m_nCurrentPlugin >= MAX_MIXPLUGINS) || (!pModDoc)) return; - pModDoc->GetSoundFile().m_MixPlugins[m_nCurrentPlugin].SetWetMix(IsDlgButtonChecked(IDC_CHECK11) != BST_UNCHECKED); + pModDoc->GetSoundFile().m_MixPlugins[m_nCurrentPlugin].SetDryMix(IsDlgButtonChecked(IDC_CHECK11) != BST_UNCHECKED); SetPluginModified(); } Modified: trunk/OpenMPT/soundlib/Sndfile.cpp ============================================================================== --- trunk/OpenMPT/soundlib/Sndfile.cpp Mon May 6 18:58:40 2024 (r20711) +++ trunk/OpenMPT/soundlib/Sndfile.cpp Mon May 6 20:17:31 2024 (r20712) @@ -735,6 +735,15 @@ { // Plugin was found plugin.pMixPlugin->RestoreAllParameters(plugin.defaultProgram); + + // Special handling for instrument plugins in ProcessMixOps was removed + if(m_dwLastSavedWithVersion < MPT_V("1.32.00.11")) + { + if(plugin.pMixPlugin->IsInstrument()) + plugin.SetMixMode(PluginMixMode::Instrument); + if(!plugin.pMixPlugin->GetNumInputChannels()) + plugin.SetExpandedMix(false); + } } else { // Plugin not found - add to list Modified: trunk/OpenMPT/soundlib/plugins/PlugInterface.cpp ============================================================================== --- trunk/OpenMPT/soundlib/plugins/PlugInterface.cpp Mon May 6 18:58:40 2024 (r20711) +++ trunk/OpenMPT/soundlib/plugins/PlugInterface.cpp Mon May 6 20:17:31 2024 (r20712) @@ -239,24 +239,17 @@ // -> mixop == 4 : MIX -= middle - WET * wetRatio + middle - DRY // -> mixop == 5 : MIX_L += wetRatio * (WET_L - DRY_L) + dryRatio * (DRY_R - WET_R) // MIX_R += dryRatio * (WET_L - DRY_L) + wetRatio * (DRY_R - WET_R) + // -> mixop == 6: same as normal, but forces dry ratio to 1 MPT_ASSERT(m_pMixStruct != nullptr); - int mixop; - if(IsInstrument()) - { - // Force normal mix mode for instruments - mixop = 0; - } else - { - mixop = m_pMixStruct->GetMixMode(); - } + const PluginMixMode mixop = m_pMixStruct->GetMixMode(); - float wetRatio = 1 - m_pMixStruct->fDryRatio; - float dryRatio = IsInstrument() ? 1 : m_pMixStruct->fDryRatio; // Always mix full dry if this is an instrument + float wetRatio = 1.f - m_pMixStruct->fDryRatio; + float dryRatio = (mixop == PluginMixMode::Instrument) ? 1.f : m_pMixStruct->fDryRatio; // Wet / Dry range expansion [0,1] -> [-1,1] - if(GetNumInputChannels() > 0 && m_pMixStruct->IsExpandedMix()) + if(m_pMixStruct->IsExpandedMix()) { wetRatio = 2.0f * wetRatio - 1.0f; dryRatio = -wetRatio; @@ -273,17 +266,17 @@ { // Default mix - case 0: + case PluginMixMode::Default: + case PluginMixMode::Instrument: for(uint32 i = 0; i < numFrames; i++) { - //rewbs.wetratio - added the factors. [20040123] pOutL[i] += leftPlugOutput[i] * wetRatio + plugInputL[i] * dryRatio; pOutR[i] += rightPlugOutput[i] * wetRatio + plugInputR[i] * dryRatio; } break; // Wet subtract - case 1: + case PluginMixMode::WetSubtract: for(uint32 i = 0; i < numFrames; i++) { pOutL[i] += plugInputL[i] - leftPlugOutput[i] * wetRatio; @@ -292,7 +285,7 @@ break; // Dry subtract - case 2: + case PluginMixMode::DrySubtract: for(uint32 i = 0; i < numFrames; i++) { pOutL[i] += leftPlugOutput[i] - plugInputL[i] * dryRatio; @@ -301,7 +294,7 @@ break; // Mix subtract - case 3: + case PluginMixMode::MixSubtract: for(uint32 i = 0; i < numFrames; i++) { pOutL[i] -= leftPlugOutput[i] - plugInputL[i] * wetRatio; @@ -310,17 +303,17 @@ break; // Middle subtract - case 4: + case PluginMixMode::MiddleSubtract: for(uint32 i = 0; i < numFrames; i++) { - float middle = (pOutL[i] + plugInputL[i] + pOutR[i] + plugInputR[i]) / 2.0f; + float middle = (pOutL[i] + plugInputL[i] + pOutR[i] + plugInputR[i]) * 0.5f; pOutL[i] -= middle - leftPlugOutput[i] * wetRatio + middle - plugInputL[i]; pOutR[i] -= middle - rightPlugOutput[i] * wetRatio + middle - plugInputR[i]; } break; // Left / Right balance - case 5: + case PluginMixMode::LRBalance: if(m_pMixStruct->IsExpandedMix()) { wetRatio /= 2.0f; @@ -336,8 +329,8 @@ } // If dry mix is ticked, we add the unprocessed buffer, - // except if this is an instrument since then it has already been done: - if(m_pMixStruct->IsWetMix() && !IsInstrument()) + // except with the instrument mixop as it has already been done: + if(m_pMixStruct->IsDryMix() && mixop != PluginMixMode::Instrument) { for(uint32 i = 0; i < numFrames; i++) { Modified: trunk/OpenMPT/soundlib/plugins/PluginStructs.h ============================================================================== --- trunk/OpenMPT/soundlib/plugins/PluginStructs.h Mon May 6 18:58:40 2024 (r20711) +++ trunk/OpenMPT/soundlib/plugins/PluginStructs.h Mon May 6 20:17:31 2024 (r20712) @@ -32,6 +32,17 @@ #ifndef NO_PLUGINS +enum class PluginMixMode : uint8 +{ + Default = 0, + WetSubtract = 1, + DrySubtract = 2, + MixSubtract = 3, + MiddleSubtract = 4, + LRBalance = 5, + Instrument = 6, +}; + struct SNDMIXPLUGININFO { // dwInputRouting flags @@ -39,7 +50,7 @@ { irApplyToMaster = 0x01, // Apply to master mix irBypass = 0x02, // Bypass effect - irWetMix = 0x04, // Wet Mix (dry added) + irDryMix = 0x04, // Wet Mix (dry added) irExpandMix = 0x08, // [0%,100%] -> [-200%,200%] irAutoSuspend = 0x10, // Plugin will automatically suspend on silence }; @@ -92,12 +103,12 @@ // Input routing getters uint8 GetGain() const { return Info.gain; } - uint8 GetMixMode() const - { return Info.mixMode; } + PluginMixMode GetMixMode() const + { return static_cast<PluginMixMode>(Info.mixMode.get()); } bool IsMasterEffect() const { return (Info.routingFlags & SNDMIXPLUGININFO::irApplyToMaster) != 0; } - bool IsWetMix() const - { return (Info.routingFlags & SNDMIXPLUGININFO::irWetMix) != 0; } + bool IsDryMix() const + { return (Info.routingFlags & SNDMIXPLUGININFO::irDryMix) != 0; } bool IsExpandedMix() const { return (Info.routingFlags & SNDMIXPLUGININFO::irExpandMix) != 0; } bool IsBypassed() const @@ -107,12 +118,12 @@ // Input routing setters void SetGain(uint8 gain); - void SetMixMode(uint8 mixMode) - { Info.mixMode = mixMode; } + void SetMixMode(PluginMixMode mixMode) + { Info.mixMode = static_cast<uint8>(mixMode); } void SetMasterEffect(bool master = true) { if(master) Info.routingFlags |= SNDMIXPLUGININFO::irApplyToMaster; else Info.routingFlags &= uint8(~SNDMIXPLUGININFO::irApplyToMaster); } - void SetWetMix(bool wetMix = true) - { if(wetMix) Info.routingFlags |= SNDMIXPLUGININFO::irWetMix; else Info.routingFlags &= uint8(~SNDMIXPLUGININFO::irWetMix); } + void SetDryMix(bool wetMix = true) + { if(wetMix) Info.routingFlags |= SNDMIXPLUGININFO::irDryMix; else Info.routingFlags &= uint8(~SNDMIXPLUGININFO::irDryMix); } void SetExpandedMix(bool expanded = true) { if(expanded) Info.routingFlags |= SNDMIXPLUGININFO::irExpandMix; else Info.routingFlags &= uint8(~SNDMIXPLUGININFO::irExpandMix); } void SetBypass(bool bypass = true); |