private void OnTick(object sender, TickedEventArgs e)
        {
            if (_disposed || !IsWatching)
            {
                return;
            }

            var times = new List <PlaybackCurrentTime>();

            lock (_playbacksLock)
            {
                foreach (var playback in _playbacks)
                {
                    var currentTime = playback.Key.GetCurrentTime(playback.Value);
                    times.Add(new PlaybackCurrentTime(playback.Key, currentTime));
                }
            }

            if (times.Any())
            {
                OnCurrentTimeChanged(times);
            }
        }
Esempio n. 2
0
        private void OnClockTicked(object sender, TickedEventArgs e)
        {
            var time = e.Time;

            do
            {
                var playbackEvent = _eventsEnumerator.Current;
                if (playbackEvent == null)
                {
                    continue;
                }

                if (playbackEvent.Time > time)
                {
                    return;
                }

                var midiEvent = playbackEvent.Event;
                if (midiEvent == null)
                {
                    continue;
                }

                if (!IsRunning)
                {
                    return;
                }

                Note note;
                if (TryPlayNoteEvent(playbackEvent, out note))
                {
                    if (note != null)
                    {
                        if (playbackEvent.Event is NoteOnEvent)
                        {
                            OnNotesPlaybackStarted(note);
                        }
                        else
                        {
                            OnNotesPlaybackFinished(note);
                        }
                    }

                    continue;
                }

                var eventCallback = EventCallback;
                if (eventCallback != null)
                {
                    midiEvent = eventCallback(midiEvent.Clone(), playbackEvent.RawTime, time);
                }

                if (midiEvent == null)
                {
                    continue;
                }

                SendEvent(midiEvent);
            }while (_eventsEnumerator.MoveNext());

            if (!Loop)
            {
                _clock.Stop();
                OnFinished();
                return;
            }

            _clock.Stop();
            _clock.Reset();
            _eventsEnumerator.Reset();
            _eventsEnumerator.MoveNext();
            _clock.Start();
        }