Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 583d070

Browse files
committedFeb 7, 2025··
Reduce magic number palette constants in regview
- Set OETF gamma function as lambda - Refactor precise pitch selection - Add tone tint for S5B notes
1 parent 4493431 commit 583d070

File tree

1 file changed

+65
-49
lines changed

1 file changed

+65
-49
lines changed
 

‎Source/PatternEditor.cpp

Lines changed: 65 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1810,11 +1810,6 @@ static CString NoteToStr(int Note)
18101810
return str;
18111811
}
18121812

1813-
static const COLORREF DECAY_COLOR[CRegisterState::DECAY_RATE + 1] = { // // //
1814-
0xFFFF80, 0xE6F993, 0xCCF3A6, 0xB3ECB9, 0x99E6CC, 0x80E0E0, 0x80D9E3, 0x80D3E6,
1815-
0x80CCE9, 0x80C6EC, 0x80C0F0, 0x80B9F3, 0x80B3F6, 0x80ACF9, 0x80A6FC, 0x80A0FF,
1816-
}; // BLEND has lower precision
1817-
18181813
void CPatternEditor::DrawRegisters(CDC *pDC)
18191814
{
18201815
if (!m_pDocument || !pDC) return; // // //
@@ -1848,34 +1843,58 @@ void CPatternEditor::DrawRegisters(CDC *pDC)
18481843
m_pDocument->ExpansionEnabled(SNDCHIP_S5B) * 8); // // //
18491844
int vis_line = 0;
18501845

1846+
// TODO: custom regview palettes
1847+
1848+
static const COLORREF DECAY_COLOR[CRegisterState::DECAY_RATE + 1] = { // // //
1849+
0xFFFF80, 0xE6F993, 0xCCF3A6, 0xB3ECB9, 0x99E6CC, 0x80E0E0, 0x80D9E3, 0x80D3E6,
1850+
0x80CCE9, 0x80C6EC, 0x80C0F0, 0x80B9F3, 0x80B3F6, 0x80ACF9, 0x80A6FC, 0x80A0FF,
1851+
}; // BLEND has lower precision
1852+
1853+
// !! !!
1854+
static const COLORREF UPDATE_STALE_COLOR = 0xC0C0C0;
1855+
static const COLORREF UPDATE_FRESH_COLOR = 0xFFAFAF;
1856+
static const COLORREF BORDER_COLOR = 0x808080;
1857+
static const COLORREF SUBBORDER_COLOR = 0x303030;
1858+
1859+
// Note color tints
1860+
static const float CTINT_FDS_MOD[3] = { 1, 0, 0 };
1861+
static const float CTINT_FDS[3] = { 0, 1, 1 };
1862+
static const float CTINT_PNOISE[3] = { 0.587f, 0.676f, 1.0f };
1863+
static const float CTINT_S5B_T[3] = { 0, 1, 1 };
1864+
static const float CTINT_S5B_N[3] = { 1, 0, 1 };
1865+
static const float CTINT_S5B_E[3] = { 1, 1, 0 };
1866+
1867+
bool PrecisePitch = theApp.GetSettings()->GUI.bPreciseRegPitch;
1868+
18511869
const auto DrawHeaderFunc = [&] (CString Text) {
18521870
line += 2; y += LINE_HEIGHT * 2;
18531871
pDC->MoveTo(x, y);
18541872
pDC->SetBkColor(m_colEmptyBg);
1855-
pDC->SetTextColor(0xFFAFAF);
1873+
pDC->SetTextColor(UPDATE_FRESH_COLOR);
18561874
pDC->TextOut(x, y, Text + _T(" registers"));
18571875
};
18581876

18591877
const auto DrawRegFunc = [&] (CString Header, int Count) {
18601878
++line; y += LINE_HEIGHT;
18611879
pDC->SetBkColor(m_colEmptyBg);
1862-
pDC->SetTextColor(0xFFAFAF);
1880+
pDC->SetTextColor(UPDATE_FRESH_COLOR);
18631881
pDC->SetTextAlign(TA_UPDATECP);
18641882
pDC->MoveTo(x, y);
18651883
pDC->TextOut(0, 0, Header);
18661884
for (int j = 0; j < Count; j++) {
18671885
CString str;
18681886
str.Format(_T(" $%02X"), reg[j]);
1869-
pDC->SetTextColor(BLEND(0xC0C0C0, DECAY_COLOR[update[j] >> 4], 100 * (update[j] & 0x0F) / CRegisterState::DECAY_RATE));
1887+
pDC->SetTextColor(BLEND(UPDATE_STALE_COLOR, DECAY_COLOR[update[j] >> 4], 100 * (update[j] & 0x0F) / CRegisterState::DECAY_RATE));
18701888
pDC->TextOut(0, 0, str);
18711889
}
18721890
};
18731891

18741892
const auto DrawVolBar = [&]() {
1875-
pDC->FillSolidRect(x - 1, BAR_OFFSET + vis_line * 10 - 1, 6 * 108 + 3, 9, 0x808080);
1893+
pDC->FillSolidRect(x - 1, BAR_OFFSET + vis_line * 10 - 1, 6 * 108 + 3, 9, BORDER_COLOR);
18761894
pDC->FillSolidRect(x, BAR_OFFSET + vis_line * 10, 6 * 108 + 1, 7, 0);
1895+
// C note indicators
18771896
for (int i = 0; i < 10; i++)
1878-
pDC->SetPixelV(x + 72 * i, BAR_OFFSET + vis_line * 10 + 3, i == 4 ? 0x808080 : 0x303030);
1897+
pDC->SetPixelV(x + 72 * i, BAR_OFFSET + vis_line * 10 + 3, i == 4 ? BORDER_COLOR : SUBBORDER_COLOR);
18791898
};
18801899

18811900
const auto DrawVolNote = [&](const double note, BYTE Volume, float r = 1.f, float g = 1.f, float b = 1.f) {
@@ -1887,6 +1906,11 @@ void CPatternEditor::DrawRegisters(CDC *pDC)
18871906
);
18881907
};
18891908

1909+
// // !! apply OETF gamma 2.2 so we can see lower values better
1910+
const auto OETF_gamma_vol = [&](const double Volume) -> BYTE {
1911+
return BYTE(max(min(pow(Volume, (1 / 2.2)), 1.0), 0.0) * 255);
1912+
};
1913+
18901914
const auto DrawVolFunc = [&] (double Freq, double Volume, int Range=0, int Period=0, bool IsLength = true, float r=1.f, float g=1.f, float b=1.f) {
18911915
DrawVolBar();
18921916
double note = 0;
@@ -1896,13 +1920,9 @@ void CPatternEditor::DrawRegisters(CDC *pDC)
18961920
note = NoteFromFreq(Freq);
18971921
const int note_conv = note >= 0 ? int(note + 0.5) : int(note - 0.5);
18981922

1899-
// // !! apply OETF gamma 2.2 so we can see lower values better
1900-
BYTE vol_scaled = BYTE(max(min(pow(Volume, (1 / 2.2)), 1.0), 0.0) * 255);
1923+
BYTE vol_scaled = OETF_gamma_vol(Volume);
19011924
if (note_conv >= -12 && note_conv <= 96 && vol_scaled) { // // //
1902-
if (theApp.GetSettings()->GUI.bPreciseRegPitch || Range != 0)
1903-
DrawVolNote(note, vol_scaled, r, g, b);
1904-
else
1905-
DrawVolNote(note_conv, vol_scaled, r, g, b);
1925+
DrawVolNote((PrecisePitch || Range != 0) ? note : note_conv, vol_scaled, r, g, b);
19061926
}
19071927
++vis_line;
19081928
};
@@ -1915,29 +1935,22 @@ void CPatternEditor::DrawRegisters(CDC *pDC)
19151935
const double outnote = NoteFromFreq(OutFreq);
19161936
const int outnote_conv = outnote >= 0 ? int(outnote + 0.5) : int(outnote - 0.5);
19171937

1918-
// // !! apply OETF gamma 2.2 so we can see lower values better
1919-
BYTE vol_scaled = BYTE(max(min(pow(Volume, (1 / 2.2)), 1.0), 0.0) * 255);
1938+
BYTE vol_scaled = OETF_gamma_vol(Volume);
19201939

19211940
// TODO: do something with Depth
19221941
//if (Depth > 0xFF) Depth = 0xFF;
19231942

19241943
if (note_conv >= -12 && note_conv <= 96 && vol_scaled) { // // //
1925-
if (Depth!=0)
1944+
if (Depth != 0) {
19261945
// modulated note
1927-
if (theApp.GetSettings()->GUI.bPreciseRegPitch) {
1928-
DrawVolNote(outnote, vol_scaled, 1, 0, 0);
1929-
DrawVolNote(note, vol_scaled, 0, 1, 1);
1930-
}
1931-
else {
1932-
DrawVolNote(outnote_conv, vol_scaled, 1, 0, 0);
1933-
DrawVolNote(note_conv, vol_scaled, 0, 1, 1);
1934-
}
1946+
DrawVolNote(PrecisePitch ? outnote : outnote_conv, vol_scaled,
1947+
CTINT_FDS_MOD[0], CTINT_FDS_MOD[1], CTINT_FDS_MOD[2]);
1948+
DrawVolNote(PrecisePitch ? note : note_conv, vol_scaled,
1949+
CTINT_FDS[0], CTINT_FDS[1], CTINT_FDS[2]);
1950+
}
19351951
else
19361952
// unmodulated note
1937-
if (theApp.GetSettings()->GUI.bPreciseRegPitch)
1938-
DrawVolNote(note, vol_scaled);
1939-
else
1940-
DrawVolNote(note_conv, vol_scaled);
1953+
DrawVolNote(PrecisePitch ? note : note_conv, vol_scaled);
19411954
}
19421955
++vis_line;
19431956
};
@@ -1948,32 +1961,34 @@ void CPatternEditor::DrawRegisters(CDC *pDC)
19481961

19491962
// 3db per step
19501963
const double vol = envelope_enable ? 1 : (std::pow(10.0, (((Volume + 1.0) * 3.0) / 20.0)) / 251.18864315095801110850320677993);
1951-
// // !! apply OETF gamma 2.2 so we can see lower values better
1952-
const BYTE vol_scaled = BYTE(max(min(pow(vol, (1 / 2.2)), 1.0), 0.0) * 255);
1964+
1965+
const BYTE vol_scaled = OETF_gamma_vol(Volume);
19531966

19541967
const double note = NoteFromFreq(Freq);
19551968
const double note_envelope = NoteFromFreq(EnvelopeFreq);
19561969
const double note_noise = ((108.0 / double(0x1F)) * double(0x1F - NoisePeriod)) - 12.0;
19571970
const int note_conv = note >= 0 ? int(note + 0.5) : int(note - 0.5);
19581971

19591972

1960-
if (note_conv >= -12 && note_conv <= 96 && (vol_scaled || envelope_enable)) { // // //
1961-
if (theApp.GetSettings()->GUI.bPreciseRegPitch) {
1962-
DrawVolNote(note, vol_scaled);
1963-
}
1964-
else {
1965-
DrawVolNote(note_conv, vol_scaled);
1966-
}
1967-
}
1973+
if (note_conv >= -12 && note_conv <= 96 && (vol_scaled || envelope_enable)) // // //
1974+
if (noise_enable || envelope_enable)
1975+
DrawVolNote(PrecisePitch ? note : note_conv, vol_scaled, // !! !!
1976+
CTINT_S5B_T[0], CTINT_S5B_T[1], CTINT_S5B_T[2]);
1977+
else
1978+
DrawVolNote(PrecisePitch ? note : note_conv, vol_scaled);
1979+
19681980
if (note_noise >= -12.0 && note_noise <= 96.0 && noise_enable)
1969-
DrawVolNote(note_noise, vol_scaled, 1, 0, 1);
1981+
DrawVolNote(note_noise, vol_scaled,
1982+
CTINT_S5B_N[0], CTINT_S5B_N[1], CTINT_S5B_N[2]);
1983+
19701984
if (note_envelope >= -12.0 && note_envelope <= 96.0 && envelope_enable)
1971-
DrawVolNote(note_envelope, vol_scaled, 1, 1, 0);
1985+
DrawVolNote(note_envelope, vol_scaled,
1986+
CTINT_S5B_E[0], CTINT_S5B_E[1], CTINT_S5B_E[2]);
19721987
++vis_line;
19731988
};
19741989

19751990
const auto DrawTextFunc = [&] (int xOffsNoDPI, CString text) {
1976-
pDC->SetTextColor(0x808080);
1991+
pDC->SetTextColor(BORDER_COLOR);
19771992
pDC->SetTextAlign(TA_NOUPDATECP);
19781993
pDC->TextOut(x + DPI::SX(xOffsNoDPI), y, text);
19791994
};
@@ -2070,7 +2085,8 @@ void CPatternEditor::DrawRegisters(CDC *pDC)
20702085
DrawVolFunc(freq, (double)vol/ (double)0xF); break;
20712086
case 3:
20722087
if (reg[2] >> 7 == 1)
2073-
DrawVolFunc(freq, (double)vol/(double)0x0F, 0, 0, false, 0, 0.5, 1);
2088+
DrawVolFunc(freq, (double)vol/(double)0x0F, 0, 0, false,
2089+
CTINT_PNOISE[0], CTINT_PNOISE[1], CTINT_PNOISE[2]);
20742090
else
20752091
DrawVolFunc(0, (double)vol/(double)0x0F, 0x0F, period, true);
20762092
break;
@@ -2134,14 +2150,14 @@ void CPatternEditor::DrawRegisters(CDC *pDC)
21342150
const int Length = 0x80 - 8 * N163_CHANS;
21352151

21362152
y += 18;
2137-
pDC->FillSolidRect(wave_x - 1, y - 1, 2 * Length + 2, 17, 0x808080);
2153+
pDC->FillSolidRect(wave_x - 1, y - 1, 2 * Length + 2, 17, BORDER_COLOR);
21382154
pDC->FillSolidRect(wave_x, y, 2 * Length, 15, 0);
21392155
for (int i = 0; i < Length; i++) {
21402156
auto pState = pSoundGen->GetRegState(SNDCHIP_N163, i);
21412157
const int Hi = (pState->GetValue() >> 4) & 0x0F;
21422158
const int Lo = pState->GetValue() & 0x0F;
21432159
COLORREF Col = BLEND(
2144-
0xC0C0C0, DECAY_COLOR[pState->GetNewValueTime()], 100 * pState->GetLastUpdatedTime() / CRegisterState::DECAY_RATE
2160+
UPDATE_STALE_COLOR, DECAY_COLOR[pState->GetNewValueTime()], 100 * pState->GetLastUpdatedTime() / CRegisterState::DECAY_RATE
21452161
);
21462162
pDC->FillSolidRect(wave_x + i * 2 , y + 15 - Lo, 1, Lo, Col);
21472163
pDC->FillSolidRect(wave_x + i * 2 + 1, y + 15 - Hi, 1, Hi, Col);
@@ -2155,7 +2171,7 @@ void CPatternEditor::DrawRegisters(CDC *pDC)
21552171
const int UpdateTime = std::min(pPosState->GetLastUpdatedTime(), pLenState->GetLastUpdatedTime());
21562172
pDC->FillSolidRect(wave_x, y + 20 + i * 5, Length * 2, 3, 0);
21572173
pDC->FillSolidRect(wave_x + WavePos, y + 20 + i * 5, WaveLen, 3,
2158-
BLEND(0xC0C0C0, DECAY_COLOR[NewTime], 100 * UpdateTime / CRegisterState::DECAY_RATE));
2174+
BLEND(UPDATE_STALE_COLOR, DECAY_COLOR[NewTime], 100 * UpdateTime / CRegisterState::DECAY_RATE));
21592175
}
21602176
y -= 18;
21612177

@@ -2196,7 +2212,7 @@ void CPatternEditor::DrawRegisters(CDC *pDC)
21962212

21972213
y += 18;
21982214

2199-
pDC->FillSolidRect(wave_x-1, y-1, wave_width+2, wave_height+2, 0x808080); // draw box
2215+
pDC->FillSolidRect(wave_x-1, y-1, wave_width+2, wave_height+2, BORDER_COLOR); // draw box
22002216
pDC->FillSolidRect(wave_x, y, wave_width, wave_height-1, 0); // fill box
22012217
for (int i = 0; i < wave_width; i++) {
22022218
// get register state

0 commit comments

Comments
 (0)
Please sign in to comment.