Skip to content

Commit

Permalink
Merge pull request #1486 from Spekular/master
Browse files Browse the repository at this point in the history
Adds automation flipping.
  • Loading branch information
diizy committed Dec 24, 2014
2 parents 56ba799 + ddbf9cd commit 9e4db14
Show file tree
Hide file tree
Showing 6 changed files with 204 additions and 2 deletions.
6 changes: 6 additions & 0 deletions include/AutomationEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ protected slots:
void eraseButtonToggled();
void selectButtonToggled();
void moveButtonToggled();
void flipYButtonPressed();
void flipXButtonPressed();

void discreteButtonToggled();
void linearButtonToggled();
Expand Down Expand Up @@ -187,6 +189,8 @@ protected slots:
static QPixmap * s_toolErase;
static QPixmap * s_toolSelect;
static QPixmap * s_toolMove;
static QPixmap * s_toolYFlip;
static QPixmap * s_toolXFlip;


QWidget * m_toolBar;
Expand All @@ -198,6 +202,8 @@ protected slots:
ToolButton * m_eraseButton;
ToolButton * m_selectButton;
ToolButton * m_moveButton;
ToolButton * m_flipYButton;
ToolButton * m_flipXButton;

ToolButton * m_discreteButton;
ToolButton * m_linearButton;
Expand Down
2 changes: 2 additions & 0 deletions include/AutomationPattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ public slots:
void clear();
void openInAutomationEditor();
void objectDestroyed( jo_id_t );
void flipY( int min, int max );
void flipX( int length = -1 );

private:
void cleanObjects();
Expand Down
2 changes: 2 additions & 0 deletions include/AutomationPatternView.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ protected slots:
void changeName();
void disconnectObject( QAction * _a );
void toggleRecording();
void flipY();
void flipX();

protected:
virtual void constructContextMenu( QMenu * );
Expand Down
116 changes: 116 additions & 0 deletions src/core/AutomationPattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,122 @@ float *AutomationPattern::valuesAfter( const MidiTime & _time ) const



void AutomationPattern::flipY( int min, int max )
{
timeMap tempMap = m_timeMap;
timeMap::ConstIterator iterate = m_timeMap.lowerBound(0);
float tempValue = 0;

int numPoints = 0;

for( int i = 0; ( iterate + i + 1 ) != m_timeMap.end() && ( iterate + i ) != m_timeMap.end() ; i++)
{
numPoints++;
}

for( int i = 0; i <= numPoints; i++ )
{

if ( min < 0 )
{
tempValue = valueAt( ( iterate + i ).key() ) * -1;
putValue( MidiTime( (iterate + i).key() ) , tempValue, false);
}
else
{
tempValue = max - valueAt( ( iterate + i ).key() );
putValue( MidiTime( (iterate + i).key() ) , tempValue, false);
}
}

generateTangents();
Engine::automationEditor()->update();
emit dataChanged();

}




void AutomationPattern::flipX( int length )
{
timeMap tempMap;

timeMap::ConstIterator iterate = m_timeMap.lowerBound(0);
float tempValue = 0;
int numPoints = 0;

for( int i = 0; ( iterate + i + 1 ) != m_timeMap.end() && ( iterate + i ) != m_timeMap.end() ; i++)
{
numPoints++;
}

float realLength = ( iterate + numPoints ).key();

if ( length != -1 && length != realLength)
{
if ( realLength < length )
{
tempValue = valueAt( ( iterate + numPoints ).key() );
putValue( MidiTime( length ) , tempValue, false);
numPoints++;
for( int i = 0; i <= numPoints; i++ )
{
tempValue = valueAt( ( iterate + i ).key() );
cleanObjects();
MidiTime newTime = MidiTime( length - ( iterate + i ).key() );
tempMap[newTime] = tempValue;
}
}
else
{
//for ( int i = 0; ( iterate + i ).key() < length ; i++ )
//{
// tempValue = valueAt( ( iterate + i ).key() );
//}
//putValue( MidiTime( length ) , tempValue, false);
//numPoints++;
for( int i = 0; i <= numPoints; i++ )
{
tempValue = valueAt( ( iterate + i ).key() );
cleanObjects();
MidiTime newTime;

if ( ( iterate + i ).key() <= length )
{
newTime = MidiTime( length - ( iterate + i ).key() );
}
else
{
newTime = MidiTime( ( iterate + i ).key() );
}
tempMap[newTime] = tempValue;
}
}
}
else
{
for( int i = 0; i <= numPoints; i++ )
{
tempValue = valueAt( ( iterate + i ).key() );
cleanObjects();
MidiTime newTime = MidiTime( realLength - ( iterate + i ).key() );
tempMap[newTime] = tempValue;
}
}

m_timeMap.clear();

m_timeMap = tempMap;

generateTangents();
Engine::automationEditor()->update();
emit dataChanged();
}




void AutomationPattern::saveSettings( QDomDocument & _doc, QDomElement & _this )
{
_this.setAttribute( "pos", startPosition() );
Expand Down
53 changes: 51 additions & 2 deletions src/gui/AutomationEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ QPixmap * AutomationEditor::s_toolDraw = NULL;
QPixmap * AutomationEditor::s_toolErase = NULL;
QPixmap * AutomationEditor::s_toolSelect = NULL;
QPixmap * AutomationEditor::s_toolMove = NULL;
QPixmap * AutomationEditor::s_toolYFlip = NULL;
QPixmap * AutomationEditor::s_toolXFlip = NULL;



Expand Down Expand Up @@ -128,6 +130,16 @@ AutomationEditor::AutomationEditor() :
s_toolMove = new QPixmap( embed::getIconPixmap(
"edit_move" ) );
}
if( s_toolYFlip == NULL )
{
s_toolYFlip = new QPixmap( embed::getIconPixmap(
"flip_y" ) );
}
if( s_toolXFlip == NULL )
{
s_toolXFlip = new QPixmap( embed::getIconPixmap(
"flip_x" ) );
}

setAttribute( Qt::WA_OpaquePaintEvent, true );

Expand Down Expand Up @@ -206,15 +218,25 @@ AutomationEditor::AutomationEditor() :
m_toolBar );
m_eraseButton->setCheckable( true );

m_flipYButton = new ToolButton( embed::getIconPixmap( "flip_y" ),
tr( "Flip Vertically" ),
this, SLOT( flipYButtonPressed() ),
m_toolBar );

m_flipXButton = new ToolButton( embed::getIconPixmap( "flip_x" ),
tr( "Flip Horizontally" ),
this, SLOT( flipXButtonPressed() ),
m_toolBar );

//TODO: m_selectButton and m_moveButton are broken.
/*m_selectButton = new toolButton( embed::getIconPixmap(
/*m_selectButton = new ToolButton( embed::getIconPixmap(
"edit_select" ),
tr( "Select mode (Shift+S)" ),
this, SLOT( selectButtonToggled() ),
m_toolBar );
m_selectButton->setCheckable( true );
m_moveButton = new toolButton( embed::getIconPixmap( "edit_move" ),
m_moveButton = new ToolButton( embed::getIconPixmap( "edit_move" ),
tr( "Move selection mode (Shift+M)" ),
this, SLOT( moveButtonToggled() ),
m_toolBar );
Expand All @@ -223,6 +245,8 @@ AutomationEditor::AutomationEditor() :
QButtonGroup * tool_button_group = new QButtonGroup( this );
tool_button_group->addButton( m_drawButton );
tool_button_group->addButton( m_eraseButton );
tool_button_group->addButton( m_flipYButton );
tool_button_group->addButton( m_flipXButton );
//tool_button_group->addButton( m_selectButton );
//tool_button_group->addButton( m_moveButton );
tool_button_group->setExclusive( true );
Expand All @@ -237,6 +261,12 @@ AutomationEditor::AutomationEditor() :
tr( "Click here and erase-mode will be activated. In this "
"mode you can erase single values. You can also press "
"'Shift+E' on your keyboard to activate this mode." ) );
m_flipYButton->setWhatsThis(
tr( "Click here and the pattern will be inverted."
"The points are flipped in the y direction. " ) );
m_flipXButton->setWhatsThis(
tr( "Click here and the pattern will be reversed. "
"The points are flipped in the x direction." ) );
/*m_selectButton->setWhatsThis(
tr( "Click here and select-mode will be activated. In this "
"mode you can select values. This is necessary "
Expand Down Expand Up @@ -394,6 +424,9 @@ AutomationEditor::AutomationEditor() :
tb_layout->addSpacing( 10 );
tb_layout->addWidget( m_drawButton );
tb_layout->addWidget( m_eraseButton );
tb_layout->addSpacing( 10 );
tb_layout->addWidget( m_flipYButton );
tb_layout->addWidget( m_flipXButton );
//tb_layout->addWidget( m_selectButton );
//tb_layout->addWidget( m_moveButton );
tb_layout->addSpacing( 10 );
Expand Down Expand Up @@ -2029,6 +2062,22 @@ void AutomationEditor::eraseButtonToggled()



void AutomationEditor::flipYButtonPressed()
{
m_pattern->flipY( m_minLevel, m_maxLevel );
}




void AutomationEditor::flipXButtonPressed()
{
m_pattern->flipX();
}




void AutomationEditor::selectButtonToggled()
{
m_editMode = SELECT;
Expand Down
27 changes: 27 additions & 0 deletions src/gui/AutomationPatternView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,27 @@ void AutomationPatternView::toggleRecording()
}




void AutomationPatternView::flipY()
{
m_pat->flipY( m_pat->getMin(), m_pat->getMax() );
update();
}




void AutomationPatternView::flipX()
{
//m_pat->flipX( m_pat->length() );
m_pat->flipX( m_pat->TrackContentObject::length() );
update();
}




void AutomationPatternView::constructContextMenu( QMenu * _cm )
{
QAction * a = new QAction( embed::getIconPixmap( "automation" ),
Expand All @@ -168,6 +189,12 @@ void AutomationPatternView::constructContextMenu( QMenu * _cm )
_cm->addAction( embed::getIconPixmap( "record" ),
tr( "Set/clear record" ),
this, SLOT( toggleRecording() ) );
_cm->addAction( embed::getIconPixmap( "flip_y" ),
tr( "Flip Vertically (Visible)" ),
this, SLOT( flipY() ) );
_cm->addAction( embed::getIconPixmap( "flip_x" ),
tr( "Flip Horizontally (Visible)" ),
this, SLOT( flipX() ) );
if( !m_pat->m_objects.isEmpty() )
{
_cm->addSeparator();
Expand Down

0 comments on commit 9e4db14

Please sign in to comment.