Skip to content

Commit

Permalink
Implement logarithmic volume view for VRC7
Browse files Browse the repository at this point in the history
- S5B volume 0 does not output anything
  • Loading branch information
Gumball2415 committed Mar 6, 2025
1 parent 687aab9 commit 35532a7
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions Source/PatternEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1960,17 +1960,17 @@ void CPatternEditor::DrawRegisters(CDC *pDC)
DrawVolBar();

// 3db per step
const double vol = envelope_enable ? 1 : (std::pow(10.0, (((Volume + 1.0) * 3.0) / 20.0)) / 251.18864315095801110850320677993);
double vol = envelope_enable ? 1 : (std::pow(10.0, (((Volume + 1.0) * 3.0) / 20.0)) / 251.18864315095801110850320677993);

const BYTE vol_scaled = OETF_gamma_vol(Volume);
const BYTE vol_scaled = OETF_gamma_vol(vol);

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


if (note_conv >= -12 && note_conv <= 96 && (vol_scaled || envelope_enable)) // // //
if (note_conv >= -12 && note_conv <= 96 && (Volume || envelope_enable)) // // //
if (noise_enable || envelope_enable)
DrawVolNote(PrecisePitch ? note : note_conv, vol_scaled, // !! !!
CTINT_S5B_T[0], CTINT_S5B_T[1], CTINT_S5B_T[2]);
Expand All @@ -1987,6 +1987,24 @@ void CPatternEditor::DrawRegisters(CDC *pDC)
++vis_line;
};

// Draw envelope and noise pitch
const auto DrawVolFuncVRC7 = [&](double Freq, int Volume) {
DrawVolBar();

// 3db per step
const double vol = std::pow(10.0, (((Volume + 1.0) * 3.0) / 20.0)) / 251.18864315095801110850320677993;

const BYTE vol_scaled = OETF_gamma_vol(vol);

const double note = NoteFromFreq(Freq);
const int note_conv = note >= 0 ? int(note + 0.5) : int(note - 0.5);


if (note_conv >= -12 && note_conv <= 96 && vol_scaled) // // //
DrawVolNote(PrecisePitch ? note : note_conv, vol_scaled);
++vis_line;
};

const auto DrawTextFunc = [&] (int xOffsNoDPI, CString text) {
pDC->SetTextColor(BORDER_COLOR);
pDC->SetTextAlign(TA_NOUPDATECP);
Expand Down Expand Up @@ -2282,7 +2300,7 @@ void CPatternEditor::DrawRegisters(CDC *pDC)
text.Format(_T("%s, vol = %02i, patch = $%01X"), GetPitchTextFunc(3, period, freq), vol, reg[2] >> 4);
DrawTextFunc(180, text);

DrawVolFunc(freq, (double)vol/(double)0x0F);
DrawVolFuncVRC7(freq, vol);
}
}

Expand Down

0 comments on commit 35532a7

Please sign in to comment.