Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 40 additions & 3 deletions src/gui/editors/PianoRoll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1081,108 +1081,145 @@



void PianoRoll::drawDetuningInfo( QPainter & _p, const Note * _n, int _x,
int _y ) const
{
int middle_y = _y + m_keyLineHeight / 2;
_p.setBrush(QBrush(m_noteColor));
_p.setPen(m_noteColor);
_p.setClipRect(
m_whiteKeyWidth,
PR_TOP_MARGIN,
width() - m_whiteKeyWidth,
keyAreaBottom() - PR_TOP_MARGIN);

// Draw lines for the detuning automation, treating cubic hermit curves
// as straight lines for now. Also draw discrete jumps.
int old_x = 0;
int old_y = 0;
int old_ticks = 0;

timeMap & map = _n->detuning()->automationClip()->getTimeMap();
for (timeMap::const_iterator it = map.begin(); it != map.end(); ++it)
{
// Current node values
int cur_ticks = POS(it);
int cur_x = _x + cur_ticks * m_ppb / TimePos::ticksPerBar();
const float cur_level = INVAL(it);
int cur_y = middle_y - cur_level * m_keyLineHeight;

// First line to represent the inValue of the first node
if (it == map.begin())
{
_p.drawLine(cur_x - 1, cur_y, cur_x + 1, cur_y);
_p.drawLine(cur_x, cur_y - 1, cur_x, cur_y + 1);
}
// All subsequent lines will take the outValue of the previous node
// and the inValue of the current node. It will also draw a vertical
// line if there was a discrete jump (from old_x,old_y to pre_x,pre_y)
else
{
// Previous node values (based on outValue). We just calculate
// the y level because the x will be the same as old_x.
const auto pit = std::prev(it);
const auto nit = std::next(it);

const float pre_level = OUTVAL(pit);
int pre_y = middle_y - pre_level * m_keyLineHeight;

// Draws the line representing the discrete jump if there's one
if (old_y != pre_y)
// Draws the line representing the discrete jump if there's one.
// Displaying this line in CubicHermite mode would add clutter, so we'll stop that, except when editing mode is active and on that note.
if ((old_y != pre_y) && (_n->detuning()->automationClip()->progressionType() != AutomationClip::ProgressionType::CubicHermite || (m_editMode == EditMode::Detuning && _n->selected())))
{
_p.drawLine(old_x, old_y, old_x, pre_y);
}

// Now draw the lines representing the actual progression from one
// node to the other
switch (_n->detuning()->automationClip()->progressionType())
{
case AutomationClip::ProgressionType::Discrete:
_p.drawLine(old_x, pre_y, cur_x, pre_y);
_p.drawLine(cur_x, pre_y, cur_x, cur_y);
break;
case AutomationClip::ProgressionType::CubicHermite: /* TODO */
case AutomationClip::ProgressionType::CubicHermite: /* TODO: Make this more performant.*/
{
int cubiccurve_pre_x = old_x;
int cubiccurve_pre_y = old_y;
for (int cubiccurve_counter = old_ticks; cubiccurve_counter <= cur_ticks; cubiccurve_counter++)
{
int cubiccurve_cur_x = _x + cubiccurve_counter * m_ppb / TimePos::ticksPerBar();
int cubiccurve_cur_y = middle_y - _n->detuning()->automationClip()->valueAt(cubiccurve_counter) * m_keyLineHeight;
_p.drawLine(cubiccurve_pre_x, cubiccurve_pre_y, cubiccurve_cur_x, cubiccurve_cur_y);
cubiccurve_pre_x = cubiccurve_cur_x;
cubiccurve_pre_y = cubiccurve_cur_y;
}
break;
}
case AutomationClip::ProgressionType::Linear:
_p.drawLine(old_x, pre_y, cur_x, cur_y);
break;
}

// If we are in the last node and there's a discrete jump, we draw a
// vertical line representing it
if (nit == map.end())
{
const float last_level = OUTVAL(it);
if (cur_level != last_level)
{
int last_y = middle_y - last_level * m_keyLineHeight;
_p.drawLine(cur_x, cur_y, cur_x, last_y);
// Draw a little hook to signal end of automation.
_p.drawLine(cur_x, last_y - 1, cur_x + 5 * m_ppb / TimePos::ticksPerBar(), last_y - 1);
_p.drawLine(cur_x, last_y + 1, cur_x + 5 * m_ppb / TimePos::ticksPerBar(), last_y + 1);
}
else
{
// Draw a little hook to signal end of automation.
_p.drawLine(cur_x, cur_y - 1, cur_x + 5 * m_ppb / TimePos::ticksPerBar(), cur_y - 1);
_p.drawLine(cur_x, cur_y + 1, cur_x + 5 * m_ppb / TimePos::ticksPerBar(), cur_y + 1);
}
}
}

old_x = cur_x;
old_y = cur_y;
old_ticks = cur_ticks;
}

if (m_editMode == EditMode::Detuning && _n->selected())
{
for (timeMap::const_iterator it = map.begin(); it != map.end(); ++it)
{
int curTicks = POS(it);
int curX = _x + curTicks * m_ppb / TimePos::ticksPerBar();
const float curLevel = INVAL(it);
const float outLevel = OUTVAL(it);
int curY = middle_y - curLevel * m_keyLineHeight;
int outY = middle_y - outLevel * m_keyLineHeight;

if (curLevel != outLevel)
{
_p.drawEllipse(
curX - DETUNING_HANDLE_RADIUS / 2,
outY - DETUNING_HANDLE_RADIUS / 2,
2 * DETUNING_HANDLE_RADIUS / 2,
2 * DETUNING_HANDLE_RADIUS / 2);
}

_p.drawEllipse(
curX - DETUNING_HANDLE_RADIUS,
curY - DETUNING_HANDLE_RADIUS,
2 * DETUNING_HANDLE_RADIUS,
2 * DETUNING_HANDLE_RADIUS);
}
}
}




Check notice on line 1222 in src/gui/editors/PianoRoll.cpp

View check run for this annotation

codefactor.io / CodeFactor

src/gui/editors/PianoRoll.cpp#L1084-L1222

Complex Method
void PianoRoll::removeSelection()
{
m_selectStartTick = 0;
Expand Down
Loading