public MidiOutput(string deviceName = null, bool ignoreMissingDevice = false, [System.Runtime.CompilerServices.CallerMemberName] string name = "")
{
string midiDeviceName = deviceName;
if (string.IsNullOrEmpty(deviceName))
midiDeviceName = Executor.Current.GetSetKey(this, name + ".DeviceName", string.Empty);
int selectedDeviceId = -1;
for (int i = 0; i < OutputDevice.DeviceCount; i++)
{
var midiCap = OutputDevice.GetDeviceCapabilities(i);
if (midiCap.name == midiDeviceName)
{
selectedDeviceId = i;
break;
}
}
if (selectedDeviceId == -1)
{
if (!ignoreMissingDevice)
throw new ArgumentException("Midi device not detected");
else
log.Warn("Midi device not detected");
}
else
{
this.outputDevice = new OutputDevice(selectedDeviceId);
this.outputDevice.Error += outputDevice_Error;
if (string.IsNullOrEmpty(deviceName))
Executor.Current.SetKey(this, name + ".DeviceName", midiDeviceName);
}
Executor.Current.Register(this);
}