Remove explicit time calculations by moving them into Song and MidiTime
Add a method to convert a MidiTime instance to milliseconds. Also add a static method to MidiTime that computes the time in milliseconds for a given number of ticks and a tempo. Remove the method that sets the milliseconds explicitly from Song. Replace it by a method that takes a MidiTime instance and one method that takes an amount of ticks. Remove several explicit time calculations from the implementation of Song and TimeLineWidget. Instead use the new methods.
This commit is contained in:
@@ -258,8 +258,7 @@ void Song::processNextBuffer()
|
||||
if( m_playPos[m_playMode] < tl->loopBegin() ||
|
||||
m_playPos[m_playMode] >= tl->loopEnd() )
|
||||
{
|
||||
m_elapsedMilliSeconds =
|
||||
( tl->loopBegin().getTicks() * 60 * 1000 / 48 ) / getTempo();
|
||||
setToTime(tl->loopBegin());
|
||||
m_playPos[m_playMode].setTicks(
|
||||
tl->loopBegin().getTicks() );
|
||||
emit updateSampleTracks();
|
||||
@@ -316,8 +315,7 @@ void Song::processNextBuffer()
|
||||
ticks %= ( maxTact * MidiTime::ticksPerTact() );
|
||||
|
||||
// wrap milli second counter
|
||||
m_elapsedMilliSeconds =
|
||||
( ticks * 60 * 1000 / 48 ) / getTempo();
|
||||
setToTimeByTicks(ticks);
|
||||
|
||||
m_vstSyncController.setAbsolutePosition( ticks );
|
||||
}
|
||||
@@ -335,10 +333,7 @@ void Song::processNextBuffer()
|
||||
if( m_playPos[m_playMode] >= tl->loopEnd() )
|
||||
{
|
||||
m_playPos[m_playMode].setTicks( tl->loopBegin().getTicks() );
|
||||
|
||||
m_elapsedMilliSeconds =
|
||||
( ( tl->loopBegin().getTicks() ) * 60 * 1000 / 48 ) /
|
||||
getTempo();
|
||||
setToTime(tl->loopBegin());
|
||||
}
|
||||
else if( m_playPos[m_playMode] == tl->loopEnd() - 1 )
|
||||
{
|
||||
@@ -393,9 +388,7 @@ void Song::processNextBuffer()
|
||||
framesPlayed += framesToPlay;
|
||||
m_playPos[m_playMode].setCurrentFrame( framesToPlay +
|
||||
currentFrame );
|
||||
m_elapsedMilliSeconds +=
|
||||
( ( framesToPlay / framesPerTick ) * 60 * 1000 / 48 )
|
||||
/ getTempo();
|
||||
m_elapsedMilliSeconds += MidiTime::ticksToMilliseconds( framesToPlay / framesPerTick, getTempo());
|
||||
m_elapsedTacts = m_playPos[Mode_PlaySong].getTact();
|
||||
m_elapsedTicks = ( m_playPos[Mode_PlaySong].getTicks() % ticksPerTact() ) / 48;
|
||||
}
|
||||
@@ -603,10 +596,9 @@ void Song::updateLength()
|
||||
|
||||
void Song::setPlayPos( tick_t ticks, PlayModes playMode )
|
||||
{
|
||||
m_elapsedTicks += m_playPos[playMode].getTicks() - ticks;
|
||||
m_elapsedMilliSeconds +=
|
||||
( ( ( ( ticks - m_playPos[playMode].getTicks() ) ) * 60 * 1000 / 48) /
|
||||
getTempo() );
|
||||
tick_t ticksFromPlayMode = m_playPos[playMode].getTicks();
|
||||
m_elapsedTicks += ticksFromPlayMode - ticks;
|
||||
m_elapsedMilliSeconds += MidiTime::ticksToMilliseconds( ticks - ticksFromPlayMode, getTempo() );
|
||||
m_playPos[playMode].setTicks( ticks );
|
||||
m_playPos[playMode].setCurrentFrame( 0.0f );
|
||||
|
||||
@@ -673,9 +665,8 @@ void Song::stop()
|
||||
if( tl->savedPos() >= 0 )
|
||||
{
|
||||
m_playPos[m_playMode].setTicks( tl->savedPos().getTicks() );
|
||||
m_elapsedMilliSeconds =
|
||||
( ( ( tl->savedPos().getTicks() ) * 60 * 1000 / 48 ) /
|
||||
getTempo() );
|
||||
setToTime(tl->savedPos());
|
||||
|
||||
if( gui && gui->songEditor() &&
|
||||
( tl->autoScroll() == TimeLineWidget::AutoScrollEnabled ) )
|
||||
{
|
||||
|
||||
@@ -155,6 +155,10 @@ f_cnt_t MidiTime::frames( const float framesPerTick ) const
|
||||
return 0;
|
||||
}
|
||||
|
||||
double MidiTime::getTimeInMilliseconds(bpm_t beatsPerMinute) const
|
||||
{
|
||||
return ticksToMilliseconds(getTicks(), beatsPerMinute);
|
||||
}
|
||||
|
||||
MidiTime MidiTime::fromFrames( const f_cnt_t frames, const float framesPerTick )
|
||||
{
|
||||
@@ -191,3 +195,9 @@ MidiTime MidiTime::stepPosition( int step )
|
||||
{
|
||||
return step * ticksPerTact() / stepsPerTact();
|
||||
}
|
||||
|
||||
double MidiTime::ticksToMilliseconds(tick_t ticks, bpm_t beatsPerMinute)
|
||||
{
|
||||
// 60 * 1000 / 48 = 1250
|
||||
return ( ticks * 1250 ) / beatsPerMinute;
|
||||
}
|
||||
|
||||
@@ -371,9 +371,7 @@ void TimeLineWidget::mouseMoveEvent( QMouseEvent* event )
|
||||
{
|
||||
case MovePositionMarker:
|
||||
m_pos.setTicks( t.getTicks() );
|
||||
Engine::getSong()->setMilliSeconds( ( t.getTicks() *
|
||||
( 60 * 1000 / 48 ) ) /
|
||||
Engine::getSong()->getTempo() );
|
||||
Engine::getSong()->setToTime(t);
|
||||
m_pos.setCurrentFrame( 0 );
|
||||
updatePosition();
|
||||
positionMarkerMoved();
|
||||
|
||||
Reference in New Issue
Block a user