/// <summary> /// Initializes a new instance of the <see cref="Playback"/> with the specified /// collection of timed objects and tempo map. /// </summary> /// <param name="timedObjects">Collection of timed objects to play.</param> /// <param name="tempoMap">Tempo map used to calculate events times.</param> /// <param name="clockSettings">Settings of the internal playback's clock.</param> /// <exception cref="ArgumentNullException"><paramref name="timedObjects"/> is null. -or- /// <paramref name="tempoMap"/> is null.</exception> public Playback(IEnumerable <ITimedObject> timedObjects, TempoMap tempoMap, MidiClockSettings clockSettings = null) { ThrowIfArgument.IsNull(nameof(timedObjects), timedObjects); ThrowIfArgument.IsNull(nameof(tempoMap), tempoMap); var playbackEvents = GetPlaybackEvents(timedObjects, tempoMap); _eventsEnumerator = playbackEvents.GetEnumerator(); _eventsEnumerator.MoveNext(); var lastPlaybackEvent = playbackEvents.LastOrDefault(); _duration = lastPlaybackEvent?.Time ?? TimeSpan.Zero; _durationInTicks = lastPlaybackEvent?.RawTime ?? 0; _notesMetadata = playbackEvents.Select(e => e.Metadata.Note).Where(m => m != null).ToList(); _notesMetadata.Sort((m1, m2) => m1.StartTime.CompareTo(m2.StartTime)); TempoMap = tempoMap; clockSettings = clockSettings ?? new MidiClockSettings(); _clock = new MidiClock(false, clockSettings.CreateTickGeneratorCallback(ClockInterval)); _clock.Ticked += OnClockTicked; Snapping = new PlaybackSnapping(playbackEvents, tempoMap); }
private void CreateClock(TimeSpan pollingInterval) { _clock = new MidiClock(true, _clockSettings.CreateTickGeneratorCallback(), pollingInterval); _clock.Ticked += OnTick; }