MidiPlayerTK.MPTKTempo

Contains information about the tempo change.
More...

Public Member Functions

 MPTKTempo (int index, long fromTick=0, long toTick=long.MaxValue, double fromTime=0d, double pulse=0d, int microsecondsPerQuarterNote=0)
 Create a tempo segment with default value More...
 
double CalculateTime (long tick)
 
override string ToString ()
 

Static Public Member Functions

static void CalculateMap (int deltaTicksPerQuarterNote, List< MPTKEvent > mptkEvents, List< MPTKTempo > temposMap)
 
static int FindSegment (List< MPTKTempo > tempoMap, float timeSearch, int fromIndex=0)
 
static int FindSegment (List< MPTKTempo > tempoMap, long tickSearch, int fromIndex=0)
 

Public Attributes

long FromTick
 
double FromTime
 
int Index
 
int MicrosecondsPerQuarterNote
 
double Pulse
 
long ToTick
 

Static Public Attributes

static int DeltaTicksPerQuarterNote
 

Detailed Description

Contains information about the tempo change.

Version
Maestro 2.9.0
Note
  • The tempo map is automaticalled build when a MIDI file is loaded from the MIDI DB, from an external MIDI or from a MIDI Writer instance.
  • The tempo map must be run by script on your MIDI events when created with MidiFileWriter2 with:
    #MPTK_CalculateTempoMap
  • Each segments defined the tick start/end and the start real time of the segment and the pulse (duration in millisecond of a MIDI tick) wich is constant all along the segment.

Constructor & Destructor Documentation

◆ MPTKTempo()

MidiPlayerTK.MPTKTempo.MPTKTempo ( int  index,
long  fromTick = 0,
long  toTick = long.MaxValue,
double  fromTime = 0d,
double  pulse = 0d,
int  microsecondsPerQuarterNote = 0 
)

Create a tempo segment with default value

Parameters
index
fromTickdefault 0
toTickdefault ong.MaxValue
fromTimedefault 0
pulsedefault 0
microsecondsPerQuarterNotedefault 0

Member Function Documentation

◆ CalculateMap()

static void MidiPlayerTK.MPTKTempo.CalculateMap ( int  deltaTicksPerQuarterNote,
List< MPTKEvent mptkEvents,
List< MPTKTempo temposMap 
)
static

Create a tempo map from a MIDI events list with tempo change.
An allocated tempo map must be defined in parameter but the content will be cleared.

Note
A default tempo segment will be added at tick 0 with BPM = 120
Version
2.10.0
// A MidiFileWriter2 (mfw) has been created with new MidiFileWriter2() With a set of MIDI events.
// Sort the events by ascending absolute time (optional)
mfw.StableSortEvents();
// Calculate time, measure and beat for each events
mfw.CalculateTiming(logDebug: true, logPerf: true);
mfw.LogWriter();
Parameters
deltaTicksPerQuarterNote
mptkEvents
temposMap

◆ CalculateTime()

double MidiPlayerTK.MPTKTempo.CalculateTime ( long  tick)

Realtime in milliseconds for this tick in this segment

Parameters
tick
Returns

◆ FindSegment() [1/2]

static int MidiPlayerTK.MPTKTempo.FindSegment ( List< MPTKTempo tempoMap,
float  timeSearch,
int  fromIndex = 0 
)
static

Find an index in the tempo change list from a time position in millisecond.

Warning
  • To avoid confusion with search by ticks, make sure the timeSearch parameter is a float.
Note
Parameters
tempoMapList of tempo map build with MPTK_CalculateTempoMap
timeSearchsearch from this time in millisecond
fromIndexsearch from this index position in the TempoMap list (for optimization)
Returns
index of the segment in tempoMap

◆ FindSegment() [2/2]

static int MidiPlayerTK.MPTKTempo.FindSegment ( List< MPTKTempo tempoMap,
long  tickSearch,
int  fromIndex = 0 
)
static

Find an index in the tempo change list from a tick position.

Warning
  • To avoid confusion with search by time, make sure the tickSearch parameter is a long (or int).
Note
  • If tick is a border between two segments, the upper segment is returned.
Parameters
tempoMapList of tempo map build with MPTK_CalculateTempoMap
tickSearchsearch from this tick value
fromIndexsearch from this index position in the list (for optimization)
Returns
index of the segment in tempoMap

◆ ToString()

override string MidiPlayerTK.MPTKTempo.ToString ( )

String description of this segment

Returns

Member Data Documentation

◆ DeltaTicksPerQuarterNote

int MidiPlayerTK.MPTKTempo.DeltaTicksPerQuarterNote
static

This information is mandatory to calculate start/end measure and beat.

◆ FromTick

long MidiPlayerTK.MPTKTempo.FromTick

Tick start of this segment

◆ FromTime

double MidiPlayerTK.MPTKTempo.FromTime

Exact time in milliseconds to reach this tempo or signature change

◆ Index

int MidiPlayerTK.MPTKTempo.Index

Index of this segment if added to a list of tempo map with #MPTK_CalculateTempoMap

◆ MicrosecondsPerQuarterNote

int MidiPlayerTK.MPTKTempo.MicrosecondsPerQuarterNote

BPM = 60000000 / MicrosecondsPerQuarterNote

◆ Pulse

double MidiPlayerTK.MPTKTempo.Pulse

Duration in millisecond of a MIDI tick in this segment. The pulse length is the minimum time in millisecond between two MIDI events.

Note
  • Depends on the current tempo, the #MPTK_DeltaTicksPerQuarterNote (but not the Speed).
  • Formula: Pulse = (60000000 / MPTK_CurrentTempo) / MPTK_DeltaTicksPerQuarterNote / 1000

◆ ToTick

long MidiPlayerTK.MPTKTempo.ToTick

Tick end of this segment