Offload most Midi processing from Song into MidiTime class
This commit is contained in:
@@ -27,8 +27,10 @@
|
||||
#ifndef MIDI_TIME_H
|
||||
#define MIDI_TIME_H
|
||||
|
||||
#include "lmms_basics.h"
|
||||
#include <QtGlobal>
|
||||
|
||||
#include "export.h"
|
||||
#include "lmms_basics.h"
|
||||
|
||||
// note: 1 "Tact" = 1 Measure
|
||||
const int DefaultTicksPerTact = 192;
|
||||
@@ -36,6 +38,25 @@ const int DefaultStepsPerTact = 16;
|
||||
const int DefaultBeatsPerTact = DefaultTicksPerTact / DefaultStepsPerTact;
|
||||
|
||||
|
||||
class MeterModel;
|
||||
|
||||
class EXPORT TimeSig
|
||||
{
|
||||
public:
|
||||
// in a time signature,
|
||||
// the numerator represents the number of beats in a measure.
|
||||
// the denominator indicates which type of note represents a beat.
|
||||
// example: 6/8 means 6 beats in a measure, where each beat has duration equal to one 8th-note.
|
||||
TimeSig( int num, int denom );
|
||||
TimeSig( const MeterModel &model );
|
||||
int numerator() const;
|
||||
int denominator() const;
|
||||
private:
|
||||
int m_num;
|
||||
int m_denom;
|
||||
};
|
||||
|
||||
|
||||
class EXPORT MidiTime
|
||||
{
|
||||
public:
|
||||
@@ -112,6 +133,26 @@ public:
|
||||
return m_ticks;
|
||||
}
|
||||
|
||||
tick_t ticksPerBeat( const TimeSig &sig ) const
|
||||
{
|
||||
return ticksPerTact(sig) / sig.numerator();
|
||||
}
|
||||
// Remainder ticks after bar is removed
|
||||
tick_t getTickWithinBar( const TimeSig &sig ) const
|
||||
{
|
||||
return m_ticks % ticksPerTact(sig);
|
||||
}
|
||||
// Returns the beat position inside the bar, 0-based
|
||||
tick_t getBeatWithinBar( const TimeSig &sig ) const
|
||||
{
|
||||
return getTickWithinBar(sig) / ticksPerBeat(sig);
|
||||
}
|
||||
// Remainder ticks after bar and beat are removed
|
||||
tick_t getTickWithinBeat( const TimeSig &sig ) const
|
||||
{
|
||||
return getTickWithinBar(sig) % ticksPerBeat(sig);
|
||||
}
|
||||
|
||||
// calculate number of frame that are needed this time
|
||||
f_cnt_t frames( const float framesPerTick ) const
|
||||
{
|
||||
@@ -132,6 +173,10 @@ public:
|
||||
{
|
||||
return s_ticksPerTact;
|
||||
}
|
||||
static tick_t ticksPerTact( const TimeSig &sig ) const
|
||||
{
|
||||
return DefaultTicksPerTact * sig.numerator() / sig.denominator();
|
||||
}
|
||||
|
||||
static int stepsPerTact()
|
||||
{
|
||||
|
||||
@@ -111,22 +111,18 @@ public:
|
||||
|
||||
inline int ticksPerTact() const
|
||||
{
|
||||
return DefaultTicksPerTact *
|
||||
m_timeSigModel.getNumerator() /
|
||||
m_timeSigModel.getDenominator();
|
||||
return MidiTime::ticksPerTact(m_timeSigModel);
|
||||
}
|
||||
|
||||
// Returns the beat position inside the bar, 0-based
|
||||
inline int getBeat() const
|
||||
{
|
||||
return ( currentTick() - currentTact() * ticksPerTact() ) /
|
||||
( ticksPerTact() / m_timeSigModel.getNumerator() );
|
||||
return getPlayPos().getBeatWithinBar(m_timeSigModel);
|
||||
}
|
||||
// the remainder after bar and beat are removed
|
||||
inline int getBeatTicks() const
|
||||
{
|
||||
return ( currentTick() - currentTact() * ticksPerTact() ) %
|
||||
( ticksPerTact() / m_timeSigModel.getNumerator() );
|
||||
return getPlayPos().getTickWithinBeat(m_timeSigModel);
|
||||
}
|
||||
inline int getTicks() const
|
||||
{
|
||||
@@ -186,6 +182,10 @@ public:
|
||||
{
|
||||
return m_playPos[pm];
|
||||
}
|
||||
inline const PlayPos & getPlayPos() const
|
||||
{
|
||||
return getPlayPos(m_playMode);
|
||||
}
|
||||
|
||||
void updateLength();
|
||||
tact_t length() const
|
||||
|
||||
Reference in New Issue
Block a user