From b9c8f20513bb0fa96defcc7a1af260ce51a35b72 Mon Sep 17 00:00:00 2001 From: Steffen Baranowsky Date: Tue, 4 Apr 2017 13:32:32 +0200 Subject: [PATCH 01/11] resize sampletrack from start (gui) --- include/SampleTrack.h | 4 ++++ include/Track.h | 1 + src/core/Track.cpp | 48 +++++++++++++++++++++++++++++++++++--- src/tracks/SampleTrack.cpp | 30 +++++++++++++++++++++--- 4 files changed, 77 insertions(+), 6 deletions(-) diff --git a/include/SampleTrack.h b/include/SampleTrack.h index 25841486cf4..48fd5c2abd4 100644 --- a/include/SampleTrack.h +++ b/include/SampleTrack.h @@ -58,6 +58,7 @@ class SampleTCO : public TrackContentObject return m_sampleBuffer; } + void setStartTimeOffset( MidiTime startTime ); MidiTime sampleLength() const; void setSampleStartFrame( f_cnt_t startFrame ); void setSamplePlayLength( f_cnt_t length ); @@ -67,6 +68,8 @@ class SampleTCO : public TrackContentObject bool isPlaying() const; void setIsPlaying(bool isPlaying); + MidiTime startTimeOffset() const; + public slots: void setSampleBuffer( SampleBuffer* sb ); void setSampleFile( const QString & _sf ); @@ -80,6 +83,7 @@ public slots: SampleBuffer* m_sampleBuffer; BoolModel m_recordModel; bool m_isPlaying; + MidiTime m_startTimeOffset; friend class SampleTCOView; diff --git a/include/Track.h b/include/Track.h index dcb1648e0f5..0374fdbe9ba 100644 --- a/include/Track.h +++ b/include/Track.h @@ -276,6 +276,7 @@ protected slots: Move, MoveSelection, Resize, + ResizeFront, CopySelection, ToggleSelected } ; diff --git a/src/core/Track.cpp b/src/core/Track.cpp index 65187f552d8..b2c50c1d12f 100644 --- a/src/core/Track.cpp +++ b/src/core/Track.cpp @@ -67,7 +67,7 @@ #include "SongEditor.h" #include "StringPairDrag.h" #include "TextFloat.h" - +#include /*! The width of the resize grip in pixels */ @@ -697,8 +697,25 @@ void TrackContentObjectView::mousePressEvent( QMouseEvent * me ) m_tco->setJournalling( false ); setInitialMousePos( me->pos() ); - - if( me->x() < width() - RESIZE_GRIP_WIDTH ) + if( me->x() < RESIZE_GRIP_WIDTH ) + { + m_action = ResizeFront; + m_oldTime = m_tco->startPosition(); + QCursor c( Qt::SizeHorCursor ); + QApplication::setOverrideCursor( c ); + s_textFloat->setTitle( tr( "Current length" ) ); + delete m_hint; + m_hint = TextFloat::displayMessage( tr( "Hint" ), + tr( "Press <%1> for free " + "resizing." ).arg( + #ifdef LMMS_BUILD_APPLE + "⌘"), + #else + "Ctrl"), + #endif + embed::getIconPixmap( "hint" ), 0 ); + } + else if( me->x() < width() - RESIZE_GRIP_WIDTH ) { m_action = Move; m_oldTime = m_tco->startPosition(); @@ -909,6 +926,31 @@ void TrackContentObjectView::mouseMoveEvent( QMouseEvent * me ) s_textFloat->moveGlobal( this, QPoint( width() + 2, height() + 2) ); } + else if( m_action == ResizeFront ) + { + SampleTCO * sTco = dynamic_cast( m_tco ); + if( sTco ) + { + + const int x = mapToParent( me->pos() ).x() - m_initialMousePos.x(); + + MidiTime t = qMax( 0, (int) + m_trackView->trackContainerView()->currentPosition()+ + static_cast( x * MidiTime::ticksPerTact() / + ppt ) ); + if( ! ( me->modifiers() & Qt::ControlModifier ) + && me->button() == Qt::NoButton ) + { + t = t.toNearestTact(); + } + MidiTime oldPos = m_tco->startPosition(); + m_tco->movePosition( t ); + m_trackView->getTrackContentWidget()->changePosition(); + m_tco->changeLength( m_tco->length() + ( oldPos - t ) ); + sTco->setStartTimeOffset( sTco->startTimeOffset() + ( oldPos - t ) ); + } + + } else { if( me->x() > width() - RESIZE_GRIP_WIDTH && !me->buttons() && !m_tco->getAutoResize() ) diff --git a/src/tracks/SampleTrack.cpp b/src/tracks/SampleTrack.cpp index 2152c0cc1b1..2ed285d16bb 100644 --- a/src/tracks/SampleTrack.cpp +++ b/src/tracks/SampleTrack.cpp @@ -48,7 +48,7 @@ #include "Mixer.h" #include "EffectRackView.h" #include "TrackLabelButton.h" - +#include SampleTCO::SampleTCO( Track * _track ) : TrackContentObject( _track ), m_sampleBuffer( new SampleBuffer ), @@ -184,11 +184,22 @@ void SampleTCO::updateTrackTcos() } } +MidiTime SampleTCO::startTimeOffset() const +{ + return m_startTimeOffset; +} + + + + bool SampleTCO::isPlaying() const { return m_isPlaying; } + + + void SampleTCO::setIsPlaying(bool isPlaying) { m_isPlaying = isPlaying; @@ -271,6 +282,14 @@ void SampleTCO::loadSettings( const QDomElement & _this ) +void SampleTCO::setStartTimeOffset( MidiTime startTime ) +{ + m_startTimeOffset = startTime; +} + + + + TrackContentObjectView * SampleTCO::createView( TrackView * _tv ) { return new SampleTCOView( this, _tv ); @@ -370,6 +389,8 @@ void SampleTCOView::dragEnterEvent( QDragEnterEvent * _dee ) + + void SampleTCOView::dropEvent( QDropEvent * _de ) { if( StringPairDrag::decodeKey( _de ) == "samplefile" ) @@ -497,8 +518,10 @@ void SampleTCOView::paintEvent( QPaintEvent * pe ) float nom = Engine::getSong()->getTimeSigModel().getNumerator(); float den = Engine::getSong()->getTimeSigModel().getDenominator(); float ticksPerTact = DefaultTicksPerTact * nom / den; - - QRect r = QRect( TCO_BORDER_WIDTH, spacing, + + float offset = m_tco->startTimeOffset() / ticksPerTact * pixelsPerTact(); + qDebug() << offset << (int) offset ; + QRect r = QRect( TCO_BORDER_WIDTH + offset, spacing, qMax( static_cast( m_tco->sampleLength() * ppt / ticksPerTact ), 1 ), rect().bottom() - 2 * spacing ); m_tco->m_sampleBuffer->visualize( p, r, pe->rect() ); @@ -601,6 +624,7 @@ bool SampleTrack::play( const MidiTime & _start, const fpp_t _frames, TrackContentObject * tco = getTCO( i ); SampleTCO * sTco = dynamic_cast( tco ); float framesPerTick = Engine::framesPerTick(); + if( _start >= sTco->startPosition() && _start < sTco->endPosition() ) { if( sTco->isPlaying() == false ) From 92099b2a65914563f94197f34306df25dd9a9bcd Mon Sep 17 00:00:00 2001 From: Steffen Baranowsky Date: Tue, 4 Apr 2017 14:55:10 +0200 Subject: [PATCH 02/11] resize sampletrack from start (sample) --- src/tracks/SampleTrack.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/tracks/SampleTrack.cpp b/src/tracks/SampleTrack.cpp index 2ed285d16bb..cc0fb4376e0 100644 --- a/src/tracks/SampleTrack.cpp +++ b/src/tracks/SampleTrack.cpp @@ -627,10 +627,10 @@ bool SampleTrack::play( const MidiTime & _start, const fpp_t _frames, if( _start >= sTco->startPosition() && _start < sTco->endPosition() ) { - if( sTco->isPlaying() == false ) + if( sTco->isPlaying() == false && _start > sTco->startPosition() + sTco->startTimeOffset() ) { - f_cnt_t sampleStart = framesPerTick * ( _start - sTco->startPosition() ); - f_cnt_t tcoFrameLength = framesPerTick * ( sTco->endPosition() - sTco->startPosition() ); + f_cnt_t sampleStart = framesPerTick * ( (_start - sTco->startPosition() ) - sTco->startTimeOffset() ); + f_cnt_t tcoFrameLength = framesPerTick * ( sTco->endPosition() - sTco->startPosition() - sTco->startTimeOffset() ); f_cnt_t sampleBufferLength = sTco->sampleBuffer()->frames(); //if the Tco smaller than the sample length we play only until Tco end //else we play the sample to the end but nothing more From f8ae969a972c0d166f13738b2f97d272043f2326 Mon Sep 17 00:00:00 2001 From: Steffen Baranowsky Date: Wed, 5 Apr 2017 16:27:18 +0200 Subject: [PATCH 03/11] code clean up --- include/Track.h | 2 +- src/core/Track.cpp | 49 +++++++++++++++++++++++++++++++------- src/tracks/SampleTrack.cpp | 5 ++-- 3 files changed, 45 insertions(+), 11 deletions(-) diff --git a/include/Track.h b/include/Track.h index 0374fdbe9ba..de0abef0f6f 100644 --- a/include/Track.h +++ b/include/Track.h @@ -276,7 +276,7 @@ protected slots: Move, MoveSelection, Resize, - ResizeFront, + ResizeLeft, CopySelection, ToggleSelected } ; diff --git a/src/core/Track.cpp b/src/core/Track.cpp index b2c50c1d12f..384327d30d3 100644 --- a/src/core/Track.cpp +++ b/src/core/Track.cpp @@ -697,9 +697,10 @@ void TrackContentObjectView::mousePressEvent( QMouseEvent * me ) m_tco->setJournalling( false ); setInitialMousePos( me->pos() ); - if( me->x() < RESIZE_GRIP_WIDTH ) + SampleTCO * sTco = dynamic_cast( m_tco ); + if( me->x() < RESIZE_GRIP_WIDTH && sTco ) { - m_action = ResizeFront; + m_action = ResizeLeft; m_oldTime = m_tco->startPosition(); QCursor c( Qt::SizeHorCursor ); QApplication::setOverrideCursor( c ); @@ -926,12 +927,11 @@ void TrackContentObjectView::mouseMoveEvent( QMouseEvent * me ) s_textFloat->moveGlobal( this, QPoint( width() + 2, height() + 2) ); } - else if( m_action == ResizeFront ) + else if( m_action == ResizeLeft ) { SampleTCO * sTco = dynamic_cast( m_tco ); if( sTco ) { - const int x = mapToParent( me->pos() ).x() - m_initialMousePos.x(); MidiTime t = qMax( 0, (int) @@ -944,10 +944,25 @@ void TrackContentObjectView::mouseMoveEvent( QMouseEvent * me ) t = t.toNearestTact(); } MidiTime oldPos = m_tco->startPosition(); - m_tco->movePosition( t ); - m_trackView->getTrackContentWidget()->changePosition(); - m_tco->changeLength( m_tco->length() + ( oldPos - t ) ); - sTco->setStartTimeOffset( sTco->startTimeOffset() + ( oldPos - t ) ); + if( m_tco->length() + ( oldPos - t ) >= MidiTime::ticksPerTact() ) + { + m_tco->movePosition( t ); + m_trackView->getTrackContentWidget()->changePosition(); + m_tco->changeLength( m_tco->length() + ( oldPos - t ) ); + sTco->setStartTimeOffset( sTco->startTimeOffset() + ( oldPos - t ) ); + s_textFloat->setText( tr( "%1:%2 (%3:%4 to %5:%6)" ). + arg( m_tco->length().getTact() ). + arg( m_tco->length().getTicks() % + MidiTime::ticksPerTact() ). + arg( m_tco->startPosition().getTact() + 1 ). + arg( m_tco->startPosition().getTicks() % + MidiTime::ticksPerTact() ). + arg( m_tco->endPosition().getTact() + 1 ). + arg( m_tco->endPosition().getTicks() % + MidiTime::ticksPerTact() ) ); + s_textFloat->moveGlobal( this, QPoint( width() + 2, + height() + 2) ); + } } } @@ -967,6 +982,24 @@ void TrackContentObjectView::mouseMoveEvent( QMouseEvent * me ) QCursor c( Qt::SizeHorCursor ); QApplication::setOverrideCursor( c ); } + else if( me->x() < RESIZE_GRIP_WIDTH && !me->buttons() ) + { + SampleTCO * sTco = dynamic_cast( m_tco ); + if( sTco ) + { + if( QApplication::overrideCursor() != NULL && + QApplication::overrideCursor()->shape() != + Qt::SizeHorCursor ) + { + while( QApplication::overrideCursor() != NULL ) + { + QApplication::restoreOverrideCursor(); + } + } + QCursor c( Qt::SizeHorCursor ); + QApplication::setOverrideCursor( c ); + } + } else { leaveEvent( NULL ); diff --git a/src/tracks/SampleTrack.cpp b/src/tracks/SampleTrack.cpp index cc0fb4376e0..2933233ea42 100644 --- a/src/tracks/SampleTrack.cpp +++ b/src/tracks/SampleTrack.cpp @@ -325,6 +325,7 @@ SampleTCOView::~SampleTCOView() void SampleTCOView::updateSample() { + m_tco->setStartTimeOffset( 0 ); update(); // set tooltip to filename so that user can see what sample this // sample-tco contains @@ -520,7 +521,6 @@ void SampleTCOView::paintEvent( QPaintEvent * pe ) float ticksPerTact = DefaultTicksPerTact * nom / den; float offset = m_tco->startTimeOffset() / ticksPerTact * pixelsPerTact(); - qDebug() << offset << (int) offset ; QRect r = QRect( TCO_BORDER_WIDTH + offset, spacing, qMax( static_cast( m_tco->sampleLength() * ppt / ticksPerTact ), 1 ), rect().bottom() - 2 * spacing ); m_tco->m_sampleBuffer->visualize( p, r, pe->rect() ); @@ -528,11 +528,12 @@ void SampleTCOView::paintEvent( QPaintEvent * pe ) // disable antialiasing for borders, since its not needed p.setRenderHint( QPainter::Antialiasing, false ); - if( r.width() < width() - 1 ) + if( r.width() + offset < width() - 1 ) { p.drawLine( r.x(), r.y() + r.height() / 2, rect().right() - TCO_BORDER_WIDTH, r.y() + r.height() / 2 ); } + p.drawLine( 1, height() / 2, offset + 1, height() / 2 ); // inner border p.setPen( c.lighter( 160 ) ); From 9eb7b7294cc5b5d76c2d540b27b97949cb08db80 Mon Sep 17 00:00:00 2001 From: Steffen Baranowsky Date: Fri, 7 Apr 2017 14:02:39 +0200 Subject: [PATCH 04/11] save/load project with left resized sampletrack works --- src/core/Track.cpp | 4 ++-- src/tracks/SampleTrack.cpp | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/core/Track.cpp b/src/core/Track.cpp index 384327d30d3..179832fdc54 100644 --- a/src/core/Track.cpp +++ b/src/core/Track.cpp @@ -67,7 +67,7 @@ #include "SongEditor.h" #include "StringPairDrag.h" #include "TextFloat.h" -#include + /*! The width of the resize grip in pixels */ @@ -1029,7 +1029,7 @@ void TrackContentObjectView::mouseReleaseEvent( QMouseEvent * me ) setSelected( !isSelected() ); } - if( m_action == Move || m_action == Resize ) + if( m_action == Move || m_action == Resize || m_action == ResizeLeft ) { m_tco->setJournalling( true ); } diff --git a/src/tracks/SampleTrack.cpp b/src/tracks/SampleTrack.cpp index 2933233ea42..0a04b9286f4 100644 --- a/src/tracks/SampleTrack.cpp +++ b/src/tracks/SampleTrack.cpp @@ -48,7 +48,7 @@ #include "Mixer.h" #include "EffectRackView.h" #include "TrackLabelButton.h" -#include + SampleTCO::SampleTCO( Track * _track ) : TrackContentObject( _track ), m_sampleBuffer( new SampleBuffer ), @@ -148,6 +148,7 @@ void SampleTCO::setSampleBuffer( SampleBuffer* sb ) void SampleTCO::setSampleFile( const QString & _sf ) { m_sampleBuffer->setAudioFile( _sf ); + setStartTimeOffset( 0 ); updateLength(); emit sampleChanged(); @@ -253,6 +254,7 @@ void SampleTCO::saveSettings( QDomDocument & _doc, QDomElement & _this ) _this.setAttribute( "len", length() ); _this.setAttribute( "muted", isMuted() ); _this.setAttribute( "src", sampleFile() ); + _this.setAttribute( "off", startTimeOffset() ); if( sampleFile() == "" ) { QString s; @@ -277,6 +279,7 @@ void SampleTCO::loadSettings( const QDomElement & _this ) } changeLength( _this.attribute( "len" ).toInt() ); setMuted( _this.attribute( "muted" ).toInt() ); + setStartTimeOffset( _this.attribute( "off" ).toInt() ); } @@ -325,7 +328,6 @@ SampleTCOView::~SampleTCOView() void SampleTCOView::updateSample() { - m_tco->setStartTimeOffset( 0 ); update(); // set tooltip to filename so that user can see what sample this // sample-tco contains @@ -625,12 +627,11 @@ bool SampleTrack::play( const MidiTime & _start, const fpp_t _frames, TrackContentObject * tco = getTCO( i ); SampleTCO * sTco = dynamic_cast( tco ); float framesPerTick = Engine::framesPerTick(); - if( _start >= sTco->startPosition() && _start < sTco->endPosition() ) { if( sTco->isPlaying() == false && _start > sTco->startPosition() + sTco->startTimeOffset() ) { - f_cnt_t sampleStart = framesPerTick * ( (_start - sTco->startPosition() ) - sTco->startTimeOffset() ); + f_cnt_t sampleStart = framesPerTick * ( _start - sTco->startPosition() - sTco->startTimeOffset() ); f_cnt_t tcoFrameLength = framesPerTick * ( sTco->endPosition() - sTco->startPosition() - sTco->startTimeOffset() ); f_cnt_t sampleBufferLength = sTco->sampleBuffer()->frames(); //if the Tco smaller than the sample length we play only until Tco end From 25fb7b21497d713c571ad10e378cad29218c2d04 Mon Sep 17 00:00:00 2001 From: Steffen Baranowsky Date: Tue, 11 Apr 2017 15:53:35 +0200 Subject: [PATCH 05/11] code improvements Part I --- include/SampleTrack.h | 5 +---- include/Track.h | 4 ++++ src/core/Track.cpp | 42 +++++++++++++++++++++----------------- src/tracks/SampleTrack.cpp | 13 ------------ 4 files changed, 28 insertions(+), 36 deletions(-) diff --git a/include/SampleTrack.h b/include/SampleTrack.h index 48fd5c2abd4..147e5bee348 100644 --- a/include/SampleTrack.h +++ b/include/SampleTrack.h @@ -58,7 +58,6 @@ class SampleTCO : public TrackContentObject return m_sampleBuffer; } - void setStartTimeOffset( MidiTime startTime ); MidiTime sampleLength() const; void setSampleStartFrame( f_cnt_t startFrame ); void setSamplePlayLength( f_cnt_t length ); @@ -68,8 +67,7 @@ class SampleTCO : public TrackContentObject bool isPlaying() const; void setIsPlaying(bool isPlaying); - MidiTime startTimeOffset() const; - + public slots: void setSampleBuffer( SampleBuffer* sb ); void setSampleFile( const QString & _sf ); @@ -83,7 +81,6 @@ public slots: SampleBuffer* m_sampleBuffer; BoolModel m_recordModel; bool m_isPlaying; - MidiTime m_startTimeOffset; friend class SampleTCOView; diff --git a/include/Track.h b/include/Track.h index de0abef0f6f..c97cebb5306 100644 --- a/include/Track.h +++ b/include/Track.h @@ -149,6 +149,9 @@ class TrackContentObject : public Model, public JournallingObject /// Returns true if and only if a->startPosition() < b->startPosition() static bool comparePosition(const TrackContentObject* a, const TrackContentObject* b); + MidiTime startTimeOffset() const; + void setStartTimeOffset(const MidiTime &startTimeOffset); + public slots: void copy(); void paste(); @@ -174,6 +177,7 @@ public slots: MidiTime m_startPosition; MidiTime m_length; + MidiTime m_startTimeOffset; BoolModel m_mutedModel; BoolModel m_soloModel; diff --git a/src/core/Track.cpp b/src/core/Track.cpp index 179832fdc54..8afec11b07b 100644 --- a/src/core/Track.cpp +++ b/src/core/Track.cpp @@ -166,6 +166,9 @@ void TrackContentObject::changeLength( const MidiTime & length ) emit lengthChanged(); } + + + bool TrackContentObject::comparePosition(const TrackContentObject *a, const TrackContentObject *b) { return a->startPosition() < b->startPosition(); @@ -224,6 +227,22 @@ void TrackContentObject::toggleMute() +MidiTime TrackContentObject::startTimeOffset() const +{ + return m_startTimeOffset; +} + + + + +void TrackContentObject::setStartTimeOffset( const MidiTime &startTimeOffset ) +{ + m_startTimeOffset = startTimeOffset; +} + + + + @@ -968,7 +987,9 @@ void TrackContentObjectView::mouseMoveEvent( QMouseEvent * me ) } else { - if( me->x() > width() - RESIZE_GRIP_WIDTH && !me->buttons() && !m_tco->getAutoResize() ) + SampleTCO * sTco = dynamic_cast( m_tco ); + if( ( me->x() > width() - RESIZE_GRIP_WIDTH && !me->buttons() && !m_tco->getAutoResize() ) + || ( me->x() < RESIZE_GRIP_WIDTH && !me->buttons() && sTco ) ) { if( QApplication::overrideCursor() != NULL && QApplication::overrideCursor()->shape() != @@ -982,24 +1003,6 @@ void TrackContentObjectView::mouseMoveEvent( QMouseEvent * me ) QCursor c( Qt::SizeHorCursor ); QApplication::setOverrideCursor( c ); } - else if( me->x() < RESIZE_GRIP_WIDTH && !me->buttons() ) - { - SampleTCO * sTco = dynamic_cast( m_tco ); - if( sTco ) - { - if( QApplication::overrideCursor() != NULL && - QApplication::overrideCursor()->shape() != - Qt::SizeHorCursor ) - { - while( QApplication::overrideCursor() != NULL ) - { - QApplication::restoreOverrideCursor(); - } - } - QCursor c( Qt::SizeHorCursor ); - QApplication::setOverrideCursor( c ); - } - } else { leaveEvent( NULL ); @@ -1031,6 +1034,7 @@ void TrackContentObjectView::mouseReleaseEvent( QMouseEvent * me ) if( m_action == Move || m_action == Resize || m_action == ResizeLeft ) { + // TODO: Fix m_tco->setJournalling() consistency m_tco->setJournalling( true ); } m_action = NoAction; diff --git a/src/tracks/SampleTrack.cpp b/src/tracks/SampleTrack.cpp index 0a04b9286f4..203a1b6ff97 100644 --- a/src/tracks/SampleTrack.cpp +++ b/src/tracks/SampleTrack.cpp @@ -185,11 +185,6 @@ void SampleTCO::updateTrackTcos() } } -MidiTime SampleTCO::startTimeOffset() const -{ - return m_startTimeOffset; -} - @@ -285,14 +280,6 @@ void SampleTCO::loadSettings( const QDomElement & _this ) -void SampleTCO::setStartTimeOffset( MidiTime startTime ) -{ - m_startTimeOffset = startTime; -} - - - - TrackContentObjectView * SampleTCO::createView( TrackView * _tv ) { return new SampleTCOView( this, _tv ); From d6701d162aab56a46be11d2370759d2804311b54 Mon Sep 17 00:00:00 2001 From: Steffen Baranowksy Date: Mon, 17 Apr 2017 14:49:13 +0200 Subject: [PATCH 06/11] fixes / some spaces --- src/tracks/SampleTrack.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/tracks/SampleTrack.cpp b/src/tracks/SampleTrack.cpp index 203a1b6ff97..91efdfba4e4 100644 --- a/src/tracks/SampleTrack.cpp +++ b/src/tracks/SampleTrack.cpp @@ -196,7 +196,7 @@ bool SampleTCO::isPlaying() const -void SampleTCO::setIsPlaying(bool isPlaying) +void SampleTCO::setIsPlaying( bool isPlaying ) { m_isPlaying = isPlaying; } @@ -206,7 +206,7 @@ void SampleTCO::setIsPlaying(bool isPlaying) void SampleTCO::updateLength() { - changeLength( sampleLength() ); + changeLength( sampleLength() + startTimeOffset() ); } @@ -220,7 +220,7 @@ MidiTime SampleTCO::sampleLength() const -void SampleTCO::setSampleStartFrame(f_cnt_t startFrame) +void SampleTCO::setSampleStartFrame( f_cnt_t startFrame ) { m_sampleBuffer->setStartFrame( startFrame ); } @@ -228,7 +228,7 @@ void SampleTCO::setSampleStartFrame(f_cnt_t startFrame) -void SampleTCO::setSamplePlayLength(f_cnt_t length) +void SampleTCO::setSamplePlayLength( f_cnt_t length ) { m_sampleBuffer->setEndFrame( length ); } @@ -431,7 +431,7 @@ void SampleTCOView::mousePressEvent( QMouseEvent * _me ) -void SampleTCOView::mouseReleaseEvent(QMouseEvent *_me) +void SampleTCOView::mouseReleaseEvent( QMouseEvent *_me ) { if( _me->button() == Qt::MiddleButton && !_me->modifiers() ) { From b8e9248a62cbc3500047b0f0c73fda76b786c408 Mon Sep 17 00:00:00 2001 From: Steffen Baranowsky Date: Tue, 2 May 2017 14:15:28 +0200 Subject: [PATCH 07/11] improve resizing --- include/SampleTrack.h | 5 +++-- src/core/Track.cpp | 3 +-- src/tracks/SampleTrack.cpp | 22 ++++++++++++++++++++++ 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/include/SampleTrack.h b/include/SampleTrack.h index 147e5bee348..ffc14a77ae2 100644 --- a/include/SampleTrack.h +++ b/include/SampleTrack.h @@ -67,7 +67,8 @@ class SampleTCO : public TrackContentObject bool isPlaying() const; void setIsPlaying(bool isPlaying); - + MidiTime startTimeOffset() const; + void setStartTimeOffset(const MidiTime &startTimeOffset); public slots: void setSampleBuffer( SampleBuffer* sb ); void setSampleFile( const QString & _sf ); @@ -81,7 +82,7 @@ public slots: SampleBuffer* m_sampleBuffer; BoolModel m_recordModel; bool m_isPlaying; - + f_cnt_t m_startTimeOffset; friend class SampleTCOView; diff --git a/src/core/Track.cpp b/src/core/Track.cpp index 8afec11b07b..cfbbc63427c 100644 --- a/src/core/Track.cpp +++ b/src/core/Track.cpp @@ -68,7 +68,6 @@ #include "StringPairDrag.h" #include "TextFloat.h" - /*! The width of the resize grip in pixels */ const int RESIZE_GRIP_WIDTH = 4; @@ -963,7 +962,7 @@ void TrackContentObjectView::mouseMoveEvent( QMouseEvent * me ) t = t.toNearestTact(); } MidiTime oldPos = m_tco->startPosition(); - if( m_tco->length() + ( oldPos - t ) >= MidiTime::ticksPerTact() ) + if( t >= sTco->startPosition() + sTco->startTimeOffset() && m_tco->length() + ( oldPos - t ) >= MidiTime::ticksPerTact() ) { m_tco->movePosition( t ); m_trackView->getTrackContentWidget()->changePosition(); diff --git a/src/tracks/SampleTrack.cpp b/src/tracks/SampleTrack.cpp index 91efdfba4e4..7726439b25a 100644 --- a/src/tracks/SampleTrack.cpp +++ b/src/tracks/SampleTrack.cpp @@ -204,6 +204,28 @@ void SampleTCO::setIsPlaying( bool isPlaying ) +MidiTime SampleTCO::startTimeOffset() const +{ + float stoF = m_startTimeOffset / Engine::framesPerTick(); + MidiTime sto = m_startTimeOffset / Engine::framesPerTick(); + if( stoF < (float) sto ) + { + sto = sto-1; + } + return sto; +} + + + + +void SampleTCO::setStartTimeOffset( const MidiTime &startTimeOffset ) +{ + m_startTimeOffset = startTimeOffset * Engine::framesPerTick(); +} + + + + void SampleTCO::updateLength() { changeLength( sampleLength() + startTimeOffset() ); From 0849eecddf4a4e90b9f21d660523157859ca7587 Mon Sep 17 00:00:00 2001 From: Steffen Baranowsky Date: Wed, 3 May 2017 14:42:15 +0200 Subject: [PATCH 08/11] refactor startTimeOffset(positive values)/change offset on tempochange --- include/SampleTrack.h | 5 ++-- src/core/Track.cpp | 17 +++++++------ src/tracks/SampleTrack.cpp | 49 +++++++++++++++----------------------- 3 files changed, 31 insertions(+), 40 deletions(-) diff --git a/include/SampleTrack.h b/include/SampleTrack.h index ffc14a77ae2..66eaae155e4 100644 --- a/include/SampleTrack.h +++ b/include/SampleTrack.h @@ -67,8 +67,6 @@ class SampleTCO : public TrackContentObject bool isPlaying() const; void setIsPlaying(bool isPlaying); - MidiTime startTimeOffset() const; - void setStartTimeOffset(const MidiTime &startTimeOffset); public slots: void setSampleBuffer( SampleBuffer* sb ); void setSampleFile( const QString & _sf ); @@ -76,13 +74,14 @@ public slots: void toggleRecord(); void playbackPositionChanged(); void updateTrackTcos(); + void tempoChanged(); private: SampleBuffer* m_sampleBuffer; BoolModel m_recordModel; bool m_isPlaying; - f_cnt_t m_startTimeOffset; + float m_currentFramesPerTick; friend class SampleTCOView; diff --git a/src/core/Track.cpp b/src/core/Track.cpp index cfbbc63427c..83bf71f5a50 100644 --- a/src/core/Track.cpp +++ b/src/core/Track.cpp @@ -952,22 +952,25 @@ void TrackContentObjectView::mouseMoveEvent( QMouseEvent * me ) { const int x = mapToParent( me->pos() ).x() - m_initialMousePos.x(); - MidiTime t = qMax( 0, (int) - m_trackView->trackContainerView()->currentPosition()+ + MidiTime t = (int) m_trackView->trackContainerView()->currentPosition() + static_cast( x * MidiTime::ticksPerTact() / - ppt ) ); + ppt ); if( ! ( me->modifiers() & Qt::ControlModifier ) && me->button() == Qt::NoButton ) { t = t.toNearestTact(); } - MidiTime oldPos = m_tco->startPosition(); - if( t >= sTco->startPosition() + sTco->startTimeOffset() && m_tco->length() + ( oldPos - t ) >= MidiTime::ticksPerTact() ) + if( t < sTco->startPosition() - sTco->startTimeOffset() ) + { + t = sTco->startPosition() - sTco->startTimeOffset(); + } + MidiTime offset = t - m_tco->startPosition(); + if( m_tco->length() - offset >= MidiTime::ticksPerTact() ) { m_tco->movePosition( t ); m_trackView->getTrackContentWidget()->changePosition(); - m_tco->changeLength( m_tco->length() + ( oldPos - t ) ); - sTco->setStartTimeOffset( sTco->startTimeOffset() + ( oldPos - t ) ); + m_tco->changeLength( m_tco->length() - offset ); + sTco->setStartTimeOffset( sTco->startTimeOffset() + offset ); s_textFloat->setText( tr( "%1:%2 (%3:%4 to %5:%6)" ). arg( m_tco->length().getTact() ). arg( m_tco->length().getTicks() % diff --git a/src/tracks/SampleTrack.cpp b/src/tracks/SampleTrack.cpp index 7726439b25a..729c2ccec16 100644 --- a/src/tracks/SampleTrack.cpp +++ b/src/tracks/SampleTrack.cpp @@ -52,7 +52,8 @@ SampleTCO::SampleTCO( Track * _track ) : TrackContentObject( _track ), m_sampleBuffer( new SampleBuffer ), - m_isPlaying( false ) + m_isPlaying( false ), + m_currentFramesPerTick( Engine::framesPerTick() ) { saveJournallingState( false ); setSampleFile( "" ); @@ -61,9 +62,9 @@ SampleTCO::SampleTCO( Track * _track ) : // we need to receive bpm-change-events, because then we have to // change length of this TCO connect( Engine::getSong(), SIGNAL( tempoChanged( bpm_t ) ), - this, SLOT( updateLength() ) ); + this, SLOT( tempoChanged() ) ); connect( Engine::getSong(), SIGNAL( timeSignatureChanged( int,int ) ), - this, SLOT( updateLength() ) ); + this, SLOT( tempoChanged() ) ); //care about positionmarker TimeLineWidget * timeLine = Engine::getSong()->getPlayPos( Engine::getSong()->Mode_PlaySong ).m_timeLine; @@ -188,39 +189,28 @@ void SampleTCO::updateTrackTcos() -bool SampleTCO::isPlaying() const -{ - return m_isPlaying; -} - - - - -void SampleTCO::setIsPlaying( bool isPlaying ) +void SampleTCO::tempoChanged() { - m_isPlaying = isPlaying; + float newStartTimeOffset = ( startTimeOffset() * m_currentFramesPerTick ) / Engine::framesPerTick(); + setStartTimeOffset( qRound( newStartTimeOffset ) ); + m_currentFramesPerTick = Engine::framesPerTick(); + updateLength(); } -MidiTime SampleTCO::startTimeOffset() const +bool SampleTCO::isPlaying() const { - float stoF = m_startTimeOffset / Engine::framesPerTick(); - MidiTime sto = m_startTimeOffset / Engine::framesPerTick(); - if( stoF < (float) sto ) - { - sto = sto-1; - } - return sto; + return m_isPlaying; } -void SampleTCO::setStartTimeOffset( const MidiTime &startTimeOffset ) +void SampleTCO::setIsPlaying( bool isPlaying ) { - m_startTimeOffset = startTimeOffset * Engine::framesPerTick(); + m_isPlaying = isPlaying; } @@ -228,7 +218,7 @@ void SampleTCO::setStartTimeOffset( const MidiTime &startTimeOffset ) void SampleTCO::updateLength() { - changeLength( sampleLength() + startTimeOffset() ); + changeLength( sampleLength() - startTimeOffset() ); } @@ -532,19 +522,18 @@ void SampleTCOView::paintEvent( QPaintEvent * pe ) float ticksPerTact = DefaultTicksPerTact * nom / den; float offset = m_tco->startTimeOffset() / ticksPerTact * pixelsPerTact(); - QRect r = QRect( TCO_BORDER_WIDTH + offset, spacing, + QRect r = QRect( TCO_BORDER_WIDTH - offset, spacing, qMax( static_cast( m_tco->sampleLength() * ppt / ticksPerTact ), 1 ), rect().bottom() - 2 * spacing ); m_tco->m_sampleBuffer->visualize( p, r, pe->rect() ); // disable antialiasing for borders, since its not needed p.setRenderHint( QPainter::Antialiasing, false ); - if( r.width() + offset < width() - 1 ) + if( r.width() - offset < width() - 1 ) { p.drawLine( r.x(), r.y() + r.height() / 2, rect().right() - TCO_BORDER_WIDTH, r.y() + r.height() / 2 ); } - p.drawLine( 1, height() / 2, offset + 1, height() / 2 ); // inner border p.setPen( c.lighter( 160 ) ); @@ -638,10 +627,10 @@ bool SampleTrack::play( const MidiTime & _start, const fpp_t _frames, float framesPerTick = Engine::framesPerTick(); if( _start >= sTco->startPosition() && _start < sTco->endPosition() ) { - if( sTco->isPlaying() == false && _start > sTco->startPosition() + sTco->startTimeOffset() ) + if( sTco->isPlaying() == false && _start > sTco->startPosition() - sTco->startTimeOffset() ) { - f_cnt_t sampleStart = framesPerTick * ( _start - sTco->startPosition() - sTco->startTimeOffset() ); - f_cnt_t tcoFrameLength = framesPerTick * ( sTco->endPosition() - sTco->startPosition() - sTco->startTimeOffset() ); + f_cnt_t sampleStart = framesPerTick * ( _start - sTco->startPosition() + sTco->startTimeOffset() ); + f_cnt_t tcoFrameLength = framesPerTick * ( sTco->endPosition() - sTco->startPosition() + sTco->startTimeOffset() ); f_cnt_t sampleBufferLength = sTco->sampleBuffer()->frames(); //if the Tco smaller than the sample length we play only until Tco end //else we play the sample to the end but nothing more From 246797aaf5fb79f007dc4642c8bc5efbc5746705 Mon Sep 17 00:00:00 2001 From: Steffen Baranowsky Date: Sun, 7 May 2017 00:34:34 +0200 Subject: [PATCH 09/11] improve rounding in sampletrack visualizing --- src/tracks/SampleTrack.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tracks/SampleTrack.cpp b/src/tracks/SampleTrack.cpp index 729c2ccec16..3b6dcad2ce4 100644 --- a/src/tracks/SampleTrack.cpp +++ b/src/tracks/SampleTrack.cpp @@ -521,7 +521,7 @@ void SampleTCOView::paintEvent( QPaintEvent * pe ) float den = Engine::getSong()->getTimeSigModel().getDenominator(); float ticksPerTact = DefaultTicksPerTact * nom / den; - float offset = m_tco->startTimeOffset() / ticksPerTact * pixelsPerTact(); + int offset = ceilf( m_tco->startTimeOffset() * ppt / ticksPerTact ); QRect r = QRect( TCO_BORDER_WIDTH - offset, spacing, qMax( static_cast( m_tco->sampleLength() * ppt / ticksPerTact ), 1 ), rect().bottom() - 2 * spacing ); m_tco->m_sampleBuffer->visualize( p, r, pe->rect() ); From 1c3082752bb9b645e6adcdaabeefd4841b24fb8e Mon Sep 17 00:00:00 2001 From: Steffen Baranowsky Date: Sun, 14 May 2017 08:11:43 +0200 Subject: [PATCH 10/11] change approach again --- include/SampleTrack.h | 4 ++-- src/core/Track.cpp | 18 +++++++-------- src/tracks/SampleTrack.cpp | 46 ++++++++++++-------------------------- 3 files changed, 24 insertions(+), 44 deletions(-) diff --git a/include/SampleTrack.h b/include/SampleTrack.h index 66eaae155e4..147e5bee348 100644 --- a/include/SampleTrack.h +++ b/include/SampleTrack.h @@ -67,6 +67,7 @@ class SampleTCO : public TrackContentObject bool isPlaying() const; void setIsPlaying(bool isPlaying); + public slots: void setSampleBuffer( SampleBuffer* sb ); void setSampleFile( const QString & _sf ); @@ -74,14 +75,13 @@ public slots: void toggleRecord(); void playbackPositionChanged(); void updateTrackTcos(); - void tempoChanged(); private: SampleBuffer* m_sampleBuffer; BoolModel m_recordModel; bool m_isPlaying; - float m_currentFramesPerTick; + friend class SampleTCOView; diff --git a/src/core/Track.cpp b/src/core/Track.cpp index 83bf71f5a50..8afec11b07b 100644 --- a/src/core/Track.cpp +++ b/src/core/Track.cpp @@ -68,6 +68,7 @@ #include "StringPairDrag.h" #include "TextFloat.h" + /*! The width of the resize grip in pixels */ const int RESIZE_GRIP_WIDTH = 4; @@ -952,25 +953,22 @@ void TrackContentObjectView::mouseMoveEvent( QMouseEvent * me ) { const int x = mapToParent( me->pos() ).x() - m_initialMousePos.x(); - MidiTime t = (int) m_trackView->trackContainerView()->currentPosition() + + MidiTime t = qMax( 0, (int) + m_trackView->trackContainerView()->currentPosition()+ static_cast( x * MidiTime::ticksPerTact() / - ppt ); + ppt ) ); if( ! ( me->modifiers() & Qt::ControlModifier ) && me->button() == Qt::NoButton ) { t = t.toNearestTact(); } - if( t < sTco->startPosition() - sTco->startTimeOffset() ) - { - t = sTco->startPosition() - sTco->startTimeOffset(); - } - MidiTime offset = t - m_tco->startPosition(); - if( m_tco->length() - offset >= MidiTime::ticksPerTact() ) + MidiTime oldPos = m_tco->startPosition(); + if( m_tco->length() + ( oldPos - t ) >= MidiTime::ticksPerTact() ) { m_tco->movePosition( t ); m_trackView->getTrackContentWidget()->changePosition(); - m_tco->changeLength( m_tco->length() - offset ); - sTco->setStartTimeOffset( sTco->startTimeOffset() + offset ); + m_tco->changeLength( m_tco->length() + ( oldPos - t ) ); + sTco->setStartTimeOffset( sTco->startTimeOffset() + ( oldPos - t ) ); s_textFloat->setText( tr( "%1:%2 (%3:%4 to %5:%6)" ). arg( m_tco->length().getTact() ). arg( m_tco->length().getTicks() % diff --git a/src/tracks/SampleTrack.cpp b/src/tracks/SampleTrack.cpp index 3b6dcad2ce4..678986a15ae 100644 --- a/src/tracks/SampleTrack.cpp +++ b/src/tracks/SampleTrack.cpp @@ -52,8 +52,7 @@ SampleTCO::SampleTCO( Track * _track ) : TrackContentObject( _track ), m_sampleBuffer( new SampleBuffer ), - m_isPlaying( false ), - m_currentFramesPerTick( Engine::framesPerTick() ) + m_isPlaying( false ) { saveJournallingState( false ); setSampleFile( "" ); @@ -62,9 +61,9 @@ SampleTCO::SampleTCO( Track * _track ) : // we need to receive bpm-change-events, because then we have to // change length of this TCO connect( Engine::getSong(), SIGNAL( tempoChanged( bpm_t ) ), - this, SLOT( tempoChanged() ) ); + this, SLOT( updateLength() ) ); connect( Engine::getSong(), SIGNAL( timeSignatureChanged( int,int ) ), - this, SLOT( tempoChanged() ) ); + this, SLOT( updateLength() ) ); //care about positionmarker TimeLineWidget * timeLine = Engine::getSong()->getPlayPos( Engine::getSong()->Mode_PlaySong ).m_timeLine; @@ -150,7 +149,7 @@ void SampleTCO::setSampleFile( const QString & _sf ) { m_sampleBuffer->setAudioFile( _sf ); setStartTimeOffset( 0 ); - updateLength(); + changeLength( (int) ( m_sampleBuffer->frames() / Engine::framesPerTick() ) ); emit sampleChanged(); emit playbackPositionChanged(); @@ -189,17 +188,6 @@ void SampleTCO::updateTrackTcos() -void SampleTCO::tempoChanged() -{ - float newStartTimeOffset = ( startTimeOffset() * m_currentFramesPerTick ) / Engine::framesPerTick(); - setStartTimeOffset( qRound( newStartTimeOffset ) ); - m_currentFramesPerTick = Engine::framesPerTick(); - updateLength(); -} - - - - bool SampleTCO::isPlaying() const { return m_isPlaying; @@ -208,7 +196,7 @@ bool SampleTCO::isPlaying() const -void SampleTCO::setIsPlaying( bool isPlaying ) +void SampleTCO::setIsPlaying(bool isPlaying) { m_isPlaying = isPlaying; } @@ -218,7 +206,7 @@ void SampleTCO::setIsPlaying( bool isPlaying ) void SampleTCO::updateLength() { - changeLength( sampleLength() - startTimeOffset() ); + emit sampleChanged(); } @@ -232,7 +220,7 @@ MidiTime SampleTCO::sampleLength() const -void SampleTCO::setSampleStartFrame( f_cnt_t startFrame ) +void SampleTCO::setSampleStartFrame(f_cnt_t startFrame) { m_sampleBuffer->setStartFrame( startFrame ); } @@ -240,7 +228,7 @@ void SampleTCO::setSampleStartFrame( f_cnt_t startFrame ) -void SampleTCO::setSamplePlayLength( f_cnt_t length ) +void SampleTCO::setSamplePlayLength(f_cnt_t length) { m_sampleBuffer->setEndFrame( length ); } @@ -443,7 +431,7 @@ void SampleTCOView::mousePressEvent( QMouseEvent * _me ) -void SampleTCOView::mouseReleaseEvent( QMouseEvent *_me ) +void SampleTCOView::mouseReleaseEvent(QMouseEvent *_me) { if( _me->button() == Qt::MiddleButton && !_me->modifiers() ) { @@ -521,20 +509,14 @@ void SampleTCOView::paintEvent( QPaintEvent * pe ) float den = Engine::getSong()->getTimeSigModel().getDenominator(); float ticksPerTact = DefaultTicksPerTact * nom / den; - int offset = ceilf( m_tco->startTimeOffset() * ppt / ticksPerTact ); - QRect r = QRect( TCO_BORDER_WIDTH - offset, spacing, + float offset = m_tco->startTimeOffset() / ticksPerTact * pixelsPerTact(); + QRect r = QRect( TCO_BORDER_WIDTH + offset, spacing, qMax( static_cast( m_tco->sampleLength() * ppt / ticksPerTact ), 1 ), rect().bottom() - 2 * spacing ); m_tco->m_sampleBuffer->visualize( p, r, pe->rect() ); // disable antialiasing for borders, since its not needed p.setRenderHint( QPainter::Antialiasing, false ); - if( r.width() - offset < width() - 1 ) - { - p.drawLine( r.x(), r.y() + r.height() / 2, - rect().right() - TCO_BORDER_WIDTH, r.y() + r.height() / 2 ); - } - // inner border p.setPen( c.lighter( 160 ) ); p.drawRect( 1, 1, rect().right() - TCO_BORDER_WIDTH, @@ -627,10 +609,10 @@ bool SampleTrack::play( const MidiTime & _start, const fpp_t _frames, float framesPerTick = Engine::framesPerTick(); if( _start >= sTco->startPosition() && _start < sTco->endPosition() ) { - if( sTco->isPlaying() == false && _start > sTco->startPosition() - sTco->startTimeOffset() ) + if( sTco->isPlaying() == false && _start > sTco->startPosition() + sTco->startTimeOffset() ) { - f_cnt_t sampleStart = framesPerTick * ( _start - sTco->startPosition() + sTco->startTimeOffset() ); - f_cnt_t tcoFrameLength = framesPerTick * ( sTco->endPosition() - sTco->startPosition() + sTco->startTimeOffset() ); + f_cnt_t sampleStart = framesPerTick * ( _start - sTco->startPosition() - sTco->startTimeOffset() ); + f_cnt_t tcoFrameLength = framesPerTick * ( sTco->endPosition() - sTco->startPosition() - sTco->startTimeOffset() ); f_cnt_t sampleBufferLength = sTco->sampleBuffer()->frames(); //if the Tco smaller than the sample length we play only until Tco end //else we play the sample to the end but nothing more From 2b27365db8b355144d38a3137114dc2ee291f674 Mon Sep 17 00:00:00 2001 From: Steffen Baranowsky Date: Thu, 1 Jun 2017 15:36:55 +0200 Subject: [PATCH 11/11] cleanup the code/consolidate if blocks --- include/SampleTrack.h | 1 - include/Track.h | 2 +- src/core/Track.cpp | 121 ++++++++++++++++-------------------------- 3 files changed, 48 insertions(+), 76 deletions(-) diff --git a/include/SampleTrack.h b/include/SampleTrack.h index 147e5bee348..25841486cf4 100644 --- a/include/SampleTrack.h +++ b/include/SampleTrack.h @@ -67,7 +67,6 @@ class SampleTCO : public TrackContentObject bool isPlaying() const; void setIsPlaying(bool isPlaying); - public slots: void setSampleBuffer( SampleBuffer* sb ); void setSampleFile( const QString & _sf ); diff --git a/include/Track.h b/include/Track.h index c97cebb5306..e1272eb363a 100644 --- a/include/Track.h +++ b/include/Track.h @@ -150,7 +150,7 @@ class TrackContentObject : public Model, public JournallingObject static bool comparePosition(const TrackContentObject* a, const TrackContentObject* b); MidiTime startTimeOffset() const; - void setStartTimeOffset(const MidiTime &startTimeOffset); + void setStartTimeOffset( const MidiTime &startTimeOffset ); public slots: void copy(); diff --git a/src/core/Track.cpp b/src/core/Track.cpp index 8afec11b07b..42770426948 100644 --- a/src/core/Track.cpp +++ b/src/core/Track.cpp @@ -724,16 +724,6 @@ void TrackContentObjectView::mousePressEvent( QMouseEvent * me ) QCursor c( Qt::SizeHorCursor ); QApplication::setOverrideCursor( c ); s_textFloat->setTitle( tr( "Current length" ) ); - delete m_hint; - m_hint = TextFloat::displayMessage( tr( "Hint" ), - tr( "Press <%1> for free " - "resizing." ).arg( - #ifdef LMMS_BUILD_APPLE - "⌘"), - #else - "Ctrl"), - #endif - embed::getIconPixmap( "hint" ), 0 ); } else if( me->x() < width() - RESIZE_GRIP_WIDTH ) { @@ -742,16 +732,6 @@ void TrackContentObjectView::mousePressEvent( QMouseEvent * me ) QCursor c( Qt::SizeAllCursor ); QApplication::setOverrideCursor( c ); s_textFloat->setTitle( tr( "Current position" ) ); - delete m_hint; - m_hint = TextFloat::displayMessage( tr( "Hint" ), - tr( "Press <%1> and drag to make " - "a copy." ).arg( - #ifdef LMMS_BUILD_APPLE - "⌘"), - #else - "Ctrl"), - #endif - embed::getIconPixmap( "hint" ), 0 ); } else if( !m_tco->getAutoResize() ) { @@ -760,17 +740,20 @@ void TrackContentObjectView::mousePressEvent( QMouseEvent * me ) QCursor c( Qt::SizeHorCursor ); QApplication::setOverrideCursor( c ); s_textFloat->setTitle( tr( "Current length" ) ); - delete m_hint; - m_hint = TextFloat::displayMessage( tr( "Hint" ), - tr( "Press <%1> for free " - "resizing." ).arg( - #ifdef LMMS_BUILD_APPLE - "⌘"), - #else - "Ctrl"), - #endif - embed::getIconPixmap( "hint" ), 0 ); } + delete m_hint; + QString hint = m_action == Move ? tr( "Press <%1> and drag to make " + "a copy." ) + : tr( "Press <%1> for free " + "resizing." ); + m_hint = TextFloat::displayMessage( tr( "Hint" ), + hint.arg( + #ifdef LMMS_BUILD_APPLE + "⌘"), + #else + "Ctrl"), + #endif + embed::getIconPixmap( "hint" ), 0 ); // s_textFloat->reparent( this ); // setup text-float as if TCO was already moved/resized mouseMoveEvent( me ); @@ -925,14 +908,43 @@ void TrackContentObjectView::mouseMoveEvent( QMouseEvent * me ) ( *it )->movePosition( t ); } } - else if( m_action == Resize ) + else if( m_action == Resize || m_action == ResizeLeft ) { - MidiTime t = qMax( MidiTime::ticksPerTact() / 16, static_cast( me->x() * MidiTime::ticksPerTact() / ppt ) ); - if( ! ( me->modifiers() & Qt::ControlModifier ) && me->button() == Qt::NoButton ) + if( m_action == Resize ) + { + MidiTime t = qMax( MidiTime::ticksPerTact() / 16, static_cast( me->x() * MidiTime::ticksPerTact() / ppt ) ); + if( ! ( me->modifiers() & Qt::ControlModifier ) && me->button() == Qt::NoButton ) + { + t = qMax( MidiTime::ticksPerTact(), t.toNearestTact() ); + } + m_tco->changeLength( t ); + } + else { - t = qMax( MidiTime::ticksPerTact(), t.toNearestTact() ); + SampleTCO * sTco = dynamic_cast( m_tco ); + if( sTco ) + { + const int x = mapToParent( me->pos() ).x() - m_initialMousePos.x(); + + MidiTime t = qMax( 0, (int) + m_trackView->trackContainerView()->currentPosition()+ + static_cast( x * MidiTime::ticksPerTact() / + ppt ) ); + if( ! ( me->modifiers() & Qt::ControlModifier ) + && me->button() == Qt::NoButton ) + { + t = t.toNearestTact(); + } + MidiTime oldPos = m_tco->startPosition(); + if( m_tco->length() + ( oldPos - t ) >= MidiTime::ticksPerTact() ) + { + m_tco->movePosition( t ); + m_trackView->getTrackContentWidget()->changePosition(); + m_tco->changeLength( m_tco->length() + ( oldPos - t ) ); + sTco->setStartTimeOffset( sTco->startTimeOffset() + ( oldPos - t ) ); + } + } } - m_tco->changeLength( t ); s_textFloat->setText( tr( "%1:%2 (%3:%4 to %5:%6)" ). arg( m_tco->length().getTact() ). arg( m_tco->length().getTicks() % @@ -946,45 +958,6 @@ void TrackContentObjectView::mouseMoveEvent( QMouseEvent * me ) s_textFloat->moveGlobal( this, QPoint( width() + 2, height() + 2) ); } - else if( m_action == ResizeLeft ) - { - SampleTCO * sTco = dynamic_cast( m_tco ); - if( sTco ) - { - const int x = mapToParent( me->pos() ).x() - m_initialMousePos.x(); - - MidiTime t = qMax( 0, (int) - m_trackView->trackContainerView()->currentPosition()+ - static_cast( x * MidiTime::ticksPerTact() / - ppt ) ); - if( ! ( me->modifiers() & Qt::ControlModifier ) - && me->button() == Qt::NoButton ) - { - t = t.toNearestTact(); - } - MidiTime oldPos = m_tco->startPosition(); - if( m_tco->length() + ( oldPos - t ) >= MidiTime::ticksPerTact() ) - { - m_tco->movePosition( t ); - m_trackView->getTrackContentWidget()->changePosition(); - m_tco->changeLength( m_tco->length() + ( oldPos - t ) ); - sTco->setStartTimeOffset( sTco->startTimeOffset() + ( oldPos - t ) ); - s_textFloat->setText( tr( "%1:%2 (%3:%4 to %5:%6)" ). - arg( m_tco->length().getTact() ). - arg( m_tco->length().getTicks() % - MidiTime::ticksPerTact() ). - arg( m_tco->startPosition().getTact() + 1 ). - arg( m_tco->startPosition().getTicks() % - MidiTime::ticksPerTact() ). - arg( m_tco->endPosition().getTact() + 1 ). - arg( m_tco->endPosition().getTicks() % - MidiTime::ticksPerTact() ) ); - s_textFloat->moveGlobal( this, QPoint( width() + 2, - height() + 2) ); - } - } - - } else { SampleTCO * sTco = dynamic_cast( m_tco );