diff --git a/Lib.Midi/Interfaces/IMidiCommunication.cs b/Lib.Midi/Interfaces/IMidiCommunication.cs index 68b3ab5..a3cc630 100644 --- a/Lib.Midi/Interfaces/IMidiCommunication.cs +++ b/Lib.Midi/Interfaces/IMidiCommunication.cs @@ -14,5 +14,6 @@ namespace Lib.Midi.Interfaces void Send(IMidiMessage message); event EventHandler MessageReceived; + event EventHandler ErrorReceived; } } \ No newline at end of file diff --git a/Lib.Midi/MidiCommunication.cs b/Lib.Midi/MidiCommunication.cs index 374aa69..f9d175c 100644 --- a/Lib.Midi/MidiCommunication.cs +++ b/Lib.Midi/MidiCommunication.cs @@ -3,6 +3,7 @@ // Copyright(c) 2021 SimonG. All Rights Reserved. using System; +using Lib.Midi.Factories; using Lib.Midi.Interfaces; using NAudio.Midi; @@ -10,11 +11,13 @@ namespace Lib.Midi { public class MidiCommunication : IMidiCommunication { + private readonly IMidiMessageFactory _midiMessageFactory; private readonly MidiIn _midiIn; private readonly MidiOut _midiOut; - public MidiCommunication() + public MidiCommunication(IMidiMessageFactory midiMessageFactory) { + _midiMessageFactory = midiMessageFactory; _midiIn = new MidiIn(0); //TODO: don't always use device 0? _midiOut = new MidiOut(0); } @@ -36,21 +39,11 @@ namespace Lib.Midi _midiOut.Close(); } - public void Send(IMidiMessage message) - { - - } - - private void OnMidiInMessageReceived(object? sender, MidiInMessageEventArgs args) - { - int i = 0; - } - - private void OnMidiInErrorReceived(object? sender, MidiInMessageEventArgs args) - { - int i = 0; - } + public void Send(IMidiMessage message) => _midiOut.Send(message.RawMessage); + private void OnMidiInMessageReceived(object? sender, MidiInMessageEventArgs args) => MessageReceived?.Invoke(this, _midiMessageFactory.Create(args)); + private void OnMidiInErrorReceived(object? sender, MidiInMessageEventArgs args) => ErrorReceived?.Invoke(this, _midiMessageFactory.Create(args)); public event EventHandler? MessageReceived; + public event EventHandler? ErrorReceived; } } \ No newline at end of file