public ITime ConvertTo(long time, TempoMap tempoMap) { ThrowIfTimeArgument.IsNegative(nameof(time), time); ThrowIfArgument.IsNull(nameof(tempoMap), tempoMap); var ticksPerQuarterNoteTimeDivision = tempoMap.TimeDivision as TicksPerQuarterNoteTimeDivision; if (ticksPerQuarterNoteTimeDivision != null) { return(ConvertToByTicksPerQuarterNote(time, ticksPerQuarterNoteTimeDivision.TicksPerQuarterNote, tempoMap)); } ThrowIfTimeDivision.IsNotSupportedForTimeConversion(tempoMap.TimeDivision); return(null); }
public ILength ConvertTo(long length, long time, TempoMap tempoMap) { ThrowIfLengthArgument.IsNegative(nameof(length), length); ThrowIfTimeArgument.IsNegative(nameof(time), time); ThrowIfArgument.IsNull(nameof(tempoMap), tempoMap); var ticksPerQuarterNoteTimeDivision = tempoMap.TimeDivision as TicksPerQuarterNoteTimeDivision; if (ticksPerQuarterNoteTimeDivision != null) { return(new MusicalLength(FractionUtilities.FromTicks(length, ticksPerQuarterNoteTimeDivision.TicksPerQuarterNote))); } ThrowIfTimeDivision.IsNotSupportedForLengthConversion(tempoMap.TimeDivision); return(null); }
public long ConvertFrom(ITime time, TempoMap tempoMap) { ThrowIfArgument.IsNull(nameof(time), time); ThrowIfArgument.IsNull(nameof(tempoMap), tempoMap); var metricTime = time as MetricTime; if (metricTime == null) { throw new ArgumentException($"Time is not an instance of the {nameof(MetricTime)}.", nameof(time)); } var ticksPerQuarterNoteTimeDivision = tempoMap.TimeDivision as TicksPerQuarterNoteTimeDivision; if (ticksPerQuarterNoteTimeDivision != null) { return(ConvertFromByTicksPerQuarterNote(metricTime, ticksPerQuarterNoteTimeDivision.TicksPerQuarterNote, tempoMap)); } ThrowIfTimeDivision.IsNotSupportedForTimeConversion(tempoMap.TimeDivision); return(0); }
public long ConvertFrom(ILength length, long time, TempoMap tempoMap) { ThrowIfArgument.IsNull(nameof(length), length); ThrowIfTimeArgument.IsNegative(nameof(time), time); ThrowIfArgument.IsNull(nameof(tempoMap), tempoMap); var musicalLength = length as MusicalLength; if (musicalLength == null) { throw new ArgumentException($"Length is not an instance of the {nameof(MusicalLength)}.", nameof(length)); } var ticksPerQuarterNoteTimeDivision = tempoMap.TimeDivision as TicksPerQuarterNoteTimeDivision; if (ticksPerQuarterNoteTimeDivision != null) { return(musicalLength.Fraction.ToTicks(ticksPerQuarterNoteTimeDivision.TicksPerQuarterNote)); } ThrowIfTimeDivision.IsNotSupportedForLengthConversion(tempoMap.TimeDivision); return(0); }