- add midi lib

master
Simon G 5 years ago
parent a50a93aff3
commit b1cba90c06
  1. 13
      Lib.Midi/Factories/IMidiCommunicationFactory.cs
  2. 14
      Lib.Midi/Factories/IMidiMessageFactory.cs
  3. 18
      Lib.Midi/Interfaces/IMidiCommunication.cs
  4. 11
      Lib.Midi/Interfaces/IMidiMessage.cs
  5. 12
      Lib.Midi/Lib.Midi.csproj
  6. 56
      Lib.Midi/MidiCommunication.cs
  7. 17
      Lib.Midi/MidiMessage.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();
}
}

@ -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);
}
}

@ -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<IMidiMessage> MessageReceived;
}
}

@ -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
{
}
}

@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NAudio.Midi" Version="2.0.0" />
</ItemGroup>
</Project>

@ -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<IMidiMessage>? MessageReceived;
}
}

@ -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)
{
}
}
}
Loading…
Cancel
Save