Inline TimePos and TimeSig functions to improve performance (#7549)
* Inline TimeSig functions * Inline TimePos functions
This commit is contained in:
@@ -43,20 +43,6 @@ TimeSig::TimeSig( const MeterModel &model ) :
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
int TimeSig::numerator() const
|
||||
{
|
||||
return m_num;
|
||||
}
|
||||
|
||||
int TimeSig::denominator() const
|
||||
{
|
||||
return m_denom;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
TimePos::TimePos( const bar_t bar, const tick_t ticks ) :
|
||||
m_ticks( bar * s_ticksPerBar + ticks )
|
||||
{
|
||||
@@ -86,140 +72,4 @@ TimePos TimePos::quantize(float bars) const
|
||||
return (lowPos + snapUp) * interval;
|
||||
}
|
||||
|
||||
|
||||
TimePos TimePos::toAbsoluteBar() const
|
||||
{
|
||||
return getBar() * s_ticksPerBar;
|
||||
}
|
||||
|
||||
|
||||
TimePos& TimePos::operator+=( const TimePos& time )
|
||||
{
|
||||
m_ticks += time.m_ticks;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TimePos& TimePos::operator-=( const TimePos& time )
|
||||
{
|
||||
m_ticks -= time.m_ticks;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
bar_t TimePos::getBar() const
|
||||
{
|
||||
return m_ticks / s_ticksPerBar;
|
||||
}
|
||||
|
||||
|
||||
bar_t TimePos::nextFullBar() const
|
||||
{
|
||||
return ( m_ticks + ( s_ticksPerBar - 1 ) ) / s_ticksPerBar;
|
||||
}
|
||||
|
||||
|
||||
void TimePos::setTicks( tick_t ticks )
|
||||
{
|
||||
m_ticks = ticks;
|
||||
}
|
||||
|
||||
|
||||
tick_t TimePos::getTicks() const
|
||||
{
|
||||
return m_ticks;
|
||||
}
|
||||
|
||||
|
||||
TimePos::operator int() const
|
||||
{
|
||||
return m_ticks;
|
||||
}
|
||||
|
||||
|
||||
tick_t TimePos::ticksPerBeat( const TimeSig &sig ) const
|
||||
{
|
||||
// (number of ticks per bar) divided by (number of beats per bar)
|
||||
return ticksPerBar(sig) / sig.numerator();
|
||||
}
|
||||
|
||||
|
||||
tick_t TimePos::getTickWithinBar( const TimeSig &sig ) const
|
||||
{
|
||||
return m_ticks % ticksPerBar( sig );
|
||||
}
|
||||
|
||||
tick_t TimePos::getBeatWithinBar( const TimeSig &sig ) const
|
||||
{
|
||||
return getTickWithinBar( sig ) / ticksPerBeat( sig );
|
||||
}
|
||||
|
||||
tick_t TimePos::getTickWithinBeat( const TimeSig &sig ) const
|
||||
{
|
||||
return getTickWithinBar( sig ) % ticksPerBeat( sig );
|
||||
}
|
||||
|
||||
|
||||
f_cnt_t TimePos::frames( const float framesPerTick ) const
|
||||
{
|
||||
// Before, step notes used to have negative length. This
|
||||
// assert is a safeguard against negative length being
|
||||
// introduced again (now using Note Types instead #5902)
|
||||
assert(m_ticks >= 0);
|
||||
return static_cast<f_cnt_t>(m_ticks * framesPerTick);
|
||||
}
|
||||
|
||||
double TimePos::getTimeInMilliseconds( bpm_t beatsPerMinute ) const
|
||||
{
|
||||
return ticksToMilliseconds( getTicks(), beatsPerMinute );
|
||||
}
|
||||
|
||||
TimePos TimePos::fromFrames( const f_cnt_t frames, const float framesPerTick )
|
||||
{
|
||||
return TimePos( static_cast<int>( frames / framesPerTick ) );
|
||||
}
|
||||
|
||||
|
||||
tick_t TimePos::ticksPerBar()
|
||||
{
|
||||
return s_ticksPerBar;
|
||||
}
|
||||
|
||||
|
||||
tick_t TimePos::ticksPerBar( const TimeSig &sig )
|
||||
{
|
||||
return DefaultTicksPerBar * sig.numerator() / sig.denominator();
|
||||
}
|
||||
|
||||
|
||||
int TimePos::stepsPerBar()
|
||||
{
|
||||
int steps = ticksPerBar() / DefaultBeatsPerBar;
|
||||
return std::max(1, steps);
|
||||
}
|
||||
|
||||
|
||||
void TimePos::setTicksPerBar( tick_t tpb )
|
||||
{
|
||||
s_ticksPerBar = tpb;
|
||||
}
|
||||
|
||||
|
||||
TimePos TimePos::stepPosition( int step )
|
||||
{
|
||||
return step * ticksPerBar() / stepsPerBar();
|
||||
}
|
||||
|
||||
double TimePos::ticksToMilliseconds( tick_t ticks, bpm_t beatsPerMinute )
|
||||
{
|
||||
return TimePos::ticksToMilliseconds( static_cast<double>(ticks), beatsPerMinute );
|
||||
}
|
||||
|
||||
double TimePos::ticksToMilliseconds(double ticks, bpm_t beatsPerMinute)
|
||||
{
|
||||
// 60 * 1000 / 48 = 1250
|
||||
return ( ticks * 1250 ) / beatsPerMinute;
|
||||
}
|
||||
|
||||
|
||||
} // namespace lmms
|
||||
|
||||
Reference in New Issue
Block a user