diff --git a/Lib.Midi/Factories/IMidiCommunicationFactory.cs b/Lib.Midi/Factories/IMidiCommunicationFactory.cs new file mode 100644 index 0000000..b228134 --- /dev/null +++ b/Lib.Midi/Factories/IMidiCommunicationFactory.cs @@ -0,0 +1,13 @@ +// Author: Gockner, Simon +// Created: 2021-04-09 +// Copyright(c) 2021 SimonG. All Rights Reserved. + +using Lib.Midi.Interfaces; + +namespace Lib.Midi.Factories +{ + public interface IMidiCommunicationFactory + { + IMidiCommunication Create(); + } +} \ No newline at end of file diff --git a/Lib.Midi/Factories/IMidiMessageFactory.cs b/Lib.Midi/Factories/IMidiMessageFactory.cs new file mode 100644 index 0000000..e1d3c22 --- /dev/null +++ b/Lib.Midi/Factories/IMidiMessageFactory.cs @@ -0,0 +1,14 @@ +// Author: Gockner, Simon +// Created: 2021-04-09 +// Copyright(c) 2021 SimonG. All Rights Reserved. + +using Lib.Midi.Interfaces; +using NAudio.Midi; + +namespace Lib.Midi.Factories +{ + public interface IMidiMessageFactory + { + IMidiMessage Create(MidiInMessageEventArgs midiInMessageEventArgs); + } +} \ No newline at end of file diff --git a/Lib.Midi/Interfaces/IMidiCommunication.cs b/Lib.Midi/Interfaces/IMidiCommunication.cs new file mode 100644 index 0000000..68b3ab5 --- /dev/null +++ b/Lib.Midi/Interfaces/IMidiCommunication.cs @@ -0,0 +1,18 @@ +// Author: Gockner, Simon +// Created: 2021-04-09 +// Copyright(c) 2021 SimonG. All Rights Reserved. + +using System; + +namespace Lib.Midi.Interfaces +{ + public interface IMidiCommunication + { + void Open(); + void Close(); + + void Send(IMidiMessage message); + + event EventHandler MessageReceived; + } +} \ No newline at end of file diff --git a/Lib.Midi/Interfaces/IMidiMessage.cs b/Lib.Midi/Interfaces/IMidiMessage.cs new file mode 100644 index 0000000..a41c5bd --- /dev/null +++ b/Lib.Midi/Interfaces/IMidiMessage.cs @@ -0,0 +1,11 @@ +// Author: Gockner, Simon +// Created: 2021-04-09 +// Copyright(c) 2021 SimonG. All Rights Reserved. + +namespace Lib.Midi.Interfaces +{ + public interface IMidiMessage + { + + } +} \ No newline at end of file diff --git a/Lib.Midi/Lib.Midi.csproj b/Lib.Midi/Lib.Midi.csproj new file mode 100644 index 0000000..71db116 --- /dev/null +++ b/Lib.Midi/Lib.Midi.csproj @@ -0,0 +1,12 @@ + + + + net5.0 + enable + + + + + + + diff --git a/Lib.Midi/MidiCommunication.cs b/Lib.Midi/MidiCommunication.cs new file mode 100644 index 0000000..374aa69 --- /dev/null +++ b/Lib.Midi/MidiCommunication.cs @@ -0,0 +1,56 @@ +// Author: Gockner, Simon +// Created: 2021-04-09 +// Copyright(c) 2021 SimonG. All Rights Reserved. + +using System; +using Lib.Midi.Interfaces; +using NAudio.Midi; + +namespace Lib.Midi +{ + public class MidiCommunication : IMidiCommunication + { + private readonly MidiIn _midiIn; + private readonly MidiOut _midiOut; + + public MidiCommunication() + { + _midiIn = new MidiIn(0); //TODO: don't always use device 0? + _midiOut = new MidiOut(0); + } + + public void Open() + { + _midiIn.MessageReceived += OnMidiInMessageReceived; + _midiIn.ErrorReceived += OnMidiInErrorReceived; + _midiIn.Start(); + } + + public void Close() + { + _midiIn.Stop(); + _midiIn.MessageReceived -= OnMidiInMessageReceived; + _midiIn.ErrorReceived -= OnMidiInErrorReceived; + + _midiIn.Close(); + _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 event EventHandler? MessageReceived; + } +} \ No newline at end of file diff --git a/Lib.Midi/MidiMessage.cs b/Lib.Midi/MidiMessage.cs new file mode 100644 index 0000000..d2dbea2 --- /dev/null +++ b/Lib.Midi/MidiMessage.cs @@ -0,0 +1,17 @@ +// Author: Gockner, Simon +// Created: 2021-04-09 +// Copyright(c) 2021 SimonG. All Rights Reserved. + +using Lib.Midi.Interfaces; +using NAudio.Midi; + +namespace Lib.Midi +{ + public class MidiMessage : IMidiMessage + { + public MidiMessage(MidiInMessageEventArgs midiInMessageEventArgs) + { + + } + } +} \ No newline at end of file