Skip to content

Commit

Permalink
Knife Tool for Sample Clips (Again) (#5524)
Browse files Browse the repository at this point in the history
* Rebase BaraMGB's Knife
Co-authored-by: Steffen Baranowsky <BaraMGB@freenet.de>

* Draw marker

* Refactoring and shift mode

* Allow resizing

* Add Icon

* Fix stuck marker on RMB, remove unnecessary cast

* Remove redundant line, more const

* Fix

* Review fixes

* Only perform split logic for SampleTCO

* Add unquantizedModHeld function

* missed one

* Don't use copy/paste

* Don't use copy/paste

* More git troubles

* Fix undo

* git dammit

* Cleaner solution?

* Set cursor, add copy assignment to SampleBuffer

* Add TODO comment

* Make it build

* Fixes from review

* Make splitTCO virtual

* Make splitTCO more generic

Co-authored-by: IanCaio <iancaio_dev@hotmail.com>

* Prevent resizing of MIDI clips in knife mode

* Fix move/resize and rework box select via ctrl

* Apply suggestions from code review.

Co-authored-by: IanCaio <iancaio_dev@hotmail.com>

* Don't show inaccurate/useless/empty text float in knife mode

* Addresses Github review

	- Fixes a typo where QWidget::mousePressEvent was being called
inside mouseReleaseEvent.
	- Avoids unnecessarily disabling journalling on the Split
action, since it doesn't require it.

* Revert format changes in Track

* Revert format changes in Track.h

* Revert formatting changes in Track.cpp

Co-authored-by: Hyunjin Song <tteu.ingog@gmail.com>
Co-authored-by: IanCaio <iancaio_dev@hotmail.com>
  • Loading branch information
3 people authored Mar 12, 2021
1 parent 266ad8d commit 8acb922
Show file tree
Hide file tree
Showing 14 changed files with 276 additions and 98 deletions.
Binary file added data/themes/classic/cursor_knife.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 6 additions & 5 deletions data/themes/classic/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -598,10 +598,10 @@ FxLine {
color: #e0e0e0;
qproperty-backgroundActive: qlineargradient(spread:reflect, x1:0, y1:0, x2:1, y2:0,
stop:0 #7b838d, stop:1 #6b7581 );
qproperty-strokeOuterActive: rgb( 0, 0, 0 );
qproperty-strokeOuterInactive: rgba( 0, 0, 0, 50 );
qproperty-strokeInnerActive: rgba( 255, 255, 255, 100 );
qproperty-strokeInnerInactive: rgba( 255, 255, 255, 50 );
qproperty-strokeOuterActive: rgb( 0, 0, 0 );
qproperty-strokeOuterInactive: rgba( 0, 0, 0, 50 );
qproperty-strokeInnerActive: rgba( 255, 255, 255, 100 );
qproperty-strokeInnerInactive: rgba( 255, 255, 255, 50 );
}

/* persistent peak markers for fx peak meters */
Expand Down Expand Up @@ -658,7 +658,8 @@ TrackContentObjectView {
qproperty-gradient: true; /* boolean property, set true to have a gradient */
/* finger tip offset of cursor */
qproperty-mouseHotspotHand: 3px 3px;

qproperty-mouseHotspotKnife: 0px 0px;

font-size: 11px;
}

Expand Down
Binary file added data/themes/default/cursor_knife.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion data/themes/default/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,8 @@ TrackContentObjectView {
qproperty-gradient: false; /* boolean property, set true to have a gradient */
/* finger tip offset of cursor */
qproperty-mouseHotspotHand: 7px 2px;

qproperty-mouseHotspotKnife: 0px 0px;

font-size: 11px;
}

Expand Down
2 changes: 1 addition & 1 deletion include/SampleTrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ public slots:
BoolModel m_recordModel;
bool m_isPlaying;


friend class SampleTCOView;


Expand Down Expand Up @@ -132,6 +131,7 @@ public slots:
private:
SampleTCO * m_tco;
QPixmap m_paintPixmap;
bool splitTCO( const TimePos pos ) override;
} ;


Expand Down
8 changes: 5 additions & 3 deletions include/SongEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class SongEditor : public TrackContainerView
enum EditMode
{
DrawMode,
KnifeMode,
SelectMode
};

Expand All @@ -77,6 +78,7 @@ public slots:

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

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

bool allowRubberband() const override;
bool knifeMode() const override;

int trackIndexFromSelectionPoint(int yPos);
int indexOfTrackView(const TrackView* tv);
Expand Down Expand Up @@ -173,6 +176,7 @@ class SongEditorWindow : public Editor
QSize sizeHint() const override;

SongEditor* m_editor;
void syncEditMode();

protected:
void resizeEvent( QResizeEvent * event ) override;
Expand All @@ -194,16 +198,14 @@ protected slots:
void resized();

private:
void keyPressEvent( QKeyEvent * ke ) override;
void keyReleaseEvent( QKeyEvent * ke ) override;

QAction* m_addBBTrackAction;
QAction* m_addSampleTrackAction;
QAction* m_addAutomationTrackAction;
QAction* m_setProportionalSnapAction;

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 @@ -80,6 +80,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
29 changes: 24 additions & 5 deletions include/TrackContentObjectView.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class TrackContentObjectView : public selectableObject, public ModelView
// We have to use a QSize here because using QPoint isn't supported.
// width -> x, height -> y
Q_PROPERTY( QSize mouseHotspotHand WRITE setMouseHotspotHand )
Q_PROPERTY( QSize mouseHotspotKnife WRITE setMouseHotspotKnife )

public:
TrackContentObjectView( TrackContentObject * tco, TrackView * tv );
Expand Down Expand Up @@ -93,6 +94,7 @@ class TrackContentObjectView : public selectableObject, public ModelView
void setBBPatternBackground( const QColor & c );
void setGradient( const bool & b );
void setMouseHotspotHand(const QSize & s);
void setMouseHotspotKnife(const QSize & s);

// access needsUpdate member variable
bool needsUpdate();
Expand All @@ -118,6 +120,9 @@ class TrackContentObjectView : public selectableObject, public ModelView

QColor getColorForDisplay( QColor );

void inline setMarkerPos(int x) { m_markerPos = x; }
void inline setMarkerEnabled(bool e) { m_marker = e; }

public slots:
virtual bool close();
void remove();
Expand All @@ -137,6 +142,13 @@ public slots:
Merge
};

TrackView * m_trackView;
TimePos m_initialTCOPos;
TimePos m_initialTCOEnd;

bool m_marker = false;
int m_markerPos = 0;

virtual void constructContextMenu( QMenu * )
{
}
Expand All @@ -145,7 +157,6 @@ public slots:
void contextMenuAction( ContextMenuAction action );
void dragEnterEvent( QDragEnterEvent * dee ) override;
void dropEvent( QDropEvent * de ) override;
void leaveEvent( QEvent * e ) override;
void mousePressEvent( QMouseEvent * me ) override;
void mouseMoveEvent( QMouseEvent * me ) override;
void mouseReleaseEvent( QMouseEvent * me ) override;
Expand All @@ -155,6 +166,9 @@ public slots:
selectableObject::resizeEvent( re );
}

bool unquantizedModHeld( QMouseEvent * me );
TimePos quantizeSplitPos( TimePos, bool shiftMode );

float pixelsPerBar();


Expand All @@ -176,19 +190,17 @@ protected slots:
MoveSelection,
Resize,
ResizeLeft,
Split,
CopySelection,
ToggleSelected
} ;

static TextFloat * s_textFloat;

TrackContentObject * m_tco;
TrackView * m_trackView;
Actions m_action;
QPoint m_initialMousePos;
QPoint m_initialMouseGlobalPos;
TimePos m_initialTCOPos;
TimePos m_initialTCOEnd;
QVector<TimePos> m_initialOffsets;

TextFloat * m_hint;
Expand All @@ -202,7 +214,10 @@ protected slots:
QColor m_textShadowColor;
QColor m_BBPatternBackground;
bool m_gradient;
QSize m_mouseHotspotHand; // QSize must be used because QPoint isn't supported by property system
QSize m_mouseHotspotHand; // QSize must be used because QPoint
QSize m_mouseHotspotKnife; // isn't supported by property system
QCursor m_cursorHand;
QCursor m_cursorKnife;
bool m_cursorSetYet;

bool m_needsUpdate;
Expand All @@ -217,6 +232,10 @@ protected slots:

bool mouseMovedDistance( QMouseEvent * me, int distance );
TimePos draggedTCOPos( QMouseEvent * me );
int knifeMarkerPos( QMouseEvent * me );
//! Return true iff TCO could be split. Currently only implemented for samples
virtual bool splitTCO( const TimePos pos ){ return false; };
void updateCursor(QMouseEvent * me);
} ;


Expand Down
1 change: 1 addition & 0 deletions include/TrackContentWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public slots:
void dragEnterEvent( QDragEnterEvent * dee ) override;
void dropEvent( QDropEvent * de ) override;
void mousePressEvent( QMouseEvent * me ) override;
void mouseReleaseEvent( QMouseEvent * me ) override;
void paintEvent( QPaintEvent * pe ) override;
void resizeEvent( QResizeEvent * re ) override;

Expand Down
10 changes: 9 additions & 1 deletion src/gui/TrackContainerView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,14 @@ bool TrackContainerView::allowRubberband() const



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




void TrackContainerView::setPixelsPerBar( int ppb )
{
m_ppb = ppb;
Expand Down Expand Up @@ -374,7 +382,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
Loading

0 comments on commit 8acb922

Please sign in to comment.