Skip to content
Closed
Show file tree
Hide file tree
Changes from 11 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
1 change: 0 additions & 1 deletion include/AutomatableModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -483,4 +483,3 @@ class LMMS_EXPORT BoolModel : public TypedAutomatableModel<bool>
typedef QMap<AutomatableModel*, float> AutomatedValueMap;

#endif

3 changes: 3 additions & 0 deletions include/AutomationEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public slots:
virtual void mousePressEvent(QMouseEvent * mouseEvent);
virtual void mouseReleaseEvent(QMouseEvent * mouseEvent);
virtual void mouseMoveEvent(QMouseEvent * mouseEvent);
virtual void mouseDoubleClickEvent( QMouseEvent * mouseEvent);
virtual void paintEvent(QPaintEvent * pe);
virtual void resizeEvent(QResizeEvent * re);
virtual void wheelEvent(QWheelEvent * we);
Expand Down Expand Up @@ -208,6 +209,8 @@ protected slots:
float m_scrollLevel;
float m_bottomLevel;
float m_topLevel;
float m_pointYLevel;
ulong m_pointYLevelTimestamp;

void updateTopBottomLevels();

Expand Down
227 changes: 151 additions & 76 deletions src/gui/editors/AutomationEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <cmath>

#include <QApplication>
#include <QInputDialog>
#include <QKeyEvent>
#include <QLabel>
#include <QLayout>
Expand Down Expand Up @@ -86,6 +87,7 @@ AutomationEditor::AutomationEditor() :
m_scrollLevel( 0 ),
m_bottomLevel( 0 ),
m_topLevel( 0 ),
m_pointYLevel(0),
m_currentPosition(),
m_action( NONE ),
m_moveStartLevel( 0 ),
Expand Down Expand Up @@ -742,6 +744,7 @@ void AutomationEditor::mouseMoveEvent(QMouseEvent * mouseEvent )

int pos_ticks = x * MidiTime::ticksPerTact() / m_ppt +
m_currentPosition;

if( mouseEvent->buttons() & Qt::LeftButton && m_editMode == DRAW )
{
if( m_action == MOVE_VALUE )
Expand Down Expand Up @@ -783,63 +786,6 @@ void AutomationEditor::mouseMoveEvent(QMouseEvent * mouseEvent )
removePoints( m_drawLastTick, pos_ticks );
Engine::getSong()->setModified();
}
else if( mouseEvent->buttons() & Qt::NoButton && m_editMode == DRAW )
{
// set move- or resize-cursor

// get time map of current pattern
timeMap & time_map = m_pattern->getTimeMap();

// will be our iterator in the following loop
timeMap::iterator it = time_map.begin();
// loop through whole time map...
for( ; it != time_map.end(); ++it )
{
// and check whether the cursor is over an
// existing value
if( pos_ticks >= it.key() &&
( it+1==time_map.end() ||
pos_ticks <= (it+1).key() ) &&
level <= it.value() )
{
break;
}
}

// did it reach end of map because there's
// no value??
if( it != time_map.end() )
{
if( QApplication::overrideCursor() )
{
if( QApplication::overrideCursor()->shape() != Qt::SizeAllCursor )
{
while( QApplication::overrideCursor() != NULL )
{
QApplication::restoreOverrideCursor();
}

QCursor c( Qt::SizeAllCursor );
QApplication::setOverrideCursor(
c );
}
}
else
{
QCursor c( Qt::SizeAllCursor );
QApplication::setOverrideCursor( c );
}
}
else
{
// the cursor is over no value, so restore
// cursor
while( QApplication::overrideCursor() != NULL )
{
QApplication::restoreOverrideCursor();
}
}
}
else if( mouseEvent->buttons() & Qt::LeftButton &&
m_editMode == SELECT &&
m_action == SELECT_VALUES )
Expand Down Expand Up @@ -921,7 +867,6 @@ void AutomationEditor::mouseMoveEvent(QMouseEvent * mouseEvent )
int tact_diff = ticks_diff / MidiTime::ticksPerTact();
ticks_diff = ticks_diff % MidiTime::ticksPerTact();


// do vertical move-stuff
float level_diff = level - m_moveStartLevel;

Expand Down Expand Up @@ -998,14 +943,75 @@ void AutomationEditor::mouseMoveEvent(QMouseEvent * mouseEvent )
m_moveStartTick = pos_ticks;
m_moveStartLevel = level;
}
else if (m_editMode == DRAW)
{
// get time map of current pattern
timeMap & time_map = m_pattern->getTimeMap();
// will be our iterator in the following loop
timeMap::iterator it = time_map.begin();
// loop through whole time map...

while (it != time_map.end())
{
// and check whether the cursor is over an
// existing value
if (pos_ticks >= it.key() - MidiTime::ticksPerTact() *4 / m_ppt
&& (it+1==time_map.end() || pos_ticks <= (it+1).key())
&& (pos_ticks<= it.key() + MidiTime::ticksPerTact() *4 / m_ppt))
{
break;
}
it++;
}

m_pointYLevel = roundf(it.value() * 1000) / 1000;
// did it reach end of map because there's
// no value??
if( it != time_map.end() )
{
if( QApplication::overrideCursor() )
{
if( QApplication::overrideCursor()->shape() != Qt::SizeAllCursor )
{
while( QApplication::overrideCursor() != NULL )
{
QApplication::restoreOverrideCursor();
}

QCursor c( Qt::SizeAllCursor );
QApplication::setOverrideCursor(
c );
}
}
else
{
QCursor c( Qt::SizeAllCursor );
QApplication::setOverrideCursor( c );
}
}
else
{
// the cursor is over no value, so restore
// cursor
while( QApplication::overrideCursor() != NULL )
{
QApplication::restoreOverrideCursor();
}

// sets drawCross tooltip back to mouse y position
if (mouseEvent->timestamp() > m_pointYLevelTimestamp)
{
m_pointYLevel = 0;
}
}
}
}
else
{
if( mouseEvent->buttons() & Qt::LeftButton &&
m_editMode == SELECT &&
m_action == SELECT_VALUES )
{

int x = mouseEvent->x() - VALUES_WIDTH;
if( x < 0 && m_currentPosition > 0 )
{
Expand All @@ -1030,22 +1036,20 @@ void AutomationEditor::mouseMoveEvent(QMouseEvent * mouseEvent )
m_leftRightScroll->setValue( m_currentPosition +
4 );
}

// get tick in which the cursor is posated
int pos_ticks = x * MidiTime::ticksPerTact() / m_ppt +
m_currentPosition;

m_selectedTick = pos_ticks -
m_selectStartTick;
if( (int) m_selectStartTick + m_selectedTick <
0 )
if ((int) m_selectStartTick + m_selectedTick < 0)
{
m_selectedTick = -m_selectStartTick;
}

float level = getLevel( mouseEvent->y() );
float level = getLevel(mouseEvent->y());

if( level <= m_bottomLevel )
if (level <= m_bottomLevel)
{
QCursor::setPos( mapToGlobal( QPoint( mouseEvent->x(),
height() -
Expand All @@ -1054,7 +1058,7 @@ void AutomationEditor::mouseMoveEvent(QMouseEvent * mouseEvent )
m_topBottomScroll->value() + 1 );
level = m_bottomLevel;
}
else if( level >= m_topLevel )
else if (level >= m_topLevel)
{
QCursor::setPos( mapToGlobal( QPoint( mouseEvent->x(),
TOP_MARGIN ) ) );
Expand All @@ -1063,7 +1067,7 @@ void AutomationEditor::mouseMoveEvent(QMouseEvent * mouseEvent )
level = m_topLevel;
}
m_selectedLevels = level - m_selectStartLevel;
if( level <= m_selectStartLevel )
if (level <= m_selectStartLevel)
{
--m_selectedLevels;
}
Expand All @@ -1077,6 +1081,15 @@ void AutomationEditor::mouseMoveEvent(QMouseEvent * mouseEvent )



void AutomationEditor::mouseDoubleClickEvent( QMouseEvent * mouseEvent)
{
// TODO: Double click on automation point opens Dialog Box
// to enter automation point y level values
}




inline void AutomationEditor::drawCross( QPainter & p )
{
QPoint mouse_pos = mapFromGlobal( QCursor::pos() );
Expand All @@ -1100,12 +1113,19 @@ inline void AutomationEditor::drawCross( QPainter & p )
float scaledLevel = m_pattern->firstObject()->scaledValue( level );

// Limit the scaled-level tooltip to the grid
if( mouse_pos.x() >= 0 &&
if(mouse_pos.x() >= 0 &&
mouse_pos.x() <= width() - SCROLLBAR_SIZE &&
mouse_pos.y() >= 0 &&
mouse_pos.y() <= height() - SCROLLBAR_SIZE )
mouse_pos.y() <= height() - SCROLLBAR_SIZE)
{
QToolTip::showText( tt_pos, QString::number( scaledLevel ), this );
if (m_pointYLevel == 0)
{
QToolTip::showText(tt_pos, QString::number(scaledLevel), this);
}
else if (m_pointYLevel != 0)
{
QToolTip::showText(tt_pos, QString::number(m_pointYLevel), this);
}
}
}

Expand Down Expand Up @@ -1696,19 +1716,74 @@ void AutomationEditor::wheelEvent(QWheelEvent * we )
// scroll so the tick "selected" by the mouse x doesn't move on the screen
m_leftRightScroll->setValue(m_leftRightScroll->value() + ticks - newTicks);


m_zoomingXModel.setValue( x );
}
else if( we->modifiers() & Qt::ShiftModifier
|| we->orientation() == Qt::Horizontal )
else if (we->modifiers() & Qt::ShiftModifier
|| we->orientation() == Qt::Horizontal)
{
m_leftRightScroll->setValue( m_leftRightScroll->value() -
we->delta() * 2 / 15 );
m_leftRightScroll->setValue(m_leftRightScroll->value() -
we->delta() * 2 / 15);
}
else
{
m_topBottomScroll->setValue( m_topBottomScroll->value() -
we->delta() / 30 );
if (we->y() > TOP_MARGIN)
{
float level = getLevel(we->y());
int x = we->x();

if (x >= VALUES_WIDTH)
{
// set or move value
x -= VALUES_WIDTH;
// get tick in which the cursor is posated
int pos_ticks = x * MidiTime::ticksPerTact() / m_ppt +
m_currentPosition;
//disable scrolling while adjusting automation point
bool enableYScrolling = true;
// get time map of current pattern
timeMap & time_map = m_pattern->getTimeMap();
// will be our iterator in the following loop
timeMap::iterator it = time_map.begin();
// and check whether the user scrolls over an
// existing value
while (it != time_map.end())
{
pos_ticks = (pos_ticks < 0) ? 0 : pos_ticks;

if (pos_ticks >= it.key() - MidiTime::ticksPerTact() *4 / m_ppt
&& (it+1==time_map.end() || pos_ticks <= (it+1).key())
&& (pos_ticks<= it.key() + MidiTime::ticksPerTact() *4 / m_ppt))
{
// mouse wheel up
if (we->delta() < 0)
{
level = roundf(it.value() * 1000) / 1000 -
m_pattern->firstObject()->step<float>();
}
// mouse wheel down
else if (we->delta() > 0)
{
level = roundf(it.value() * 1000) / 1000 +
m_pattern->firstObject()->step<float>();
}
m_pointYLevel = level;
m_pointYLevelTimestamp = we->timestamp();
enableYScrolling = false;
// set new value
m_pattern->setDragValue(MidiTime(pos_ticks), level, true, false);
// apply new value
m_pattern->applyDragValue();
break;
}
++it;
}
if (enableYScrolling)
{
m_topBottomScroll->setValue(m_topBottomScroll->value() -
we->delta() / 30);
}
}
}
}
}

Expand Down