private static void ConvertNotesToCsv(
            IEnumerable <NoteWithCustomTimeAndLength> expectedNotes,
            TempoMap tempoMap,
            TimeSpanType timeType,
            string[] expectedCsvLines,
            NoteNumberFormat noteNumberFormat = NoteNumberFormat.NoteNumber,
            TimeSpanType noteLengthType       = TimeSpanType.Midi,
            char delimiter = ',')
        {
            var filePath = Path.GetTempFileName();

            var settings = new NoteCsvConversionSettings
            {
                TimeType         = timeType,
                NoteNumberFormat = noteNumberFormat,
                NoteLengthType   = noteLengthType
            };

            settings.CsvSettings.CsvDelimiter = delimiter;

            try
            {
                new CsvConverter().ConvertNotesToCsv(expectedNotes.Select(n => n.GetNote(tempoMap)), filePath, tempoMap, true, settings);
                var actualCsvLines = File.ReadAllLines(filePath);
                CollectionAssert.AreEqual(expectedCsvLines, actualCsvLines, StringComparer.OrdinalIgnoreCase);
            }
            finally
            {
                File.Delete(filePath);
            }
        }
Esempio n. 2
0
        private static void ConvertCsvToNotes(
            IEnumerable <NoteWithCustomTimeAndLength> expectedNotes,
            TempoMap tempoMap,
            TimeSpanType timeType,
            string[] csvLines,
            NoteNumberFormat noteNumberFormat = NoteNumberFormat.NoteNumber,
            TimeSpanType noteLengthType       = TimeSpanType.Midi,
            char delimiter = ',')
        {
            var filePath = Path.GetTempFileName();

            File.WriteAllLines(filePath, csvLines);

            var settings = new NoteCsvConversionSettings
            {
                TimeType         = timeType,
                NoteNumberFormat = noteNumberFormat,
                NoteLengthType   = noteLengthType,
                CsvDelimiter     = delimiter
            };

            try
            {
                var actualNotes = new CsvConverter().ConvertCsvToNotes(filePath, tempoMap, settings).ToList();
                _noteMethods.AssertCollectionsAreEqual(expectedNotes.Select(n => n.GetNote(tempoMap)), actualNotes);

                ConvertNotesToFromCsv(actualNotes, tempoMap, filePath, settings);
            }
            finally
            {
                File.Delete(filePath);
            }
        }
Esempio n. 3
0
        public GeneralTimeSpanViewModel(TimeSpanType rpType) : base(rpType)
        {
            switch (rpType)
            {
            case TimeSpanType.All:
                TimeSpanStart = "0";
                TimeSpanEnd   = "strftime('%s', 'now')";
                break;

            case TimeSpanType.Recent24Hours:
                TimeSpanStart = "strftime('%s', 'now', '-1 days')";
                TimeSpanEnd   = "strftime('%s', 'now')";
                break;

            case TimeSpanType.Recent3Days:
                TimeSpanStart = "strftime('%s', 'now', '-3 days')";
                TimeSpanEnd   = "strftime('%s', 'now')";
                break;

            case TimeSpanType.Recent7Days:
                TimeSpanStart = "strftime('%s', 'now', '-7 days')";
                TimeSpanEnd   = "strftime('%s', 'now')";
                break;
            }
        }
        /// <summary>
        /// Resizes group of notes by the specified ratio treating all notes as single object. For example,
        /// resizing by ratio of 0.5 shrinks group of notes by two times.
        /// </summary>
        /// <param name="notes">Notes to resize.</param>
        /// <param name="ratio">Ratio to resize notes by.</param>
        /// <param name="distanceCalculationType">Type of distance calculations.</param>
        /// <param name="tempoMap"></param>
        /// <exception cref="ArgumentNullException"><paramref name="notes"/> is null. -or-
        /// <paramref name="tempoMap"/> is null.</exception>
        /// <exception cref="ArgumentException"><see cref="TimeSpanType.BarBeatTicks"/> or <see cref="TimeSpanType.BarBeatFraction"/>
        /// is used for <paramref name="distanceCalculationType"/> which is unsupported.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="ratio"/> is negative.</exception>
        /// <exception cref="InvalidEnumArgumentException"><paramref name="distanceCalculationType"/> specified an
        /// invalid value.</exception>
        public static void ResizeNotes(this IEnumerable <Note> notes,
                                       double ratio,
                                       TimeSpanType distanceCalculationType,
                                       TempoMap tempoMap)
        {
            ThrowIfArgument.IsNull(nameof(notes), notes);
            ThrowIfArgument.IsNegative(nameof(ratio), ratio, "Ratio is negative");
            ThrowIfArgument.IsInvalidEnumValue(nameof(distanceCalculationType), distanceCalculationType);
            ThrowIfArgument.IsNull(nameof(tempoMap), tempoMap);

            // Unable to calculate ratio between two bar/beat time spans
            if (distanceCalculationType == TimeSpanType.BarBeatTicks || distanceCalculationType == TimeSpanType.BarBeatFraction)
            {
                throw new ArgumentException("BarBeat distance calculation type is not supported.", nameof(distanceCalculationType));
            }

            var notNullNotes = notes.Where(n => n != null);

            if (!notNullNotes.Any())
            {
                return;
            }

            //

            var minStartTime = notNullNotes.Select(n => n.Time).Min();
            var startTime    = TimeConverter.ConvertTo(minStartTime, distanceCalculationType, tempoMap);

            ResizeNotesByRatio(notNullNotes, ratio, distanceCalculationType, tempoMap, startTime);
        }
Esempio n. 5
0
        private static void ConvertMidiFileToCsv(
            MidiFile midiFile,
            MidiFileCsvLayout layout,
            TimeSpanType timeType,
            string[] expectedCsvLines,
            NoteFormat noteFormat             = NoteFormat.Events,
            NoteNumberFormat noteNumberFormat = NoteNumberFormat.NoteNumber,
            TimeSpanType noteLengthType       = TimeSpanType.Midi)
        {
            var filePath = Path.GetTempFileName();

            var settings = new MidiFileCsvConversionSettings
            {
                CsvLayout        = layout,
                TimeType         = timeType,
                NoteFormat       = noteFormat,
                NoteNumberFormat = noteNumberFormat,
                NoteLengthType   = noteLengthType
            };

            try
            {
                new CsvConverter().ConvertMidiFileToCsv(midiFile, filePath, true, settings);
                var actualCsvLines = File.ReadAllLines(filePath);
                CollectionAssert.AreEqual(expectedCsvLines, actualCsvLines, StringComparer.OrdinalIgnoreCase);
            }
            finally
            {
                File.Delete(filePath);
            }
        }
Esempio n. 6
0
        [Command(501)] // 4.0.0+
        // CalculateSpanBetween(buffer<nn::time::sf::ClockSnapshot, 0x19>, buffer<nn::time::sf::ClockSnapshot, 0x19>) -> nn::TimeSpanType
        public ResultCode CalculateSpanBetween(ServiceCtx context)
        {
            ClockSnapshot clockSnapshotA = ReadClockSnapshotFromBuffer(context, context.Request.PtrBuff[0]);
            ClockSnapshot clockSnapshotB = ReadClockSnapshotFromBuffer(context, context.Request.PtrBuff[1]);

            TimeSpanType result;

            ResultCode resultCode = clockSnapshotA.SteadyClockTimePoint.GetSpanBetween(clockSnapshotB.SteadyClockTimePoint, out long timeSpan);

            if (resultCode != ResultCode.Success)
            {
                resultCode = ResultCode.TimeNotFound;

                if (clockSnapshotA.NetworkTime != 0 && clockSnapshotB.NetworkTime != 0)
                {
                    result     = TimeSpanType.FromSeconds(clockSnapshotB.NetworkTime - clockSnapshotA.NetworkTime);
                    resultCode = ResultCode.Success;
                }
                else
                {
                    return(resultCode);
                }
            }
            else
            {
                result = TimeSpanType.FromSeconds(timeSpan);
            }

            context.ResponseData.Write(result.NanoSeconds);

            return(resultCode);
        }
Esempio n. 7
0
        [Command(300)] // 4.0.0+
        // CalculateMonotonicSystemClockBaseTimePoint(nn::time::SystemClockContext) -> s64
        public ResultCode CalculateMonotonicSystemClockBaseTimePoint(ServiceCtx context)
        {
            SteadyClockCore steadyClock = _timeManager.StandardSteadyClock;

            if (!steadyClock.IsInitialized())
            {
                return(ResultCode.UninitializedClock);
            }

            SystemClockContext   otherContext     = context.RequestData.ReadStruct <SystemClockContext>();
            SteadyClockTimePoint currentTimePoint = steadyClock.GetCurrentTimePoint(context.Thread);

            ResultCode result = ResultCode.TimeMismatch;

            if (currentTimePoint.ClockSourceId == otherContext.SteadyTimePoint.ClockSourceId)
            {
                TimeSpanType ticksTimeSpan = TimeSpanType.FromTicks(context.Thread.Context.CntpctEl0, context.Thread.Context.CntfrqEl0);
                long         baseTimePoint = otherContext.Offset + currentTimePoint.TimePoint - ticksTimeSpan.ToSeconds();

                context.ResponseData.Write(baseTimePoint);

                result = ResultCode.Success;
            }

            return(result);
        }
        private static MidiFile ConvertCsvToMidiFile(
            MidiFileCsvLayout layout,
            TimeSpanType timeType,
            string[] csvLines,
            NoteFormat noteFormat             = NoteFormat.Events,
            NoteNumberFormat noteNumberFormat = NoteNumberFormat.NoteNumber,
            TimeSpanType noteLengthType       = TimeSpanType.Midi)
        {
            var filePath = Path.GetTempFileName();

            File.WriteAllLines(filePath, csvLines);

            var settings = new MidiFileCsvConversionSettings
            {
                CsvLayout        = layout,
                TimeType         = timeType,
                NoteFormat       = noteFormat,
                NoteNumberFormat = noteNumberFormat,
                NoteLengthType   = noteLengthType
            };

            try
            {
                var midiFile = new CsvConverter().ConvertCsvToMidiFile(filePath, settings);
                ConvertMidiFileToFromCsv(midiFile, filePath, settings);
                return(midiFile);
            }
            finally
            {
                File.Delete(filePath);
            }
        }
Esempio n. 9
0
 /// <summary>
 /// Add a timed event to this container, if there is enough space
 /// </summary>
 public void AddTimedEvent(TimeSpanType type, int timeSpan, string message,
                           string parameter1, string parameter2)
 {
     for (int i = 0; i < size; i++)
     {
         ref var Tuple = ref events[i];
         ref var Event = ref Tuple.timedEvent;
Esempio n. 10
0
        public void SetStandardSteadyClockRtcOffset(ITickSource tickSource, TimeSpanType rtcOffset)
        {
            StandardSteadyClock.SetSetupValue(rtcOffset);

            TimeSpanType currentTimePoint = StandardSteadyClock.GetCurrentRawTimePoint(tickSource);

            SharedMemory.SetSteadyClockRawTimePoint(tickSource, currentTimePoint);
        }
Esempio n. 11
0
        /// <summary>
        /// Converts time from one time type to another one.
        /// </summary>
        /// <param name="time">Time to convert.</param>
        /// <param name="timeType">Type that will represent the time of an object.</param>
        /// <param name="tempoMap">Tempo map used to convert <paramref name="time"/>.</param>
        /// <returns>Time as an instance of time span defined by <paramref name="timeType"/>.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="time"/> is null. -or-
        /// <paramref name="tempoMap"/> is null.</exception>
        /// <exception cref="InvalidEnumArgumentException"><paramref name="timeType"/> specified an invalid value.</exception>
        public static ITimeSpan ConvertTo(ITimeSpan time, TimeSpanType timeType, TempoMap tempoMap)
        {
            ThrowIfArgument.IsNull(nameof(time), time);
            ThrowIfArgument.IsInvalidEnumValue(nameof(timeType), timeType);
            ThrowIfArgument.IsNull(nameof(tempoMap), tempoMap);

            return(TimeSpanConverter.ConvertTo(time, timeType, 0, tempoMap));
        }
Esempio n. 12
0
        /// <summary>
        /// Gets length of an <see cref="ILengthedObject"/> as an instance of type defined by the
        /// specified time span type.
        /// </summary>
        /// <param name="obj">Object to get length of.</param>
        /// <param name="lengthType">The type of time span to convert the length of <paramref name="obj"/> to.</param>
        /// <param name="tempoMap">Tempo map to calculate length of the <paramref name="obj"/>.</param>
        /// <returns>Time of the specified object as an instance of time span defined by the
        /// <paramref name="lengthType"/>.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="obj"/> is null. -or-
        /// <paramref name="tempoMap"/> is null.</exception>
        /// <exception cref="InvalidEnumArgumentException"><paramref name="lengthType"/> specified an invalid value.</exception>
        public static ITimeSpan LengthAs(this ILengthedObject obj, TimeSpanType lengthType, TempoMap tempoMap)
        {
            ThrowIfArgument.IsNull(nameof(obj), obj);
            ThrowIfArgument.IsInvalidEnumValue(nameof(lengthType), lengthType);
            ThrowIfArgument.IsNull(nameof(tempoMap), tempoMap);

            return(LengthConverter.ConvertTo(obj.Length, lengthType, obj.Time, tempoMap));
        }
Esempio n. 13
0
        // SetTestOffset(nn::TimeSpanType)
        public ResultCode SetTestOffset(ServiceCtx context)
        {
            TimeSpanType testOffset = context.RequestData.ReadStruct <TimeSpanType>();

            StandardSteadyClockCore.Instance.SetTestOffset(testOffset);

            return(0);
        }
Esempio n. 14
0
        [Command(201)] // 3.0.0-3.0.2
        // SetInternalOffset(nn::TimeSpanType)
        public ResultCode SetInternalOffset(ServiceCtx context)
        {
            TimeSpanType internalOffset = context.RequestData.ReadStruct <TimeSpanType>();

            StandardSteadyClockCore.Instance.SetInternalOffset(internalOffset);

            return(ResultCode.Success);
        }
Esempio n. 15
0
        // SetStandardSteadyClockRtcOffset(nn::TimeSpanType rtc_offset)
        public ResultCode SetStandardSteadyClockRtcOffset(ServiceCtx context)
        {
            TimeSpanType rtcOffset = context.RequestData.ReadStruct <TimeSpanType>();

            _timeManager.SetStandardSteadyClockRtcOffset(context.Thread, rtcOffset);

            return(ResultCode.Success);
        }
Esempio n. 16
0
 public BufferSlot()
 {
     GraphicBuffer    = new AndroidStrongPointer <GraphicBuffer>();
     BufferState      = BufferState.Free;
     QueueTime        = TimeSpanType.Zero;
     PresentationTime = TimeSpanType.Zero;
     IsPreallocated   = false;
 }
Esempio n. 17
0
        public void SetStandardSteadyClockRtcOffset(KThread thread, TimeSpanType rtcOffset)
        {
            StandardSteadyClock.SetSetupValue(rtcOffset);

            TimeSpanType currentTimePoint = StandardSteadyClock.GetCurrentRawTimePoint(thread);

            SharedMemory.SetSteadyClockRawTimePoint(thread, currentTimePoint);
        }
        /// <summary>
        /// Gets time of an <see cref="ITimedObject"/> as an instance of time span defined by the
        /// specified time span type.
        /// </summary>
        /// <param name="obj">Object to get time of.</param>
        /// <param name="timeType">The type of time span to convert the time of <paramref name="obj"/> to.</param>
        /// <param name="tempoMap">Tempo map to calculate time of the <paramref name="obj"/>.</param>
        /// <returns>Time of the specified object as an instance of time span defined by the
        /// <paramref name="timeType"/>.</returns>
        /// <exception cref="ArgumentNullException">
        /// <para>One of the following errors occured:</para>
        /// <list type="bullet">
        /// <item>
        /// <description><paramref name="obj"/> is <c>null</c>.</description>
        /// </item>
        /// <item>
        /// <description><paramref name="tempoMap"/> is <c>null</c>.</description>
        /// </item>
        /// </list>
        /// </exception>
        /// <exception cref="InvalidEnumArgumentException"><paramref name="timeType"/> specified an invalid value.</exception>
        public static ITimeSpan TimeAs(this ITimedObject obj, TimeSpanType timeType, TempoMap tempoMap)
        {
            ThrowIfArgument.IsNull(nameof(obj), obj);
            ThrowIfArgument.IsInvalidEnumValue(nameof(timeType), timeType);
            ThrowIfArgument.IsNull(nameof(tempoMap), tempoMap);

            return(TimeConverter.ConvertTo(obj.Time, timeType, tempoMap));
        }
Esempio n. 19
0
        public static ITimeSpan ConvertTo(ITimeSpan timeSpan, TimeSpanType timeSpanType, long time, TempoMap tempoMap)
        {
            if (timeSpan.GetType() == TimeSpansTypes[timeSpanType])
            {
                return(timeSpan.Clone());
            }

            return(ConvertTo(ConvertFrom(timeSpan, time, tempoMap), timeSpanType, time, tempoMap));
        }
 private static void ResizeNotesByRatio(IEnumerable <Note> notes,
                                        IEnumerable <TimeAndLength> expectedTimesAndLengths,
                                        double ratio,
                                        TimeSpanType lengthType,
                                        TempoMap tempoMap)
 {
     notes.ResizeNotes(ratio, lengthType, tempoMap);
     CheckNotes(notes, expectedTimesAndLengths, tempoMap);
 }
Esempio n. 21
0
        /// <summary>
        /// Converts length from <see cref="long"/> to the specified length type.
        /// </summary>
        /// <param name="length">Length to convert.</param>
        /// <param name="lengthType">Type that will represent the length of an object.</param>
        /// <param name="time">Start time of an object to convert length of.</param>
        /// <param name="tempoMap">Tempo map used to convert <paramref name="length"/>.</param>
        /// <returns>Length as an instance of time span defined by <paramref name="lengthType"/>.</returns>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="length"/> is negative.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="time"/> is null. -or-
        /// <paramref name="tempoMap"/> is null.</exception>
        /// <exception cref="InvalidEnumArgumentException"><paramref name="lengthType"/> specified an invalid value.</exception>
        public static ITimeSpan ConvertTo(long length, TimeSpanType lengthType, ITimeSpan time, TempoMap tempoMap)
        {
            ThrowIfLengthArgument.IsNegative(nameof(length), length);
            ThrowIfArgument.IsInvalidEnumValue(nameof(lengthType), lengthType);
            ThrowIfArgument.IsNull(nameof(time), time);
            ThrowIfArgument.IsNull(nameof(tempoMap), tempoMap);

            return(TimeSpanConverter.ConvertTo(length, lengthType, TimeConverter.ConvertFrom(time, tempoMap), tempoMap));
        }
Esempio n. 22
0
        public void SetSteadyClockRawTimePoint(ITickSource tickSource, TimeSpanType currentTimePoint)
        {
            SteadyClockContext context       = ReadObjectFromSharedMemory <SteadyClockContext>(SteadyClockContextOffset, 4);
            TimeSpanType       ticksTimeSpan = TimeSpanType.FromTicks(tickSource.Counter, tickSource.Frequency);

            context.InternalOffset = (ulong)(currentTimePoint.NanoSeconds - ticksTimeSpan.NanoSeconds);

            WriteObjectToSharedMemory(SteadyClockContextOffset, 4, context);
        }
Esempio n. 23
0
        public void SetSteadyClockRawTimePoint(KThread thread, TimeSpanType currentTimePoint)
        {
            SteadyClockContext context       = ReadObjectFromSharedMemory <SteadyClockContext>(SteadyClockContextOffset, 4);
            TimeSpanType       ticksTimeSpan = TimeSpanType.FromTicks(thread.Context.CntpctEl0, thread.Context.CntfrqEl0);

            context.InternalOffset = (ulong)(currentTimePoint.NanoSeconds - ticksTimeSpan.NanoSeconds);

            WriteObjectToSharedMemory(SteadyClockContextOffset, 4, context);
        }
Esempio n. 24
0
        // SetupStandardNetworkSystemClock(nn::time::SystemClockContext context, nn::TimeSpanType sufficient_accuracy)
        public ResultCode SetupStandardNetworkSystemClock(ServiceCtx context)
        {
            SystemClockContext clockContext       = context.RequestData.ReadStruct <SystemClockContext>();
            TimeSpanType       sufficientAccuracy = context.RequestData.ReadStruct <TimeSpanType>();

            _timeManager.SetupStandardNetworkSystemClock(clockContext, sufficientAccuracy);

            return(ResultCode.Success);
        }
        /// <summary>
        /// Resizes group of notes to the specified length treating all notes as single object.
        /// </summary>
        /// <param name="notes">Notes to resize.</param>
        /// <param name="length">New length of the notes collection.</param>
        /// <param name="distanceCalculationType">Type of distance calculations.</param>
        /// <param name="tempoMap"></param>
        /// <exception cref="ArgumentNullException"><paramref name="notes"/> is null. -or-
        /// <paramref name="length"/> is null. -or- <paramref name="tempoMap"/> is null.</exception>
        /// <exception cref="ArgumentException"><see cref="TimeSpanType.BarBeat"/> used for <paramref name="distanceCalculationType"/>
        /// with relative resizing.</exception>
        /// <exception cref="InvalidEnumArgumentException"><paramref name="distanceCalculationType"/> specified an
        /// invalid value.</exception>
        public static void ResizeNotes(this IEnumerable <Note> notes,
                                       ITimeSpan length,
                                       TimeSpanType distanceCalculationType,
                                       TempoMap tempoMap)
        {
            ThrowIfArgument.IsNull(nameof(notes), notes);
            ThrowIfArgument.IsNull(nameof(length), length);
            ThrowIfArgument.IsInvalidEnumValue(nameof(distanceCalculationType), distanceCalculationType);
            ThrowIfArgument.IsNull(nameof(tempoMap), tempoMap);

            if (distanceCalculationType == TimeSpanType.BarBeat)
            {
                throw new ArgumentException("BarBeat length type is not supported for relative resizing.", nameof(distanceCalculationType));
            }

            if (!notes.Any())
            {
                return;
            }

            //

            var minStartTime = long.MaxValue;
            var maxEndTime   = 0L;

            foreach (var note in notes.Where(n => n != null))
            {
                var noteStartTime = note.Time;
                var noteEndTime   = noteStartTime + note.Length;

                minStartTime = Math.Min(minStartTime, noteStartTime);
                maxEndTime   = Math.Max(maxEndTime, noteEndTime);
            }

            var totalLength = maxEndTime - minStartTime;

            //

            var oldLength = LengthConverter.ConvertTo(totalLength, distanceCalculationType, minStartTime, tempoMap);
            var newLength = LengthConverter.ConvertTo(length, distanceCalculationType, minStartTime, tempoMap);
            var ratio     = TimeSpanUtilities.Divide(newLength, oldLength);

            var startTime = TimeConverter.ConvertTo(minStartTime, distanceCalculationType, tempoMap);

            foreach (var note in notes.Where(n => n != null))
            {
                var noteLength = note.LengthAs(distanceCalculationType, tempoMap);
                var noteTime   = note.TimeAs(distanceCalculationType, tempoMap);

                var scaledShiftFromStart = noteTime.Subtract(startTime, TimeSpanMode.TimeTime).Multiply(ratio);
                note.Time = TimeConverter.ConvertFrom(startTime.Add(scaledShiftFromStart, TimeSpanMode.TimeLength), tempoMap);

                var scaledLength = noteLength.Multiply(ratio);
                note.Length = LengthConverter.ConvertFrom(scaledLength, note.Time, tempoMap);
            }
        }
Esempio n. 26
0
        public void SetupStandardSteadyClock(KThread thread, UInt128 clockSourceId, TimeSpanType setupValue, TimeSpanType internalOffset, TimeSpanType testOffset, bool isRtcResetDetected)
        {
            SetupInternalStandardSteadyClock(clockSourceId, setupValue, internalOffset, testOffset, isRtcResetDetected);

            TimeSpanType currentTimePoint = StandardSteadyClock.GetCurrentRawTimePoint(thread);

            SharedMemory.SetupStandardSteadyClock(thread, clockSourceId, currentTimePoint);

            // TODO: propagate IPC late binding of "time:s" and "time:p"
        }
Esempio n. 27
0
        // SetStandardSteadyClockRtcOffset(nn::TimeSpanType rtc_offset)
        public ResultCode SetStandardSteadyClockRtcOffset(ServiceCtx context)
        {
            TimeSpanType rtcOffset = context.RequestData.ReadStruct <TimeSpanType>();

            ITickSource tickSource = context.Device.System.TickSource;

            _timeManager.SetStandardSteadyClockRtcOffset(tickSource, rtcOffset);

            return(ResultCode.Success);
        }
Esempio n. 28
0
        public UtilityImpl(ITickSource tickSource)
        {
            _x = 123456789;
            _y = 362436069;

            TimeSpanType time = TimeManager.Instance.TickBasedSteadyClock.GetCurrentRawTimePoint(tickSource);

            _w = (uint)(time.NanoSeconds & uint.MaxValue);
            _z = (uint)((time.NanoSeconds >> 32) & uint.MaxValue);
        }
        /// <summary>
        /// Gets the duration of the specified <see cref="MidiFile"/>. Duration is
        /// defined by the time of last MIDI event of the file.
        /// </summary>
        /// <param name="midiFile"><see cref="MidiFile"/> to get duration of.</param>
        /// <param name="durationType">The type of time span representing the duration of <paramref name="midiFile"/>.</param>
        /// <returns>An implementation of <see cref="ITimeSpan"/> representing
        /// duration of <paramref name="midiFile"/>.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="midiFile"/> is <c>null</c>.</exception>
        /// <exception cref="InvalidEnumArgumentException"><paramref name="durationType"/> specified an invalid value.</exception>
        public static ITimeSpan GetDuration(this MidiFile midiFile, TimeSpanType durationType)
        {
            ThrowIfArgument.IsNull(nameof(midiFile), midiFile);
            ThrowIfArgument.IsInvalidEnumValue(nameof(durationType), durationType);

            var tempoMap = midiFile.GetTempoMap();

            return(midiFile.GetTimedEvents().LastOrDefault()?.TimeAs(durationType, tempoMap) ??
                   TimeSpanUtilities.GetZeroTimeSpan(durationType));
        }
        /// <summary>
        /// Adds a playback to the list of ones to watch current times of.
        /// </summary>
        /// <param name="playback">Playback to watch current time of.</param>
        /// <param name="timeType">Type of current time to convert to.</param>
        /// <exception cref="ArgumentNullException"><paramref name="playback"/> is <c>null</c>.</exception>
        /// <exception cref="InvalidEnumArgumentException"><paramref name="timeType"/> specified an invalid value.</exception>
        /// <exception cref="ObjectDisposedException">The current <see cref="PlaybackCurrentTimeWatcher"/>
        /// is disposed.</exception>
        public void AddPlayback(Playback playback, TimeSpanType timeType)
        {
            ThrowIfArgument.IsNull(nameof(playback), playback);
            ThrowIfArgument.IsInvalidEnumValue(nameof(timeType), timeType);
            EnsureIsNotDisposed();

            lock (_playbacksLock)
            {
                _playbacks[playback] = timeType;
            }
        }
Esempio n. 31
0
        private TypeScriptType GetTypeScriptType(Type type)
        {
            TypeScriptType tst;

              if (TypeHelper.Is(type, typeof(string)))
              {
            tst = new StringType();
              }
              else if (TypeHelper.Is(type, typeof(bool)))
              {
            tst = new BooleanType();
              }
              else if (TypeHelper.Is(type, typeof(int),
                                        typeof(decimal),
                                        typeof(double),
                                        typeof(long),
                                        typeof(float),
                                        typeof(short),
                                        typeof(byte),
                                        typeof(uint),
                                        typeof(ushort),
                                        typeof(ulong),
                                        typeof(sbyte)
                                        ))
              {
            tst = new NumberType();
              }
              else if (TypeHelper.Is(type, typeof(DateTime)))
              {
            tst = new DateTimeType();
              }
              else if (TypeHelper.Is(type, typeof(TimeSpan)))
              {
            tst = new TimeSpanType();
              }
              else if (type.IsGenericParameter)
              {
            tst = new GenericTypeParameter();
              }
              else if (TypeHelper.IsDictionary(type))
              {
            tst = new DictionaryType();
              }
              else if (TypeHelper.IsEnumerable(type))
              {
            tst = new ArrayType();
              }
              else if (TypeHelper.IsEnum(type))
              {
            tst = new EnumType();
              }
              else
              {
            var processType = _options.TypeFilter(type);

            if (processType)
            {
              if (type.IsInterface)
              {
            tst = new InterfaceType(type);
              }
              else
              {
            tst = new CustomType(type);
              }
            }
            else
            {
              tst = new AnyType();
            }
              }

              if (TypeHelper.IsNullableValueType(type))
              {
            ((ValueType)tst).IsNullable = true;
            type = Nullable.GetUnderlyingType(type);
              }

              tst.ClrType = type;

              return tst;
        }