public static MIDIInputDevice GetInputDevice(int deviceID, ITranslationMap translationMap = null, bool failSilently = false) { if (DevicesInUse != null && DevicesInUse.Any(device => device.DeviceID == deviceID)) return DevicesInUse.First(device => device.DeviceID == deviceID); else { if (FreeDevices.Any(d => d.DeviceID == deviceID)) { return CreateInputDevice(deviceID, translationMap); } else { if (failSilently) return null; else throw new Exception($"No device with ID {deviceID} found."); } } }
public static MIDIInputDevice GetInputDevice(string name, ITranslationMap translationMap = null, bool failSilently = false) { Func<dynamic, bool> nameMatch = d => d.Name.Equals(name, StringComparison.OrdinalIgnoreCase); if (DevicesInUse != null && DevicesInUse.Any(nameMatch)) return DevicesInUse.First(nameMatch); else { if (FreeDevices.Any(nameMatch)) { var deviceID = FreeDevices.Single(d => d.Name == name).DeviceID; return CreateInputDevice(deviceID, translationMap); } else { if (failSilently) return null; else throw new Exception($"No device with name {name} found."); } } }
public MIDIInputDevice(int deviceID, ITranslationMap translationMap = null) : base(deviceID) { TranslationMap = translationMap; ChannelMessageReceived += MIDIInputDevice_ChannelMessageReceived; }
private static MIDIInputDevice CreateInputDevice(int deviceID, ITranslationMap translationMap = null) { var device = new MIDIInputDevice(deviceID, translationMap); DevicesInUse.Add(device); return device; }