Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Knife Tool for Sample Clips (Again) #5524

Merged
merged 35 commits into from
Mar 12, 2021
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
c8c710b
Rebase BaraMGB's Knife
Spekular May 29, 2019
c14efd4
Draw marker
Spekular May 29, 2019
6672bfc
Refactoring and shift mode
Spekular Jul 27, 2019
b52fbdb
Allow resizing
Spekular Jul 27, 2019
79fda6f
Add Icon
Spekular Jul 28, 2019
05a2275
Fix stuck marker on RMB, remove unnecessary cast
Spekular Jul 29, 2019
06bccf6
Remove redundant line, more const
Spekular Jul 29, 2019
d1e5de4
Fix
Spekular Jul 29, 2019
18bd074
Review fixes
Spekular Sep 7, 2019
c2c0c3c
Only perform split logic for SampleTCO
Spekular Sep 7, 2019
a519f7c
Add unquantizedModHeld function
Spekular Sep 25, 2019
cfa5389
missed one
Spekular Sep 25, 2019
f05ada0
Merge remote-tracking branch 'upstream/master' into Knife
PhysSong May 3, 2020
aac9c07
Don't use copy/paste
Spekular May 5, 2020
bdde426
Don't use copy/paste
Spekular May 5, 2020
54b2002
Committed too early
Spekular May 5, 2020
8e8cf2c
More git troubles
Spekular May 5, 2020
3f39abf
Fix undo
Spekular May 5, 2020
5b8bd6d
Merge
Spekular May 10, 2020
31b938d
git dammit
Spekular May 10, 2020
902f775
Cleaner solution
Spekular May 22, 2020
e5a818d
Merge branch 'ROT' of https://github.com/Spekular/lmms
Spekular Jun 2, 2020
12d818d
Set cursor, add copy assignment to SampleBuffer
Spekular Jun 2, 2020
e9906bc
Add TODO comment
Spekular Oct 3, 2020
84ff7e7
Merge commit
Spekular Jan 1, 2021
19c31f3
Make it build
Spekular Jan 1, 2021
3a532b3
Fixes from review
Spekular Jan 4, 2021
08aaea3
Make splitTCO virtual
Spekular Jan 5, 2021
22a8d47
Make splitTCO more generic
Spekular Jan 14, 2021
4782994
Prevent resizing of MIDI clips in knife mode
Spekular Jan 14, 2021
245160d
Fix move/resize and rework box select via ctrl
Spekular Jan 16, 2021
d498802
Apply suggestions from code review.
Spekular Jan 26, 2021
81fc127
Don't show inaccurate/useless/empty text float in knife mode
Spekular Jan 26, 2021
4c604d8
Addresses Github review
IanCaio Feb 12, 2021
6fb38c4
Revert format changes in Track
Spekular Mar 12, 2021
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
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.
Binary file added data/themes/classic/edit_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 @@ -564,10 +564,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 @@ -624,7 +624,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.
Binary file added data/themes/default/edit_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 @@ -662,7 +662,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
5 changes: 4 additions & 1 deletion include/SampleBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class LMMS_EXPORT SampleBuffer : public QObject, public sharedObject
{
m_isBackwards = _backwards;
}

int interpolationMode() const
{
return m_interpolationMode;
Expand All @@ -109,6 +109,9 @@ class LMMS_EXPORT SampleBuffer : public QObject, public sharedObject
SampleBuffer( const QString & _audio_file, bool _is_base64_data = false );
SampleBuffer( const sampleFrame * _data, const f_cnt_t _frames );
explicit SampleBuffer( const f_cnt_t _frames );
SampleBuffer( const SampleBuffer& orig );

SampleBuffer& operator= ( const SampleBuffer& that );

virtual ~SampleBuffer();

Expand Down
15 changes: 15 additions & 0 deletions include/SampleTrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,12 @@ class SampleTCO : public TrackContentObject
mapPropertyFromModel(bool,isRecord,setRecord,m_recordModel);
public:
SampleTCO( Track * _track );
SampleTCO( const SampleTCO& orig );
virtual ~SampleTCO();

//According to the Rule of Three we should have this
//SampleTCO& operator= ( const SampleTCO& that );

void changeLength( const MidiTime & _length ) override;
const QString & sampleFile() const;

Expand All @@ -74,6 +78,15 @@ class SampleTCO : public TrackContentObject
bool isPlaying() const;
void setIsPlaying(bool isPlaying);

void inline setMarkerPos( int x )
{
m_markerPos = x;
}
void inline setMarkerEnabled( bool e )
{
m_marker = e;
}
Spekular marked this conversation as resolved.
Show resolved Hide resolved

public slots:
void setSampleBuffer( SampleBuffer* sb );
void setSampleFile( const QString & _sf );
Expand All @@ -88,6 +101,8 @@ public slots:
BoolModel m_recordModel;
bool m_isPlaying;

bool m_marker = false;
int m_markerPos = 0;

friend class SampleTCOView;

Expand Down
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 @@ -85,6 +86,7 @@ public slots:

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

Expand Down Expand Up @@ -120,6 +122,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 @@ -209,6 +212,7 @@ protected slots:

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

Expand Down
11 changes: 10 additions & 1 deletion include/Track.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,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 @@ -245,6 +246,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 Down Expand Up @@ -295,6 +297,7 @@ protected slots:
MoveSelection,
Resize,
ResizeLeft,
Split,
CopySelection,
ToggleSelected
} ;
Expand All @@ -321,7 +324,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 @@ -335,7 +341,10 @@ protected slots:
void setInitialOffsets();

bool mouseMovedDistance( QMouseEvent * me, int distance );
bool unquantizedModHeld( QMouseEvent * me );
MidiTime draggedTCOPos( QMouseEvent * me );
int knifeMarkerPos( QMouseEvent * me );
MidiTime quantizeMarkerPos( MidiTime, bool shiftMode );
} ;


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
52 changes: 50 additions & 2 deletions src/core/SampleBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,54 @@ SampleBuffer::SampleBuffer( const f_cnt_t _frames )



SampleBuffer::SampleBuffer( const SampleBuffer& orig ):
m_audioFile( orig.m_audioFile ),
m_origData( MM_ALLOC( sampleFrame, orig.m_origFrames ) ),
m_origFrames( orig.m_origFrames ),
m_data( MM_ALLOC( sampleFrame, orig.m_frames ) ),
m_frames( orig.m_frames ),
m_startFrame( orig.m_startFrame ),
m_endFrame( orig.m_endFrame ),
m_loopStartFrame( orig.m_loopStartFrame ),
m_loopEndFrame( orig.m_loopEndFrame ),
m_amplification( orig.m_amplification ),
m_reversed( orig.m_reversed ),
m_frequency( orig.m_frequency ),
m_sampleRate( orig.m_sampleRate )
{
//Deep copy m_origData and m_data from original
memcpy( m_origData, orig.m_origData, m_origFrames * BYTES_PER_FRAME );
memcpy( m_data, orig.m_data, m_frames * BYTES_PER_FRAME );
}




SampleBuffer& SampleBuffer::operator=( const SampleBuffer& that )
{
m_audioFile = that.m_audioFile;
m_origData = MM_ALLOC( sampleFrame, that.m_origFrames );
m_origFrames = that.m_origFrames;
m_data = MM_ALLOC( sampleFrame, that.m_frames );
m_frames = that.m_frames;
m_startFrame = that.m_startFrame;
m_endFrame = that.m_endFrame;
m_loopStartFrame = that.m_loopStartFrame;
m_loopEndFrame = that.m_loopEndFrame;
m_amplification = that.m_amplification;
m_reversed = that.m_reversed;
m_frequency = that.m_frequency;
m_sampleRate = that.m_sampleRate;
memcpy( m_origData, that.m_origData, m_origFrames * BYTES_PER_FRAME );
memcpy( m_data, that.m_data, m_frames * BYTES_PER_FRAME );
update();

return *this;
}




SampleBuffer::~SampleBuffer()
{
MM_FREE( m_origData );
Expand Down Expand Up @@ -781,7 +829,7 @@ bool SampleBuffer::play( sampleFrame * _ab, handleState * _state,
}
}

if( tmp != NULL )
if( tmp != NULL )
{
MM_FREE( tmp );
}
Expand Down Expand Up @@ -1488,7 +1536,7 @@ SampleBuffer::handleState::handleState( bool _varying_pitch, int interpolation_m
{
int error;
m_interpolationMode = interpolation_mode;

if( ( m_resamplingData = src_new( interpolation_mode, DEFAULT_CHANNELS, &error ) ) == NULL )
{
qDebug( "Error: src_new() failed in sample_buffer.cpp!\n" );
Expand Down
Loading