コード例 #1
0
        private void StopStartNotes()
        {
            if (!TrackNotes)
            {
                return;
            }

            var currentTime = _clock.CurrentTime;
            var notesToPlay = _notesMetadata.SkipWhile(m => m.EndTime <= currentTime)
                              .TakeWhile(m => m.StartTime < currentTime)
                              .Where(m => m.StartTime <currentTime && m.EndTime> currentTime)
                              .Select(m => m.Note)
                              .Distinct()
                              .ToArray();
            var notesIds = notesToPlay.Select(n => n.GetNoteId()).ToArray();

            var onNotes  = notesToPlay.Where(n => !_activeNotes.ContainsValue(n)).ToArray();
            var offNotes = _activeNotes.Where(n => !notesIds.Contains(n.Key)).Select(n => n.Value).ToArray();

            OutputDevice.PrepareForEventsSending();

            foreach (var note in offNotes)
            {
                SendEvent(note.TimedNoteOffEvent.Event);
            }

            OnNotesPlaybackFinished(offNotes);

            foreach (var note in onNotes)
            {
                SendEvent(note.TimedNoteOnEvent.Event);
            }

            OnNotesPlaybackStarted(onNotes);
        }
コード例 #2
0
ファイル: Playback.cs プロジェクト: joschemd/drywetmidi
        /// <summary>
        /// Starts playing of the MIDI data. This method is non-blocking.
        /// </summary>
        /// <exception cref="ObjectDisposedException">The current <see cref="Playback"/> is disposed.</exception>
        /// <exception cref="MidiDeviceException">An error occurred on device.</exception>
        public void Start()
        {
            EnsureIsNotDisposed();

            if (_clock.IsRunning)
            {
                return;
            }

            OutputDevice?.PrepareForEventsSending();
            StopStartNotes();
            _clock.Start();

            OnStarted();
        }
コード例 #3
0
        /// <summary>
        /// Starts playing of the MIDI data. This method is non-blocking.
        /// </summary>
        /// <exception cref="ObjectDisposedException">The current <see cref="Playback"/> is disposed.</exception>
        /// <exception cref="MidiDeviceException">An error occurred on device.</exception>
        public void Start()
        {
            EnsureIsNotDisposed();

            if (OutputDevice == null)
            {
                throw new InvalidOperationException("Output device is not set.");
            }

            if (_clock.IsRunning)
            {
                return;
            }

            OutputDevice.PrepareForEventsSending();
            StopStartNotes();
            _clock.Start();

            OnStarted();
        }
コード例 #4
0
ファイル: Playback.cs プロジェクト: mmandel/VirtuosoXR
        public void Start()
        {
            EnsureIsNotDisposed();

            if (_clock.IsRunning)
            {
                return;
            }

            _outputDevice.PrepareForEventsSending();

            foreach (var noteOnEvent in _noteOnEvents.Values)
            {
                _outputDevice.SendEvent(noteOnEvent);
            }
            _noteOnEvents.Clear();

            _clock.Start();
            IsRunning = true;
        }
コード例 #5
0
ファイル: Playback.cs プロジェクト: jrdndj/drywetmidi
        /// <summary>
        /// Starts playing of the MIDI data. This method is non-blocking.
        /// </summary>
        /// <exception cref="ObjectDisposedException">The current <see cref="Playback"/> is disposed.</exception>
        /// <exception cref="MidiDeviceException">An error occurred on device.</exception>
        public void Start()
        {
            EnsureIsNotDisposed();

            if (_clock.IsRunning)
            {
                return;
            }

            if (!_hasBeenStarted)
            {
                MoveToStart();
            }

            OutputDevice?.PrepareForEventsSending();
            SendTrackedData();
            StopStartNotes();
            _clock.Start();

            _hasBeenStarted = true;
            OnStarted();
        }
コード例 #6
0
ファイル: Playback.cs プロジェクト: joschemd/drywetmidi
        private void StopStartNotes()
        {
            if (!TrackNotes)
            {
                return;
            }

            var currentTime = _clock.CurrentTime;
            var notesToPlay = _notesMetadata.SkipWhile(m => m.EndTime <= currentTime)
                              .TakeWhile(m => m.StartTime < currentTime)
                              .Where(m => m.StartTime <currentTime && m.EndTime> currentTime)
                              .Distinct()
                              .ToArray();
            var onNotesMetadata  = notesToPlay.Where(n => !_activeNotesMetadata.Contains(n)).ToArray();
            var offNotesMetadata = _activeNotesMetadata.Where(n => !notesToPlay.Contains(n)).ToArray();

            OutputDevice?.PrepareForEventsSending();

            Note note;
            var  notes = new List <Note>();

            foreach (var noteMetadata in offNotesMetadata)
            {
                TryPlayNoteEvent(noteMetadata, false, currentTime, out note);
                notes.Add(note);
            }

            OnNotesPlaybackFinished(notes.ToArray());
            notes.Clear();

            foreach (var noteMetadata in onNotesMetadata)
            {
                TryPlayNoteEvent(noteMetadata, true, currentTime, out note);
                notes.Add(note);
            }

            OnNotesPlaybackStarted(notes.ToArray());
        }