Use lambda for calculating a note's Y position

This commit is contained in:
Veratil
2021-03-07 12:45:23 -06:00
committed by Kevin Zander
parent 85c1973f30
commit 266ad8d45e

View File

@@ -3362,6 +3362,12 @@ void PianoRoll::paintEvent(QPaintEvent * pe )
QPolygonF editHandles;
// Return a note's Y position on the grid
auto noteYPos = [&](const int key)
{
return (topKey - key) * m_keyLineHeight + keyAreaTop() - 1;
};
// -- Begin ghost pattern
if( !m_ghostNotes.empty() )
{
@@ -3395,7 +3401,7 @@ void PianoRoll::paintEvent(QPaintEvent * pe )
// we've done and checked all, let's draw the note
drawNoteRect(
p, x + m_whiteKeyWidth, (topKey - note->key()) * m_keyLineHeight + keyAreaTop() - 1, note_width,
p, x + m_whiteKeyWidth, noteYPos(note->key()), note_width,
note, m_ghostNoteColor, m_ghostNoteTextColor, m_selectedNoteColor,
m_ghostNoteOpacity, m_ghostNoteBorders, drawNoteNames);
}
@@ -3417,8 +3423,6 @@ void PianoRoll::paintEvent(QPaintEvent * pe )
len_ticks = 4;
}
const int key = note->key() - m_startKey + 1;
int pos_ticks = note->pos();
int note_width = len_ticks * m_ppb / TimePos::ticksPerBar();
@@ -3435,7 +3439,7 @@ void PianoRoll::paintEvent(QPaintEvent * pe )
{
// we've done and checked all, let's draw the note
drawNoteRect(
p, x + m_whiteKeyWidth, (topKey - note->key()) * m_keyLineHeight + keyAreaTop() - 1, note_width,
p, x + m_whiteKeyWidth, noteYPos(note->key()), note_width,
note, m_noteColor, m_noteTextColor, m_selectedNoteColor,
m_noteOpacity, m_noteBorders, drawNoteNames);
}
@@ -3484,7 +3488,7 @@ void PianoRoll::paintEvent(QPaintEvent * pe )
if( note->hasDetuningInfo() )
{
drawDetuningInfo(p, note, x + m_whiteKeyWidth, y_base - key * m_keyLineHeight);
drawDetuningInfo(p, note, x + m_whiteKeyWidth, noteYPos(note->key()));
p.setClipRect(
m_whiteKeyWidth,
PR_TOP_MARGIN,
@@ -3556,7 +3560,7 @@ void PianoRoll::paintEvent(QPaintEvent * pe )
// we've done and checked all, let's draw the note
drawNoteRect(
p, x + m_whiteKeyWidth, (topKey - note->key()) * m_keyLineHeight + keyAreaTop() - 1, note_width,
p, x + m_whiteKeyWidth, noteYPos(note->key()), note_width,
note, m_stepRecorder.curStepNoteColor(), m_noteTextColor, m_selectedNoteColor,
m_noteOpacity, m_noteBorders, drawNoteNames);
}