Skip to content

Commit

Permalink
[Ref] Turn pattern and MIDI setup flags into enum class FlagSets, and…
Browse files Browse the repository at this point in the history
… rename many flags to have more understandable names.

git-svn-id: https://source.openmpt.org/svn/openmpt/trunk/OpenMPT@22684 56274372-70c3-4bfc-bfc3-4c3a0b034d27
  • Loading branch information
sagamusix committed Jan 1, 2025
1 parent 026fb16 commit 494c073
Show file tree
Hide file tree
Showing 23 changed files with 315 additions and 277 deletions.
20 changes: 11 additions & 9 deletions mptrack/ColorConfigDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ static constexpr struct ColorDescriptions
{
const TCHAR *name;
int previewImage;
ModColor colorIndex[3];
const TCHAR *descText[3];
std::array<ModColor, 3> colorIndex;
std::array<const TCHAR *, 3> descText;
} colorDefs[] =
{
{ _T("Pattern Editor"), 0, { MODCOLOR_BACKNORMAL, MODCOLOR_TEXTNORMAL, MODCOLOR_BACKHILIGHT }, { _T("Background:"), _T("Foreground:"), _T("Highlighted:") } },
Expand Down Expand Up @@ -182,9 +182,10 @@ BOOL COptionsColors::OnInitDialog()
0, 0,
HighDPISupport::ScalePixels(PREVIEWBMP_WIDTH * 2, m_hWnd) + 2, HighDPISupport::ScalePixels(PREVIEWBMP_HEIGHT * 2, m_hWnd) + 2,
SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
if (TrackerSettings::Instance().m_dwPatternSetup & PATTERN_STDHIGHLIGHT) CheckDlgButton(IDC_CHECK1, BST_CHECKED);
if (TrackerSettings::Instance().m_dwPatternSetup & PATTERN_EFFECTHILIGHT) CheckDlgButton(IDC_CHECK2, BST_CHECKED);
if (TrackerSettings::Instance().m_dwPatternSetup & PATTERN_2NDHIGHLIGHT) CheckDlgButton(IDC_CHECK4, BST_CHECKED);
const FlagSet<PatternSetup> patternSetup = TrackerSettings::Instance().patternSetup;
if(patternSetup[PatternSetup::HighlightMeasures]) CheckDlgButton(IDC_CHECK1, BST_CHECKED);
if(patternSetup[PatternSetup::EffectHighlight]) CheckDlgButton(IDC_CHECK2, BST_CHECKED);
if(patternSetup[PatternSetup::HighlightBeats]) CheckDlgButton(IDC_CHECK4, BST_CHECKED);
CheckDlgButton(IDC_CHECK3, TrackerSettings::Instance().patternIgnoreSongTimeSignature ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(IDC_CHECK5, TrackerSettings::Instance().rememberSongWindows ? BST_CHECKED : BST_UNCHECKED);
CheckRadioButton(IDC_RADIO1, IDC_RADIO2, TrackerSettings::Instance().accidentalFlats ? IDC_RADIO2 : IDC_RADIO1);
Expand Down Expand Up @@ -269,10 +270,11 @@ void COptionsColors::OnOK()
}
}

TrackerSettings::Instance().m_dwPatternSetup &= ~(PATTERN_STDHIGHLIGHT|PATTERN_2NDHIGHLIGHT|PATTERN_EFFECTHILIGHT);
if(IsDlgButtonChecked(IDC_CHECK1)) TrackerSettings::Instance().m_dwPatternSetup |= PATTERN_STDHIGHLIGHT;
if(IsDlgButtonChecked(IDC_CHECK2)) TrackerSettings::Instance().m_dwPatternSetup |= PATTERN_EFFECTHILIGHT;
if(IsDlgButtonChecked(IDC_CHECK4)) TrackerSettings::Instance().m_dwPatternSetup |= PATTERN_2NDHIGHLIGHT;
FlagSet<PatternSetup> patternSetup = TrackerSettings::Instance().patternSetup;
patternSetup.set(PatternSetup::HighlightMeasures, IsDlgButtonChecked(IDC_CHECK1) != BST_UNCHECKED);
patternSetup.set(PatternSetup::EffectHighlight, IsDlgButtonChecked(IDC_CHECK2) != BST_UNCHECKED);
patternSetup.set(PatternSetup::HighlightBeats, IsDlgButtonChecked(IDC_CHECK4) != BST_UNCHECKED);
TrackerSettings::Instance().patternSetup = patternSetup;
TrackerSettings::Instance().patternIgnoreSongTimeSignature = IsDlgButtonChecked(IDC_CHECK3) != BST_UNCHECKED;
TrackerSettings::Instance().rememberSongWindows = IsDlgButtonChecked(IDC_CHECK5) != BST_UNCHECKED;
TrackerSettings::Instance().accidentalFlats = IsDlgButtonChecked(IDC_RADIO2) != BST_UNCHECKED;
Expand Down
8 changes: 4 additions & 4 deletions mptrack/Ctrl_pat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ BOOL CCtrlPatterns::OnInitDialog()
m_ToolBar.AddButton(ID_SEPARATOR, 0, TBSTYLE_SEP);
m_ToolBar.AddButton(ID_PATTERNDETAIL_DROPDOWN, TIMAGE_PATTERN_DETAIL, TBSTYLE_BUTTON | TBSTYLE_DROPDOWN);
m_ToolBar.AddButton(ID_SEPARATOR, 0, TBSTYLE_SEP);
m_ToolBar.AddButton(ID_OVERFLOWPASTE, TIMAGE_PATTERN_OVERFLOWPASTE, TBSTYLE_CHECK, ((TrackerSettings::Instance().m_dwPatternSetup & PATTERN_OVERFLOWPASTE) ? TBSTATE_CHECKED : 0) | TBSTATE_ENABLED);
m_ToolBar.AddButton(ID_OVERFLOWPASTE, TIMAGE_PATTERN_OVERFLOWPASTE, TBSTYLE_CHECK, ((TrackerSettings::Instance().patternSetup & PatternSetup::OverflowPaste) ? TBSTATE_CHECKED : 0) | TBSTATE_ENABLED);

m_EditPatName.SetLimitText(MAX_PATTERNNAME - 1);
// Spin controls
Expand All @@ -182,7 +182,7 @@ BOOL CCtrlPatterns::OnInitDialog()
m_SpinInstrument.SetPos(0);

SetDlgItemInt(IDC_EDIT_SPACING, TrackerSettings::Instance().gnPatternSpacing);
CheckDlgButton(IDC_PATTERN_FOLLOWSONG, (TrackerSettings::Instance().m_dwPatternSetup & PATTERN_FOLLOWSONGOFF) ? BST_UNCHECKED : BST_CHECKED);
CheckDlgButton(IDC_PATTERN_FOLLOWSONG, (TrackerSettings::Instance().patternSetup & PatternSetup::FollowSongOffByDefault) ? BST_UNCHECKED : BST_CHECKED);

m_SpinSequence.SetRange32(1, m_sndFile.Order.GetNumSequences());
m_SpinSequence.SetPos(m_sndFile.Order.GetCurrentSequenceIndex() + 1);
Expand Down Expand Up @@ -544,7 +544,7 @@ LRESULT CCtrlPatterns::OnModCtrlMsg(WPARAM wParam, LPARAM lParam)
break;

case CTRLMSG_PAT_UPDATE_TOOLBAR:
m_ToolBar.CheckButton(ID_OVERFLOWPASTE, (TrackerSettings::Instance().m_dwPatternSetup & PATTERN_OVERFLOWPASTE) ? TRUE : FALSE);
m_ToolBar.CheckButton(ID_OVERFLOWPASTE, (TrackerSettings::Instance().patternSetup & PatternSetup::OverflowPaste) ? TRUE : FALSE);
m_ToolBar.CheckButton(IDC_METRONOME, TrackerSettings::Instance().metronomeEnabled ? TRUE : FALSE);
break;

Expand Down Expand Up @@ -1105,7 +1105,7 @@ void CCtrlPatterns::OnPatternViewPlugNames()

void CCtrlPatterns::OnToggleOverflowPaste()
{
TrackerSettings::Instance().m_dwPatternSetup ^= PATTERN_OVERFLOWPASTE;
TrackerSettings::Instance().patternSetup ^= PatternSetup::OverflowPaste;
theApp.PostMessageToAllViews(WM_MOD_CTRLMSG, CTRLMSG_PAT_UPDATE_TOOLBAR);
SwitchToView();
}
Expand Down
2 changes: 1 addition & 1 deletion mptrack/Ctrl_seq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ void COrderList::UpdateInfoText()

const ORDERINDEX length = order.GetLengthTailTrimmed();
CString s;
if(TrackerSettings::Instance().m_dwPatternSetup & PATTERN_HEXDISPLAY)
if(TrackerSettings::Instance().patternSetup & PatternSetup::RowAndOrderNumbersHex)
s.Format(_T("Position %02Xh of %02Xh"), m_nScrollPos, length);
else
s.Format(_T("Position %u of %u (%02Xh of %02Xh)"), m_nScrollPos, length, m_nScrollPos, length);
Expand Down
36 changes: 18 additions & 18 deletions mptrack/Draw_pat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ UINT CViewPattern::GetColumnOffset(PatternCursor::Columns column) const

int CViewPattern::GetSmoothScrollOffset() const
{
if((TrackerSettings::Instance().m_dwPatternSetup & PATTERN_SMOOTHSCROLL) != 0 // Actually using the smooth scroll feature
if((TrackerSettings::Instance().patternSetup & PatternSetup::SmoothScrolling) // Actually using the smooth scroll feature
&& (m_Status & (psFollowSong | psDragActive)) == psFollowSong // Not drawing a selection during playback
&& (m_nMidRow != 0 || GetYScrollPos() > 0) // If active row is not centered, only scroll when display position is actually not at the top
&& IsLiveRecord() // Actually playing live (not paused or stepping)
Expand Down Expand Up @@ -544,7 +544,7 @@ void CViewPattern::OnDraw(CDC *pDC)
const int chanColorHeight = MulDiv(4, m_dpi, 96);
const int chanColorOffset = MulDiv(2, m_dpi, 96);
const int recordInsX = MulDiv(3, m_dpi, 96);
const bool doSmoothScroll = (TrackerSettings::Instance().m_dwPatternSetup & PATTERN_SMOOTHSCROLL) != 0;
const bool doSmoothScroll = (TrackerSettings::Instance().patternSetup & PatternSetup::SmoothScrolling);

GetClientRect(&rcClient);

Expand Down Expand Up @@ -593,7 +593,7 @@ void CViewPattern::OnDraw(CDC *pDC)
PATTERNINDEX nPrevPat = PATTERNINDEX_INVALID;

// Display previous pattern
if (TrackerSettings::Instance().m_dwPatternSetup & PATTERN_SHOWPREVIOUS)
if(TrackerSettings::Instance().patternSetup & PatternSetup::ShowPrevNextPattern)
{
if(m_nOrder > 0 && m_nOrder < ordCount)
{
Expand Down Expand Up @@ -640,7 +640,7 @@ void CViewPattern::OnDraw(CDC *pDC)
DrawPatternData(hdc, m_nPattern, true, (pMainFrm->GetModPlaying() == pModDoc),
yofs, nrows, xofs, rcClient, &ypaint);
// Display next pattern
if ((TrackerSettings::Instance().m_dwPatternSetup & PATTERN_SHOWPREVIOUS) && (ypaint < rcClient.bottom) && (ypaint == ypatternend))
if((TrackerSettings::Instance().patternSetup & PatternSetup::ShowPrevNextPattern) && (ypaint < rcClient.bottom) && (ypaint == ypatternend))
{
int nVisRows = (rcClient.bottom - ypaint + m_szCell.cy - 1) / m_szCell.cy;
if(nVisRows > 0)
Expand Down Expand Up @@ -829,7 +829,7 @@ void CViewPattern::DrawPatternData(HDC hdc, PATTERNINDEX nPattern, bool selEnabl
if(!sndFile.Patterns.IsValidPat(nPattern))
return;
const CPattern &pattern = sndFile.Patterns[nPattern];
const auto patternSetupFlags = TrackerSettings::Instance().m_dwPatternSetup.Get();
const FlagSet<PatternSetup> patternSetupFlags = TrackerSettings::Instance().patternSetup;
const bool volumeColumnIsHex = TrackerSettings::Instance().patternVolColHex;

const PATTERNFONT *pfnt = PatternFont::currentFont;
Expand Down Expand Up @@ -887,7 +887,7 @@ void CViewPattern::DrawPatternData(HDC hdc, PATTERNINDEX nPattern, bool selEnabl
nMeasure = sndFile.Patterns[nPattern].GetRowsPerMeasure();
}

const bool hexNumbers = (patternSetupFlags & PATTERN_HEXDISPLAY);
const bool hexNumbers = patternSetupFlags[PatternSetup::RowAndOrderNumbersHex];
bool bRowSel = false;
int row_col = -1, row_bkcol = -1;
for(ROWINDEX row = startRow; row < numRows; row++)
Expand Down Expand Up @@ -929,17 +929,15 @@ void CViewPattern::DrawPatternData(HDC hdc, PATTERNINDEX nPattern, bool selEnabl
ROWINDEX highlightRow = compRow;
if(nMeasure > 0)
highlightRow %= nMeasure;
if ((patternSetupFlags & PATTERN_2NDHIGHLIGHT)
&& nBeat > 0)
if(patternSetupFlags[PatternSetup::HighlightBeats] && nBeat > 0)
{
if((highlightRow % nBeat) == 0)
{
row_bkcol = MODCOLOR_2NDHIGHLIGHT;
}
}
// primary highlight (measures)
if((patternSetupFlags & PATTERN_STDHIGHLIGHT)
&& nMeasure > 0)
if(patternSetupFlags[PatternSetup::HighlightMeasures] && nMeasure > 0)
{
if(highlightRow == 0)
{
Expand Down Expand Up @@ -989,13 +987,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 auto defaultVolume = (patternSetupFlags & PATTERN_SHOWDEFAULTVOLUME) ? DrawDefaultVolume(*m) : std::nullopt;
const auto defaultVolume = patternSetupFlags[PatternSetup::ShowDefaultVolume] ? DrawDefaultVolume(*m) : std::nullopt;

DWORD dwSpeedUpMask = 0;
if(useSpeedUpMask && (m_chnState[col].selectedCols & COLUMN_BITS_SKIP) && (row))
{
const ModCommand *mold = m - ncols;
const auto oldDefaultVolume = (patternSetupFlags & PATTERN_SHOWDEFAULTVOLUME) ? DrawDefaultVolume(*mold) : std::nullopt;
const auto oldDefaultVolume = patternSetupFlags[PatternSetup::ShowDefaultVolume] ? DrawDefaultVolume(*mold) : std::nullopt;

if(m->note == mold->note || !m_visibleColumns[PatternCursor::noteColumn])
dwSpeedUpMask |= COLUMN_BITS_NOTE;
Expand Down Expand Up @@ -1043,7 +1041,7 @@ void CViewPattern::DrawPatternData(HDC hdc, PATTERNINDEX nPattern, bool selEnabl
{
tx_col = row_col;
bk_col = row_bkcol;
if((patternSetupFlags & PATTERN_EFFECTHILIGHT) && m->IsNote())
if(patternSetupFlags[PatternSetup::EffectHighlight] && m->IsNote())
{
tx_col = MODCOLOR_NOTE;

Expand Down Expand Up @@ -1084,7 +1082,7 @@ void CViewPattern::DrawPatternData(HDC hdc, PATTERNINDEX nPattern, bool selEnabl
{
tx_col = row_col;
bk_col = row_bkcol;
if ((patternSetupFlags & PATTERN_EFFECTHILIGHT) && (m->instr))
if(patternSetupFlags[PatternSetup::EffectHighlight] && (m->instr))
{
tx_col = MODCOLOR_INSTRUMENT;
}
Expand All @@ -1111,7 +1109,7 @@ void CViewPattern::DrawPatternData(HDC hdc, PATTERNINDEX nPattern, bool selEnabl
{
tx_col = MODCOLOR_TEXTSELECTED;
bk_col = MODCOLOR_BACKSELECTED;
} else if (!m->IsPcNote() && (patternSetupFlags & PATTERN_EFFECTHILIGHT))
} else if (!m->IsPcNote() && patternSetupFlags[PatternSetup::EffectHighlight])
{
auto fxColor = effectColors[static_cast<size_t>(m->GetVolumeEffectType())];
if(m->volcmd != VOLCMD_NONE && m->volcmd < MAX_VOLCMDS && fxColor != 0)
Expand All @@ -1136,7 +1134,7 @@ void CViewPattern::DrawPatternData(HDC hdc, PATTERNINDEX nPattern, bool selEnabl
uint16 val = m->GetValueEffectCol();
if(val > ModCommand::maxColumnValue) val = ModCommand::maxColumnValue;
fx_col = row_col;
if (!isPCnote && m->command != CMD_NONE && m->command < MAX_EFFECTS && (patternSetupFlags & PATTERN_EFFECTHILIGHT))
if (!isPCnote && m->command != CMD_NONE && m->command < MAX_EFFECTS && patternSetupFlags[PatternSetup::EffectHighlight])
{
if(auto fxColor = effectColors[static_cast<size_t>(m->GetEffectType())]; fxColor != 0)
fx_col = fxColor;
Expand Down Expand Up @@ -1401,8 +1399,10 @@ void CViewPattern::UpdateScrollSize()
sizePage.cy = sizeLine.cy * 8;
GetClientRect(&rect);
m_nMidRow = 0;
if (TrackerSettings::Instance().m_dwPatternSetup & PATTERN_CENTERROW) m_nMidRow = (rect.Height() - m_szHeader.cy) / (m_szCell.cy * 2);
if (m_nMidRow) sizeTotal.cy += m_nMidRow * m_szCell.cy * 2;
if(TrackerSettings::Instance().patternSetup & PatternSetup::CenterActiveRow)
m_nMidRow = (rect.Height() - m_szHeader.cy) / (m_szCell.cy * 2);
if(m_nMidRow)
sizeTotal.cy += m_nMidRow * m_szCell.cy * 2;
SetScrollSizes(MM_TEXT, sizeTotal, sizePage, sizeLine);
m_bWholePatternFitsOnScreen = (rect.Height() >= sizeTotal.cy);
if(m_bWholePatternFitsOnScreen)
Expand Down
Loading

0 comments on commit 494c073

Please sign in to comment.