Skip to content

Commit

Permalink
[Fix] Pattern tab: Drawing of default volume for instrument plugins w…
Browse files Browse the repository at this point in the history
…as broken since r22138.

git-svn-id: https://source.openmpt.org/svn/openmpt/trunk/OpenMPT@22300 56274372-70c3-4bfc-bfc3-4c3a0b034d27
  • Loading branch information
sagamusix committed Nov 24, 2024
1 parent ec0bf7c commit 57caf8d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 40 deletions.
35 changes: 11 additions & 24 deletions mptrack/Draw_pat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ void CViewPattern::DrawInstrument(int x, int y, UINT instr)
}


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;

Expand All @@ -497,11 +497,11 @@ void CViewPattern::DrawVolumeCommand(int x, int y, const ModCommand &mc, bool dr
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)
Expand Down Expand Up @@ -989,13 +989,13 @@ void CViewPattern::DrawPatternData(HDC hdc, PATTERNINDEX nPattern, bool selEnabl
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;
Expand All @@ -1013,7 +1013,7 @@ void CViewPattern::DrawPatternData(HDC hdc, PATTERNINDEX nPattern, bool selEnabl
}
} 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;
Expand Down Expand Up @@ -1117,14 +1117,14 @@ void CViewPattern::DrawPatternData(HDC hdc, PATTERNINDEX nPattern, bool selEnabl
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];
}
Expand Down Expand Up @@ -1222,24 +1222,11 @@ void CViewPattern::DrawPatternData(HDC hdc, PATTERNINDEX nPattern, bool selEnabl
}


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);
}


Expand Down
37 changes: 25 additions & 12 deletions mptrack/View_pat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2606,13 +2606,13 @@ void CViewPattern::Interpolate(PatternCursor::Columns type)
{
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;
}
Expand Down Expand Up @@ -2994,7 +2994,7 @@ bool CViewPattern::DataEntry(bool up, bool coarse)
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;
Expand Down Expand Up @@ -3041,16 +3041,29 @@ bool CViewPattern::DataEntry(bool up, bool coarse)


// 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;
}


Expand Down Expand Up @@ -3521,7 +3534,7 @@ void CViewPattern::OnPatternAmplify()
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);
Expand All @@ -3540,7 +3553,7 @@ void CViewPattern::OnPatternAmplify()
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))
{
Expand Down
8 changes: 4 additions & 4 deletions mptrack/View_pat.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,13 +295,13 @@ class CViewPattern final : public CModScrollView
#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);

Expand All @@ -317,7 +317,7 @@ class CViewPattern final : public CModScrollView
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;

Expand Down

0 comments on commit 57caf8d

Please sign in to comment.