|
|
|
@ -3,6 +3,9 @@ |
|
|
|
// Copyright(c) 2021 SimonG. All Rights Reserved. |
|
|
|
// Copyright(c) 2021 SimonG. All Rights Reserved. |
|
|
|
|
|
|
|
|
|
|
|
using System; |
|
|
|
using System; |
|
|
|
|
|
|
|
using System.Collections.Generic; |
|
|
|
|
|
|
|
using System.Linq; |
|
|
|
|
|
|
|
using Lib.Driver.Interfaces; |
|
|
|
using Lib.Midi.Interfaces; |
|
|
|
using Lib.Midi.Interfaces; |
|
|
|
using Lib.Midi.Messages.Factories; |
|
|
|
using Lib.Midi.Messages.Factories; |
|
|
|
using Lib.Midi.Messages.Interfaces; |
|
|
|
using Lib.Midi.Messages.Interfaces; |
|
|
|
@ -16,11 +19,33 @@ namespace Lib.Midi |
|
|
|
private readonly MidiIn _midiIn; |
|
|
|
private readonly MidiIn _midiIn; |
|
|
|
private readonly MidiOut _midiOut; |
|
|
|
private readonly MidiOut _midiOut; |
|
|
|
|
|
|
|
|
|
|
|
public MidiCommunication(IMidiMessageFactory midiMessageFactory) |
|
|
|
public MidiCommunication(IDriver driver, IMidiMessageFactory midiMessageFactory) |
|
|
|
{ |
|
|
|
{ |
|
|
|
_midiMessageFactory = midiMessageFactory; |
|
|
|
_midiMessageFactory = midiMessageFactory; |
|
|
|
_midiIn = new MidiIn(0); //TODO: don't always use device 0? |
|
|
|
|
|
|
|
_midiOut = new MidiOut(0); |
|
|
|
var midiInput = MidiInputs.FirstOrDefault(i => i.midiInCapabilities.ProductId == driver.ProductId); |
|
|
|
|
|
|
|
var midiOutput = MidiOutputs.FirstOrDefault(o => o.midiOutCapabilities.ProductId == driver.ProductId); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_midiIn = new MidiIn(midiInput.index); |
|
|
|
|
|
|
|
_midiOut = new MidiOut(midiOutput.index); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private IEnumerable<(MidiInCapabilities midiInCapabilities, int index)> MidiInputs |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
get |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
for (int i = 0; i < MidiIn.NumberOfDevices; i++) |
|
|
|
|
|
|
|
yield return (MidiIn.DeviceInfo(i), i); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private IEnumerable<(MidiOutCapabilities midiOutCapabilities, int index)> MidiOutputs |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
get |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
for (int i = 0; i < MidiOut.NumberOfDevices; i++) |
|
|
|
|
|
|
|
yield return (MidiOut.DeviceInfo(i), i); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void Open() |
|
|
|
public void Open() |
|
|
|
|