Skip to content

Commit

Permalink
Add workaround for Tracktion/tracktion_engine#13.
Browse files Browse the repository at this point in the history
  • Loading branch information
atsushieno committed Mar 12, 2019
1 parent 68001e6 commit 3f93961
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions samples/Midi2TracktionEdit/MidiToTracktionEdit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ void ImportTrack (MidiImportContext context, MidiTrack mtrack, TrackElement ttra
int [,] noteDeltaTimes = new int [16, 128];
NoteElement [,] notes = new NoteElement [16,128];
int timeSigNumerator = 4, timeSigDenominator = 4;
double currentBpm = 120.0;

foreach (var msg in mtrack.Messages) {
currentTotalTime += msg.DeltaTime;
Expand Down Expand Up @@ -113,11 +114,12 @@ void ImportTrack (MidiImportContext context, MidiTrack mtrack, TrackElement ttra
if (msg.Event.EventType == MidiEvent.Meta) {
switch (msg.Event.MetaType) {
//case MidiMetaType.Marker:
case MidiMetaType.Tempo:
case MidiMetaType.Tempo:
currentBpm = ToBpm (msg.Event.Data);
context.Edit.TempoSequence.Tempos.Add (new TempoElement {
StartBeat = ToTracktionBarSpec (context,
currentTotalTime),
Curve = 1.0, Bpm = ToBpm (msg.Event.Data)
Curve = 1.0, Bpm = currentBpm
});
break;
case MidiMetaType.TimeSignature:
Expand All @@ -126,6 +128,12 @@ void ImportTrack (MidiImportContext context, MidiTrack mtrack, TrackElement ttra
timeSigDenominator = (int) Math.Pow (2, timeSig [1]);
context.Edit.TempoSequence.TimeSignatures.Add (
new TimeSigElement { StartBeat = ToTracktionBarSpec (context, currentTotalTime), Numerator= timeSigNumerator, Denominator = timeSigDenominator });
// Tracktion engine has a problem that its tempo calculation goes fubar when timesig denomitator becomes non-4 value.
context.Edit.TempoSequence.Tempos.Add (new TempoElement {
StartBeat = ToTracktionBarSpec (context,
currentTotalTime),
Curve = 1.0, Bpm = currentBpm / (timeSigDenominator / 4)
});
break;
}
}
Expand Down

0 comments on commit 3f93961

Please sign in to comment.