Skip to content

Commit

Permalink
Rebase BaraMGB's Knife
Browse files Browse the repository at this point in the history
  • Loading branch information
Spekular authored and PhysSong committed Jul 27, 2019
1 parent 1c715bc commit c8c710b
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 2 deletions.
4 changes: 4 additions & 0 deletions include/SongEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class SongEditor : public TrackContainerView
enum EditMode
{
DrawMode,
KnifeMode,
SelectMode
};

Expand All @@ -82,6 +83,7 @@ public slots:

void setEditMode( EditMode mode );
void setEditModeDraw();
void setEditModeKnife();
void setEditModeSelect();
void toggleProportionalSnap();

Expand Down Expand Up @@ -114,6 +116,7 @@ private slots:
virtual void wheelEvent( QWheelEvent * we );

virtual bool allowRubberband() const;
virtual bool knifeMode() const;


Song * m_song;
Expand Down Expand Up @@ -192,6 +195,7 @@ protected slots:

ActionGroup * m_editModeGroup;
QAction* m_drawModeAction;
QAction* m_knifeModeAction;
QAction* m_selectModeAction;
QAction* m_crtlAction;

Expand Down
1 change: 1 addition & 0 deletions include/TrackContainerView.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class TrackContainerView : public QWidget, public ModelView,
const TrackView * trackViewAt( const int _y ) const;

virtual bool allowRubberband() const;
virtual bool knifeMode() const;

inline bool rubberBandActive() const
{
Expand Down
24 changes: 23 additions & 1 deletion src/core/Track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,29 @@ void TrackContentObjectView::mousePressEvent( QMouseEvent * me )
{
setInitialPos( me->pos() );
setInitialOffsets();
if( !fixedTCOs() && me->button() == Qt::LeftButton )
if ( m_trackView->trackContainerView()->knifeMode()
&& me->button() == Qt::LeftButton )
{
SampleTCO * leftTCO = dynamic_cast<SampleTCO*>( m_tco );
if ( leftTCO )
{
const float ppt = m_trackView->trackContainerView()->pixelsPerTact();
const int x = mapToParent( me->pos() ).x();
MidiTime t = qMax<int>( 0, m_trackView->trackContainerView()->currentPosition() + x * MidiTime::ticksPerTact()/ppt);
if ( me->modifiers() & Qt::ControlModifier
|| me->modifiers() & Qt::AltModifier ) {}
else { t = t.quantize( gui->songEditor()->m_editor->getSnapSize() ); }
leftTCO->copy();
SampleTCO * rightTCO = new SampleTCO ( leftTCO->getTrack() );
rightTCO->paste();

leftTCO->changeLength( t - leftTCO->startPosition() );
rightTCO->movePosition(t);
rightTCO->changeLength( rightTCO->length() - leftTCO->length() );
rightTCO->setStartTimeOffset( leftTCO->startTimeOffset() - leftTCO->length() );
}
}
else if( !fixedTCOs() && me->button() == Qt::LeftButton )
{
if( me->modifiers() & Qt::ControlModifier )
{
Expand Down
10 changes: 9 additions & 1 deletion src/gui/TrackContainerView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,14 @@ bool TrackContainerView::allowRubberband() const



bool TrackContainerView::knifeMode() const
{
return false;
}




void TrackContainerView::setPixelsPerTact( int _ppt )
{
m_ppt = _ppt;
Expand Down Expand Up @@ -377,7 +385,7 @@ void TrackContainerView::dropEvent( QDropEvent * _de )
//it->toggledInstrumentTrackButton( true );
_de->accept();
}
else if( type == "samplefile" || type == "pluginpresetfile"
else if( type == "samplefile" || type == "pluginpresetfile"
|| type == "soundfontfile" || type == "vstpluginfile"
|| type == "patchfile" )
{
Expand Down
16 changes: 16 additions & 0 deletions src/gui/editors/SongEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,11 @@ void SongEditor::setEditModeDraw()
setEditMode(DrawMode);
}

void SongEditor::setEditModeKnife()
{
setEditMode(KnifeMode);
}

void SongEditor::setEditModeSelect()
{
setEditMode(SelectMode);
Expand Down Expand Up @@ -713,6 +718,14 @@ bool SongEditor::allowRubberband() const



bool SongEditor::knifeMode() const
{
return m_mode == KnifeMode;
}




ComboBoxModel *SongEditor::zoomingModel() const
{
return m_zoomingModel;
Expand Down Expand Up @@ -777,13 +790,16 @@ SongEditorWindow::SongEditorWindow(Song* song) :

m_editModeGroup = new ActionGroup(this);
m_drawModeAction = m_editModeGroup->addAction(embed::getIconPixmap("edit_draw"), tr("Draw mode"));
m_knifeModeAction = m_editModeGroup->addAction(embed::getIconPixmap("edit_knife"), tr("Knife mode (split sample clips)"));
m_selectModeAction = m_editModeGroup->addAction(embed::getIconPixmap("edit_select"), tr("Edit mode (select and move)"));
m_drawModeAction->setChecked(true);

connect(m_drawModeAction, SIGNAL(triggered()), m_editor, SLOT(setEditModeDraw()));
connect(m_knifeModeAction, SIGNAL(triggered()), m_editor, SLOT(setEditModeKnife()));
connect(m_selectModeAction, SIGNAL(triggered()), m_editor, SLOT(setEditModeSelect()));

editActionsToolBar->addAction( m_drawModeAction );
editActionsToolBar->addAction( m_knifeModeAction );
editActionsToolBar->addAction( m_selectModeAction );

DropToolBar *timeLineToolBar = addDropToolBarToTop(tr("Timeline controls"));
Expand Down

0 comments on commit c8c710b

Please sign in to comment.