Example #1
0
        private void SendEvent(MidiEvent midiEvent)
        {
            _playbackDataTracker.UpdateCurrentData(midiEvent);

            OutputDevice?.SendEvent(midiEvent);
            OnEventPlayed(midiEvent);
        }
Example #2
0
 private void FinishCurrentNotes()
 {
     foreach (var noteId in _noteOnEvents.Keys)
     {
         OutputDevice.SendEvent(new NoteOffEvent(noteId.NoteNumber, SevenBitNumber.MinValue)
         {
             Channel = noteId.Channel
         });
     }
 }
Example #3
0
        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;
        }
Example #4
0
        private void OnClockTick(object sender, TickEventArgs e)
        {
            var time = e.Time;

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

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

                var midiEvent = timedEvent.Event;

                if (!IsRunning)
                {
                    return;
                }

                OutputDevice.SendEvent(midiEvent);

                var noteOnEvent = midiEvent as NoteOnEvent;
                if (noteOnEvent != null)
                {
                    _noteOnEvents[noteOnEvent.GetNoteId()] = noteOnEvent;
                }

                var noteOffEvent = midiEvent as NoteOffEvent;
                if (noteOffEvent != null)
                {
                    _noteOnEvents.Remove(noteOffEvent.GetNoteId());
                }
            }while (_eventsEnumerator.MoveNext());

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

            _clock.StopInternalTimer();
            _clock.Reset();
            _eventsEnumerator.Reset();
            _eventsEnumerator.MoveNext();
            _clock.StartInternalTimer();
        }
Example #5
0
 private void SendEvent(MidiEvent midiEvent)
 {
     OutputDevice?.SendEvent(midiEvent);
     OnEventPlayed(midiEvent);
 }
Example #6
0
 private void SendEvent(MidiEvent midiEvent)
 {
     OutputDevice.SendEvent(midiEvent);
 }