From: <sv...@op...> - 2025-03-23 14:31:33
|
Author: sagamusix Date: Sun Mar 23 15:31:18 2025 New Revision: 23075 URL: https://source.openmpt.org/browse/openmpt/?op=revision&rev=23075 Log: [Imp] Sample tab: Show effective sample/OPL amplification based on global volume (related to https://forum.openmpt.org/index.php?topic=7308.0). Modified: trunk/OpenMPT/mptrack/Ctrl_gen.cpp trunk/OpenMPT/mptrack/Ctrl_ins.cpp trunk/OpenMPT/mptrack/Ctrl_smp.cpp trunk/OpenMPT/mptrack/Moddoc.cpp trunk/OpenMPT/mptrack/Moddoc.h trunk/OpenMPT/mptrack/PatternEditorDialogs.cpp trunk/OpenMPT/mptrack/View_gen.cpp trunk/OpenMPT/mptrack/View_smp.cpp Modified: trunk/OpenMPT/mptrack/Ctrl_gen.cpp ============================================================================== --- trunk/OpenMPT/mptrack/Ctrl_gen.cpp Sun Mar 23 14:26:45 2025 (r23074) +++ trunk/OpenMPT/mptrack/Ctrl_gen.cpp Sun Mar 23 15:31:18 2025 (r23075) @@ -725,17 +725,17 @@ s = notAvailable; break; case IDC_SLIDER_SAMPLEPREAMP: - s = displayDBValues ? CModDoc::LinearToDecibels(m_sndFile.m_nSamplePreAmp, m_sndFile.GetPlayConfig().getNormalSamplePreAmp()).GetString() : moreRecentMixModeNote; + s = displayDBValues ? CModDoc::LinearToDecibelsString(m_sndFile.m_nSamplePreAmp, m_sndFile.GetPlayConfig().getNormalSamplePreAmp()).GetString() : moreRecentMixModeNote; break; case IDC_SLIDER_VSTIVOL: if(isEnabled) - s = displayDBValues ? CModDoc::LinearToDecibels(m_sndFile.m_nVSTiVolume, m_sndFile.GetPlayConfig().getNormalVSTiVol()).GetString() : moreRecentMixModeNote; + s = displayDBValues ? CModDoc::LinearToDecibelsString(m_sndFile.m_nVSTiVolume, m_sndFile.GetPlayConfig().getNormalVSTiVol()).GetString() : moreRecentMixModeNote; else s = notAvailable; break; case IDC_SLIDER_GLOBALVOL: if(isEnabled) - s = displayDBValues ? CModDoc::LinearToDecibels(m_sndFile.m_PlayState.m_nGlobalVolume, m_sndFile.GetPlayConfig().getNormalGlobalVol()).GetString() : moreRecentMixModeNote; + s = displayDBValues ? CModDoc::LinearToDecibelsString(m_sndFile.m_PlayState.m_nGlobalVolume, m_sndFile.GetPlayConfig().getNormalGlobalVol()).GetString() : moreRecentMixModeNote; else s = notAvailable; break; Modified: trunk/OpenMPT/mptrack/Ctrl_ins.cpp ============================================================================== --- trunk/OpenMPT/mptrack/Ctrl_ins.cpp Sun Mar 23 14:26:45 2025 (r23074) +++ trunk/OpenMPT/mptrack/Ctrl_ins.cpp Sun Mar 23 15:31:18 2025 (r23075) @@ -1807,7 +1807,7 @@ case IDC_EDIT8: // Global volume if(isEnabled) - s = CModDoc::LinearToDecibels(GetDlgItemInt(IDC_EDIT8), 64.0); + s = CModDoc::LinearToDecibelsString(GetDlgItemInt(IDC_EDIT8), 64.0); else s = _T("Only available in IT / MPTM format"); break; Modified: trunk/OpenMPT/mptrack/Ctrl_smp.cpp ============================================================================== --- trunk/OpenMPT/mptrack/Ctrl_smp.cpp Sun Mar 23 14:26:45 2025 (r23074) +++ trunk/OpenMPT/mptrack/Ctrl_smp.cpp Sun Mar 23 15:31:18 2025 (r23075) @@ -533,6 +533,36 @@ } +static CString EffectiveSampleVolume(double value, double valueAtZeroDB, double effectiveFactor, const CSoundFile &sndFile) +{ + CString s = CModDoc::LinearToDecibelsString(value, valueAtZeroDB); + if(value == 0) + return s; + + const auto &playConfig = sndFile.GetPlayConfig(); + if(!playConfig.getDisplayDBValues()) + return s; + + s += _T(" (") + CModDoc::LinearToDecibelsString(value * effectiveFactor * sndFile.m_nSamplePreAmp, valueAtZeroDB * playConfig.getNormalSamplePreAmp()) + _T(" effectively)"); + return s; +} + + +static CString EffectiveOPLVolume(double value, double effectiveFactor, const CSoundFile &sndFile) +{ + const double dB = (value - 64.0) * 0.75; + const double effectiveDB = (effectiveFactor - 64.0) * 0.75; + CString s = CModDoc::DecibelsToStrings(dB); + + const auto &playConfig = sndFile.GetPlayConfig(); + if(!playConfig.getDisplayDBValues()) + return s; + + s += _T(" (") + CModDoc::DecibelsToStrings(dB + effectiveDB + CModDoc::LinearToDecibels(sndFile.m_nVSTiVolume, playConfig.getNormalVSTiVol())) + _T(" effectively)"); + return s; +} + + CString CCtrlSamples::GetToolTipText(UINT uId, HWND) const { CString s; @@ -561,10 +591,14 @@ case IDC_EDIT7: case IDC_EDIT8: // Volume to dB - if(IsOPLInstrument()) - s = mpt::cfmt::fix((static_cast<int32>(val) - 64) * 0.75, 2) + _T(" dB"); - else - s = CModDoc::LinearToDecibels(val, 64.0); + if(m_nSample) + { + const auto globalVol = m_sndFile.GetSample(m_nSample).nGlobalVol; + if(IsOPLInstrument()) + s = EffectiveOPLVolume(val, (uId == IDC_EDIT7) ? globalVol : 64.0, m_sndFile); + else + s = EffectiveSampleVolume(val, 64.0, (uId == IDC_EDIT7) ? globalVol / 64.0 : 1.0, m_sndFile); + } break; case IDC_EDIT9: Modified: trunk/OpenMPT/mptrack/Moddoc.cpp ============================================================================== --- trunk/OpenMPT/mptrack/Moddoc.cpp Sun Mar 23 14:26:45 2025 (r23074) +++ trunk/OpenMPT/mptrack/Moddoc.cpp Sun Mar 23 15:31:18 2025 (r23075) @@ -3176,12 +3176,27 @@ } -CString CModDoc::LinearToDecibels(double value, double valueAtZeroDB) + +CString CModDoc::LinearToDecibelsString(double value, double valueAtZeroDB) +{ + return DecibelsToStrings(LinearToDecibels(value, valueAtZeroDB)); +} + + +double CModDoc::LinearToDecibels(double value, double valueAtZeroDB) { - if (value == 0) return _T("-inf"); + if(value == 0 || valueAtZeroDB == 0) + return -std::numeric_limits<double>::infinity(); double changeFactor = value / valueAtZeroDB; - double dB = 20.0 * std::log10(changeFactor); + return 20.0 * std::log10(changeFactor); +} + + +CString CModDoc::DecibelsToStrings(double dB) +{ + if(std::isinf(dB)) + return dB < 0 ? _T("-inf") : _T("inf"); CString s = (dB >= 0) ? _T("+") : _T(""); s.AppendFormat(_T("%.2f dB"), dB); Modified: trunk/OpenMPT/mptrack/Moddoc.h ============================================================================== --- trunk/OpenMPT/mptrack/Moddoc.h Sun Mar 23 14:26:45 2025 (r23074) +++ trunk/OpenMPT/mptrack/Moddoc.h Sun Mar 23 15:31:18 2025 (r23075) @@ -407,8 +407,12 @@ ModCommand::NOTE GetNoteWithBaseOctave(int noteOffset, INSTRUMENTINDEX instr) const; INSTRUMENTINDEX GetParentInstrumentWithSameName(SAMPLEINDEX smp) const; + // Convert a linear volume property to decibels, and format the value as a readable string + static CString LinearToDecibelsString(double value, double valueAtZeroDB); // Convert a linear volume property to decibels - static CString LinearToDecibels(double value, double valueAtZeroDB); + static double LinearToDecibels(double value, double valueAtZeroDB); + // Format a decibel value as a readable string + static CString DecibelsToStrings(double dB); // Convert a panning value to a more readable string static CString PanningToString(int32 value, int32 valueAtCenter); Modified: trunk/OpenMPT/mptrack/PatternEditorDialogs.cpp ============================================================================== --- trunk/OpenMPT/mptrack/PatternEditorDialogs.cpp Sun Mar 23 14:26:45 2025 (r23074) +++ trunk/OpenMPT/mptrack/PatternEditorDialogs.cpp Sun Mar 23 15:31:18 2025 (r23075) @@ -1678,7 +1678,7 @@ { case IDC_EDIT1: case IDC_SLIDER1: - text = CModDoc::LinearToDecibels(m_document->GetSoundFile().ChnSettings[m_channel].nVolume, 64.0); + text = CModDoc::LinearToDecibelsString(m_document->GetSoundFile().ChnSettings[m_channel].nVolume, 64.0); break; case IDC_EDIT2: case IDC_SLIDER2: Modified: trunk/OpenMPT/mptrack/View_gen.cpp ============================================================================== --- trunk/OpenMPT/mptrack/View_gen.cpp Sun Mar 23 14:26:45 2025 (r23074) +++ trunk/OpenMPT/mptrack/View_gen.cpp Sun Mar 23 15:31:18 2025 (r23075) @@ -1805,13 +1805,13 @@ case IDC_EDIT3: case IDC_EDIT5: case IDC_EDIT7: - text = CModDoc::LinearToDecibels(chnSettings[m_nActiveTab * CHANNELS_IN_TAB + (id - IDC_EDIT1) / 2].nVolume, 64.0); + text = CModDoc::LinearToDecibelsString(chnSettings[m_nActiveTab * CHANNELS_IN_TAB + (id - IDC_EDIT1) / 2].nVolume, 64.0); break; case IDC_SLIDER1: case IDC_SLIDER3: case IDC_SLIDER5: case IDC_SLIDER7: - text = CModDoc::LinearToDecibels(chnSettings[m_nActiveTab * CHANNELS_IN_TAB + (id - IDC_SLIDER1) / 2].nVolume, 64.0); + text = CModDoc::LinearToDecibelsString(chnSettings[m_nActiveTab * CHANNELS_IN_TAB + (id - IDC_SLIDER1) / 2].nVolume, 64.0); break; case IDC_EDIT2: case IDC_EDIT4: @@ -1828,7 +1828,7 @@ case IDC_EDIT16: { const auto gain = GetDocument()->GetSoundFile().m_MixPlugins[m_nCurrentPlugin].GetGain(); - text = CModDoc::LinearToDecibels(gain ? gain : 10, 10.0); + text = CModDoc::LinearToDecibelsString(gain ? gain : 10, 10.0); } break; case IDC_BUTTON5: Modified: trunk/OpenMPT/mptrack/View_smp.cpp ============================================================================== --- trunk/OpenMPT/mptrack/View_smp.cpp Sun Mar 23 14:26:45 2025 (r23074) +++ trunk/OpenMPT/mptrack/View_smp.cpp Sun Mar 23 15:31:18 2025 (r23075) @@ -1779,7 +1779,7 @@ linear = sample.sample16()[offset] / 32768.0; else linear = sample.sample8()[offset] / 128.0; - pMainFrm->SetXInfoText(MPT_TFORMAT("Value At Cursor: {}% / {}")(mpt::tfmt::fix(linear * 100.0, 3), CModDoc::LinearToDecibels(std::abs(linear), 1.0)).c_str()); + pMainFrm->SetXInfoText(MPT_TFORMAT("Value At Cursor: {}% / {}")(mpt::tfmt::fix(linear * 100.0, 3), CModDoc::LinearToDecibelsString(std::abs(linear), 1.0)).c_str()); } else { pMainFrm->SetInfoText(_T("")); |