Skip to content

Commit

Permalink
Simplified musical time span conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
melanchall committed Mar 21, 2024
1 parent d0bb5e7 commit 1db934b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 9 deletions.
7 changes: 0 additions & 7 deletions DryWetMidi/Common/MathUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,6 @@ public static long GreatestCommonDivisor(long a, long b)
return a;
}

// ax + by = 0
public static Tuple<long, long> SolveDiophantineEquation(long a, long b)
{
var greatestCommonDivisor = GreatestCommonDivisor(a, b);
return Tuple.Create(b / greatestCommonDivisor, -a / greatestCommonDivisor);
}

public static double Round(double value)
{
return Math.Round(value, MidpointRounding.AwayFromZero);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public ITimeSpan ConvertTo(long timeSpan, long time, TempoMap tempoMap)
if (timeSpan == 0)
return new MusicalTimeSpan();

var xy = MathUtilities.SolveDiophantineEquation(4 * ticksPerQuarterNoteTimeDivision.TicksPerQuarterNote, -timeSpan);
return new MusicalTimeSpan(Math.Abs(xy.Item1), Math.Abs(xy.Item2));
var gcd = MathUtilities.GreatestCommonDivisor(timeSpan, 4 * ticksPerQuarterNoteTimeDivision.TicksPerQuarterNote);
return new MusicalTimeSpan(timeSpan / gcd, 4 * ticksPerQuarterNoteTimeDivision.TicksPerQuarterNote / gcd);
}

public long ConvertFrom(ITimeSpan timeSpan, long time, TempoMap tempoMap)
Expand Down

0 comments on commit 1db934b

Please sign in to comment.