コード例 #1
0
        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);
        }
コード例 #2
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);
        }
コード例 #3
0
        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);
        }
コード例 #4
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);
        }