Skip to content

Commit

Permalink
Automation Node fine tuning with double-click (Rewrites LMMS#5292) (L…
Browse files Browse the repository at this point in the history
…MMS#5923)

Co-authored-by: tecknixia <[email protected]>
  • Loading branch information
IanCaio and tecknixia authored Mar 28, 2021
1 parent 9fb6295 commit 70b044a
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/AutomationEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public slots:
void keyPressEvent(QKeyEvent * ke) override;
void leaveEvent(QEvent * e) override;
void mousePressEvent(QMouseEvent * mouseEvent) override;
void mouseDoubleClickEvent(QMouseEvent * mouseEvent) override;
void mouseReleaseEvent(QMouseEvent * mouseEvent) override;
void mouseMoveEvent(QMouseEvent * mouseEvent) override;
void paintEvent(QPaintEvent * pe) override;
Expand All @@ -112,6 +113,7 @@ public slots:
timeMap::iterator getNodeAt(int x, int y, bool outValue = false, int r = 5);

void drawLine( int x0, float y0, int x1, float y1 );
bool fineTuneValue(timeMap::iterator node, bool editingOutValue);

protected slots:
void play();
Expand Down
72 changes: 72 additions & 0 deletions src/gui/editors/AutomationEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,53 @@ void AutomationEditor::drawLine( int x0In, float y0, int x1In, float y1 )



bool AutomationEditor::fineTuneValue(timeMap::iterator node, bool editingOutValue)
{
if (node == m_pattern->getTimeMap().end()) { return false; }

// Display dialog to edit the value
bool ok;
double value = QInputDialog::getDouble(
this,
tr("Edit Value"),
editingOutValue
? tr("New outValue")
: tr("New inValue"),
editingOutValue
? OUTVAL(node)
: INVAL(node),
m_pattern->firstObject()->minValue<float>(),
m_pattern->firstObject()->maxValue<float>(),
3,
&ok
);

// If dialog failed return false
if (!ok) { return false; }

// Set the new inValue/outValue
if (editingOutValue)
{
node.value().setOutValue(value);
}
else
{
// If the outValue is equal to the inValue we
// set both to the given value
if (OFFSET(node) == 0)
{
node.value().setOutValue(value);
}
node.value().setInValue(value);
}

Engine::getSong()->setModified();
return true;
}




void AutomationEditor::mousePressEvent( QMouseEvent* mouseEvent )
{
if( !validPattern() )
Expand Down Expand Up @@ -615,6 +662,31 @@ void AutomationEditor::mousePressEvent( QMouseEvent* mouseEvent )



void AutomationEditor::mouseDoubleClickEvent(QMouseEvent * mouseEvent)
{
if (!validPattern()) { return; }

// If we double clicked outside the AutomationEditor viewport return
if (mouseEvent->y() <= TOP_MARGIN || mouseEvent->x() < VALUES_WIDTH) { return; }

// Are we fine tuning the inValue or outValue?
const bool isOutVal = (m_editMode == DRAW_OUTVALUES);
timeMap::iterator clickedNode = getNodeAt(mouseEvent->x(), mouseEvent->y(), isOutVal);

switch (m_editMode)
{
case DRAW:
case DRAW_OUTVALUES:
if (fineTuneValue(clickedNode, isOutVal)) { update(); }
break;
default:
break;
}
}




void AutomationEditor::mouseReleaseEvent(QMouseEvent * mouseEvent )
{
bool mustRepaint = false;
Expand Down

0 comments on commit 70b044a

Please sign in to comment.