From: <sv...@op...> - 2024-11-24 23:00:54
|
Author: sagamusix Date: Mon Nov 25 00:00:42 2024 New Revision: 22300 URL: https://source.openmpt.org/browse/openmpt/?op=revision&rev=22300 Log: [Fix] Pattern tab: Drawing of default volume for instrument plugins was broken since r22138. Modified: trunk/OpenMPT/mptrack/Draw_pat.cpp trunk/OpenMPT/mptrack/View_pat.cpp trunk/OpenMPT/mptrack/View_pat.h Modified: trunk/OpenMPT/mptrack/Draw_pat.cpp ============================================================================== --- trunk/OpenMPT/mptrack/Draw_pat.cpp Sun Nov 24 23:29:16 2024 (r22299) +++ trunk/OpenMPT/mptrack/Draw_pat.cpp Mon Nov 25 00:00:42 2024 (r22300) @@ -476,7 +476,7 @@ } -void CViewPattern::DrawVolumeCommand(int x, int y, const ModCommand &mc, bool drawDefaultVolume, bool hex) +void CViewPattern::DrawVolumeCommand(int x, int y, const ModCommand &mc, std::optional<int> defaultVolume, bool hex) { const PATTERNFONT *pfnt = PatternFont::currentFont; @@ -497,11 +497,11 @@ ModCommand::VOLCMD volcmd = mc.volcmd; int vol = (mc.vol & 0x7F); - if(drawDefaultVolume) + if(defaultVolume) { // Displaying sample default volume if there is no volume command. volcmd = VOLCMD_VOLUME; - vol = GetDefaultVolume(mc); + vol = *defaultVolume; } if(volcmd != VOLCMD_NONE && volcmd < MAX_VOLCMDS) @@ -989,13 +989,13 @@ const ModCommand *m = pattern.GetpModCommand(row, static_cast<CHANNELINDEX>(col)); // Should empty volume commands be replaced with a volume command showing the default volume? - const bool drawDefaultVolume = (patternSetupFlags & PATTERN_SHOWDEFAULTVOLUME) && DrawDefaultVolume(*m, sndFile); + const auto defaultVolume = (patternSetupFlags & PATTERN_SHOWDEFAULTVOLUME) ? DrawDefaultVolume(*m) : std::nullopt; DWORD dwSpeedUpMask = 0; if(useSpeedUpMask && (m_chnState[col].selectedCols & COLUMN_BITS_SKIP) && (row)) { const ModCommand *mold = m - ncols; - const bool drawOldDefaultVolume = (patternSetupFlags & PATTERN_SHOWDEFAULTVOLUME) && DrawDefaultVolume(*mold, sndFile); + const auto oldDefaultVolume = (patternSetupFlags & PATTERN_SHOWDEFAULTVOLUME) ? DrawDefaultVolume(*mold) : std::nullopt; if(m->note == mold->note || !m_visibleColumns[PatternCursor::noteColumn]) dwSpeedUpMask |= COLUMN_BITS_NOTE; @@ -1013,7 +1013,7 @@ } } else { - if ((m->volcmd == mold->volcmd && (m->volcmd == VOLCMD_NONE || m->vol == mold->vol) && !drawDefaultVolume && !drawOldDefaultVolume) || !m_visibleColumns[PatternCursor::volumeColumn]) + if ((m->volcmd == mold->volcmd && (m->volcmd == VOLCMD_NONE || m->vol == mold->vol) && !defaultVolume && !oldDefaultVolume) || !m_visibleColumns[PatternCursor::volumeColumn]) dwSpeedUpMask |= COLUMN_BITS_VOLUME; if ((m->command == mold->command) || !m_visibleColumns[PatternCursor::effectColumn]) dwSpeedUpMask |= (m->command != CMD_NONE) ? COLUMN_BITS_FXCMD : COLUMN_BITS_FXCMDANDPARAM; @@ -1117,14 +1117,14 @@ if(m->volcmd != VOLCMD_NONE && m->volcmd < MAX_VOLCMDS && fxColor != 0) { tx_col = fxColor; - } else if(drawDefaultVolume) + } else if(defaultVolume) { tx_col = MODCOLOR_DEFAULTVOLUME; } } // Drawing Volume m_Dib.SetTextColor(tx_col, bk_col); - DrawVolumeCommand(xbmp + x, 0, *m, drawDefaultVolume, volumeColumnIsHex); + DrawVolumeCommand(xbmp + x, 0, *m, defaultVolume, volumeColumnIsHex); } x += pfnt->nEltWidths[2]; } @@ -1222,24 +1222,11 @@ } -bool CViewPattern::DrawDefaultVolume(const ModCommand &m, const CSoundFile &sndFile) +std::optional<int> CViewPattern::DrawDefaultVolume(const ModCommand &m) const { if(m.instr == 0 || m.volcmd != VOLCMD_NONE || m.command == CMD_VOLUME || m.command == CMD_VOLUME8) - return false; - // In instrument mode, we'd need to know the played for note-less instrument numbers - const bool hasNote = m.IsNote(); - if(sndFile.GetNumInstruments() && !hasNote) - return false; - const SAMPLEINDEX smp = sndFile.GetSampleIndex(m.note, m.instr); - if(smp != 0) - { - const ModSample &sample = sndFile.GetSample(smp); - if(sample.uFlags[SMP_NODEFAULTVOLUME]) - return false; - if(sndFile.GetType() == MOD_TYPE_S3M && !sample.HasSampleData()) - return false; - } - return smp != 0; + return std::nullopt; + return GetDefaultVolume(m, 0); } Modified: trunk/OpenMPT/mptrack/View_pat.cpp ============================================================================== --- trunk/OpenMPT/mptrack/View_pat.cpp Sun Nov 24 23:29:16 2024 (r22299) +++ trunk/OpenMPT/mptrack/View_pat.cpp Mon Nov 25 00:00:42 2024 (r22300) @@ -2606,13 +2606,13 @@ { vcmd = destCmd.volcmd; if(vcmd == VOLCMD_VOLUME && srcCmd.IsNote() && srcCmd.instr) - vsrc = GetDefaultVolume(srcCmd); + vsrc = GetDefaultVolume(srcCmd).value_or(64); else vsrc = vdest; } else if(destCmd.volcmd == VOLCMD_NONE) { if(vcmd == VOLCMD_VOLUME && destCmd.IsNote() && destCmd.instr) - vdest = GetDefaultVolume(srcCmd); + vdest = GetDefaultVolume(srcCmd).value_or(64); else vdest = vsrc; } @@ -2994,7 +2994,7 @@ if(m.volcmd == VOLCMD_NONE && m.IsNote() && m.instr && modSpecs.HasVolCommand(VOLCMD_VOLUME)) { m.volcmd = VOLCMD_VOLUME; - m.vol = static_cast<ModCommand::VOL>(GetDefaultVolume(m)); + m.vol = static_cast<ModCommand::VOL>(GetDefaultVolume(m).value_or(64)); } int vol = m.vol + offset * (coarse ? 10 : 1); ModCommand::VOL minValue = 0, maxValue = 64; @@ -3041,16 +3041,29 @@ // Get the velocity at which a given note would be played -int CViewPattern::GetDefaultVolume(const ModCommand &m, ModCommand::INSTR lastInstr) const +std::optional<int> CViewPattern::GetDefaultVolume(const ModCommand &m, ModCommand::INSTR lastInstr) const { const CSoundFile &sndFile = *GetSoundFile(); - SAMPLEINDEX sample = GetDocument()->GetSampleIndex(m, lastInstr); - if(sample) - return std::min(sndFile.GetSample(sample).nVolume, uint16(256)) / 4u; - else if(m.instr > 0 && m.instr <= sndFile.GetNumInstruments() && sndFile.Instruments[m.instr] != nullptr && sndFile.Instruments[m.instr]->HasValidMIDIChannel()) + // In instrument mode, we'd need to know the last played note for note-less instrument numbers + const bool hasNote = m.IsNote(); + if(sndFile.GetNumInstruments() && !hasNote) + return std::nullopt; + + SAMPLEINDEX smp = GetDocument()->GetSampleIndex(m, lastInstr); + if(smp != 0) + { + const ModSample &sample = sndFile.GetSample(smp); + if(sample.uFlags[SMP_NODEFAULTVOLUME]) + return std::nullopt; + if(sndFile.GetType() == MOD_TYPE_S3M && !sample.HasSampleData()) + return std::nullopt; + else + return std::min(sample.nVolume, uint16(256)) / 4u; + } else if(m.instr > 0 && m.instr <= sndFile.GetNumInstruments() && sndFile.Instruments[m.instr] != nullptr && sndFile.Instruments[m.instr]->HasValidMIDIChannel()) + { return std::min(sndFile.Instruments[m.instr]->nGlobalVol, uint32(64)); // For instrument plugins - else - return 64; + } + return std::nullopt; } @@ -3521,7 +3534,7 @@ else if(m.volcmd == VOLCMD_VOLUME) chvol[chn] = m.vol; else if(m.instr != 0) - chvol[chn] = static_cast<ModCommand::VOL>(GetDefaultVolume(m)); + chvol[chn] = static_cast<ModCommand::VOL>(GetDefaultVolume(m).value_or(64)); }); Fade::Func fadeFunc = GetFadeFunc(settings.fadeLaw); @@ -3540,7 +3553,7 @@ else if(m.volcmd == VOLCMD_VOLUME) chvol[chn] = m.vol; else if(m.instr != 0) - chvol[chn] = static_cast<ModCommand::VOL>(GetDefaultVolume(m)); + chvol[chn] = static_cast<ModCommand::VOL>(GetDefaultVolume(m).value_or(64)); if(settings.fadeIn || settings.fadeOut || (m.IsNote() && m.instr != 0)) { Modified: trunk/OpenMPT/mptrack/View_pat.h ============================================================================== --- trunk/OpenMPT/mptrack/View_pat.h Sun Nov 24 23:29:16 2024 (r22299) +++ trunk/OpenMPT/mptrack/View_pat.h Mon Nov 25 00:00:42 2024 (r22300) @@ -295,13 +295,13 @@ #endif void DrawNote(int x, int y, UINT note, CTuning *pTuning = nullptr); void DrawInstrument(int x, int y, UINT instr); - void DrawVolumeCommand(int x, int y, const ModCommand &mc, bool drawDefaultVolume, bool hex); + void DrawVolumeCommand(int x, int y, const ModCommand &mc, std::optional<int> defaultVolume, bool hex); void DrawChannelVUMeter(HDC hdc, int x, int y, UINT nChn); void UpdateAllVUMeters(Notification *pnotify); void DrawDragSel(HDC hdc); void OnDrawDragSel(); - // True if default volume should be drawn for a given cell. - static bool DrawDefaultVolume(const ModCommand &m, const CSoundFile &sndFile); + // Returns result of GetDefaultVolume if default volume should be drawn, std::nullopt otherwise + std::optional<int> DrawDefaultVolume(const ModCommand &m) const; void CursorJump(int distance, bool snap); @@ -317,7 +317,7 @@ void TempEnterFXparam(int v); void EnterAftertouch(ModCommand::NOTE note, int atValue); - int GetDefaultVolume(const ModCommand &m, ModCommand::INSTR lastInstr = 0) const; + std::optional<int> GetDefaultVolume(const ModCommand &m, ModCommand::INSTR lastInstr = 0) const; int GetBaseNote() const; ModCommand::NOTE GetNoteWithBaseOctave(int note) const; |