Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
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);
        }