Skip to content

Commit

Permalink
fixes bug on resizing and temo change
Browse files Browse the repository at this point in the history
  • Loading branch information
BaraMGB committed May 8, 2017
1 parent 7e3ee14 commit 5f3960d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 6 deletions.
6 changes: 5 additions & 1 deletion include/SampleTrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ class SampleTCO : public TrackContentObject


bool isPlaying() const;
void setIsPlaying(bool isPlaying);
void setIsPlaying( bool isPlaying );

MidiTime endingOffset() const;
void setEndingOffset( const MidiTime &endingOffset );

public slots:
void setSampleBuffer( SampleBuffer* sb );
Expand All @@ -80,6 +83,7 @@ public slots:
SampleBuffer* m_sampleBuffer;
BoolModel m_recordModel;
bool m_isPlaying;
f_cnt_t m_endingOffsetFrames;


friend class SampleTCOView;
Expand Down
11 changes: 11 additions & 0 deletions src/core/Track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,17 @@ void TrackContentObjectView::mouseMoveEvent( QMouseEvent * me )
{
t = qMax<int>( MidiTime::ticksPerTact(), t.toNearestTact() );
}
SampleTCO * sTco = dynamic_cast<SampleTCO*>( m_tco );
if( sTco )
{
//we ensure that the resizing is within the sample limits
MidiTime ticksPerTact = MidiTime::ticksPerTact();
t = t > sTco->sampleLength() ? sTco->sampleLength() : t;
//but not smaller than a tact
t = t < ticksPerTact ? ticksPerTact : t;
MidiTime offset = sTco->length() - t;
sTco->setEndingOffset( sTco->endingOffset() + offset );
}
m_tco->changeLength( t );
s_textFloat->setText( tr( "%1:%2 (%3:%4 to %5:%6)" ).
arg( m_tco->length().getTact() ).
Expand Down
36 changes: 31 additions & 5 deletions src/tracks/SampleTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
SampleTCO::SampleTCO( Track * _track ) :
TrackContentObject( _track ),
m_sampleBuffer( new SampleBuffer ),
m_isPlaying( false )
m_isPlaying( false ),
m_endingOffsetFrames( 0 )
{
saveJournallingState( false );
setSampleFile( "" );
Expand Down Expand Up @@ -148,6 +149,7 @@ void SampleTCO::setSampleBuffer( SampleBuffer* sb )
void SampleTCO::setSampleFile( const QString & _sf )
{
m_sampleBuffer->setAudioFile( _sf );
m_endingOffsetFrames = 0;
updateLength();

emit sampleChanged();
Expand Down Expand Up @@ -184,12 +186,34 @@ void SampleTCO::updateTrackTcos()
}
}




MidiTime SampleTCO::endingOffset() const
{
return (int) ( m_endingOffsetFrames / Engine::framesPerTick() );
}




void SampleTCO::setEndingOffset( const MidiTime &endingOffset )
{
m_endingOffsetFrames = endingOffset * Engine::framesPerTick();
}




bool SampleTCO::isPlaying() const
{
return m_isPlaying;
}

void SampleTCO::setIsPlaying(bool isPlaying)



void SampleTCO::setIsPlaying( bool isPlaying )
{
m_isPlaying = isPlaying;
}
Expand All @@ -199,7 +223,7 @@ void SampleTCO::setIsPlaying(bool isPlaying)

void SampleTCO::updateLength()
{
changeLength( sampleLength() );
changeLength( (int) ( ( m_sampleBuffer->frames() - m_endingOffsetFrames ) / Engine::framesPerTick() ) );
}


Expand All @@ -213,15 +237,15 @@ MidiTime SampleTCO::sampleLength() const



void SampleTCO::setSampleStartFrame(f_cnt_t startFrame)
void SampleTCO::setSampleStartFrame( f_cnt_t startFrame )
{
m_sampleBuffer->setStartFrame( startFrame );
}




void SampleTCO::setSamplePlayLength(f_cnt_t length)
void SampleTCO::setSamplePlayLength( f_cnt_t length )
{
m_sampleBuffer->setEndFrame( length );
}
Expand All @@ -242,6 +266,7 @@ void SampleTCO::saveSettings( QDomDocument & _doc, QDomElement & _this )
_this.setAttribute( "len", length() );
_this.setAttribute( "muted", isMuted() );
_this.setAttribute( "src", sampleFile() );
_this.setAttribute( "endoffset", endingOffset() );
if( sampleFile() == "" )
{
QString s;
Expand All @@ -264,6 +289,7 @@ void SampleTCO::loadSettings( const QDomElement & _this )
{
m_sampleBuffer->loadFromBase64( _this.attribute( "data" ) );
}
setEndingOffset( _this.attribute( "endoffset" ).toInt() );
changeLength( _this.attribute( "len" ).toInt() );
setMuted( _this.attribute( "muted" ).toInt() );
}
Expand Down

0 comments on commit 5f3960d

Please sign in to comment.