Ejemplo n.º 1
0
        public long ConvertFrom(ITime time, TempoMap tempoMap)
        {
            ThrowIfArgument.IsNull(nameof(time), time);
            ThrowIfArgument.IsNull(nameof(tempoMap), tempoMap);

            var mathTime = time as MathTime;

            if (mathTime == null)
            {
                throw new ArgumentException($"Time is not an instance of the {nameof(MathTime)}.", nameof(time));
            }

            var result = mathTime.Time != null
                ? TimeConverter.ConvertFrom(mathTime.Time, tempoMap)
                : mathTime.MidiTime;

            switch (mathTime.Operation)
            {
            case MathOperation.Sum:
                return(result + LengthConverter.ConvertFrom(mathTime.Offset, result, tempoMap));

            case MathOperation.Subtract:
                return(result - LengthConverter.ConvertFrom(mathTime.Offset, result, tempoMap.Flip(result)));
            }

            throw new NotImplementedException($"Conversion from the {nameof(MathTime)} with {mathTime.Operation} operation is not implemented.");
        }
Ejemplo n.º 2
0
        private static long ConvertFromTimeLength(MathTimeSpan mathTimeSpan, long time, TempoMap tempoMap)
        {
            var convertedTimeSpan1 = TimeConverter.ConvertFrom(mathTimeSpan.TimeSpan1, tempoMap);

            switch (mathTimeSpan.Operation)
            {
            case MathOperation.Add:
                return(convertedTimeSpan1 + LengthConverter.ConvertFrom(mathTimeSpan.TimeSpan2,
                                                                        convertedTimeSpan1,
                                                                        tempoMap));

            case MathOperation.Subtract:
                return(convertedTimeSpan1 - LengthConverter.ConvertFrom(mathTimeSpan.TimeSpan2,
                                                                        convertedTimeSpan1,
                                                                        tempoMap.Flip(convertedTimeSpan1)));

            default:
                throw new ArgumentException($"{mathTimeSpan.Operation} is not supported by the converter.", nameof(mathTimeSpan));
            }
        }
Ejemplo n.º 3
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 mathLength = length as MathLength;

            if (mathLength == null)
            {
                throw new ArgumentException($"Length is not an instance of the {nameof(MathLength)}.", nameof(length));
            }

            var convertedLength1 = LengthConverter.ConvertFrom(mathLength.Length1, time, tempoMap);
            var endTime1         = time + convertedLength1;

            switch (mathLength.Operation)
            {
            case MathOperation.Sum:
                return(convertedLength1 + LengthConverter.ConvertFrom(mathLength.Length2, endTime1, tempoMap));

            case MathOperation.Subtract:
                return(convertedLength1 - LengthConverter.ConvertFrom(mathLength.Length2, endTime1, tempoMap.Flip(endTime1)));
            }

            throw new NotImplementedException($"Conversion from the {nameof(MathLength)} with {mathLength.Operation} operation is not implemented.");
        }