public static MusicType GetMusicType(DeviceHandle handle) { var musicType = MusicType.Invalid; var device = MusicManager.GetPlugins().SelectMany(p => p.GetDevices()).FirstOrDefault(d => Equals(d.Handle, handle)); if (device != null) { musicType = device.MusicType; } return(musicType); }
/// <summary> /// Create music driver matching the given device handle, or NULL if there is no match. /// </summary> /// <returns>The midi.</returns> /// <param name = "mixer"></param> /// <param name="handle">Handle.</param> public static IMidiDriver CreateMidi(IMixer mixer, DeviceHandle handle) { IMidiDriver driver = null; var plugins = MusicManager.GetPlugins(); foreach (var m in plugins) { if (GetDeviceString(handle, DeviceStringType.DriverId) == m.Id) { driver = m.CreateInstance(mixer, handle); } } return(driver); }
/// <summary> /// Gets the device description string matching the given device handle and the given type. /// </summary> /// <returns>The device string.</returns> /// <param name="handle">Handle.</param> /// <param name="type">Type.</param> static string GetDeviceString(DeviceHandle handle, DeviceStringType type) { if (handle.IsValid) { var p = MusicManager.GetPlugins(); foreach (var m in p) { var devices = m.GetDevices(); foreach (var d in devices) { if (Equals(handle, d.Handle)) { if (type == DeviceStringType.DriverName) { return(d.MusicDriverName); } else if (type == DeviceStringType.DriverId) { return(d.MusicDriverId); } else if (type == DeviceStringType.DeviceName) { return(d.CompleteName); } else if (type == DeviceStringType.DeviceId) { return(d.CompleteId); } else { return("auto"); } } } } } return("auto"); }
/// <summary> /// Gets the device description string matching the given device handle and the given type. /// </summary> /// <returns>The device string.</returns> /// <param name="handle">Handle.</param> /// <param name="type">Type.</param> static string GetDeviceString(DeviceHandle handle, DeviceStringType type) { if (handle.IsValid) { var p = MusicManager.GetPlugins(); foreach (var m in p) { var devices = m.GetDevices(); foreach (var d in devices) { if (Equals(handle, d.Handle)) { if (type == DeviceStringType.DriverName) return d.MusicDriverName; else if (type == DeviceStringType.DriverId) return d.MusicDriverId; else if (type == DeviceStringType.DeviceName) return d.CompleteName; else if (type == DeviceStringType.DeviceId) return d.CompleteId; else return "auto"; } } } } return "auto"; }
public static MusicType GetMusicType(DeviceHandle handle) { var musicType = MusicType.Invalid; var device = MusicManager.GetPlugins().SelectMany(p => p.GetDevices()).FirstOrDefault(d => Equals(d.Handle, handle)); if (device != null) { musicType = device.MusicType; } return musicType; }
/// <summary> /// Returns the device handle based on the present devices and the flags parameter. /// </summary> /// <returns>The device handle based on the present devices and the flags parameter.</returns> /// <param name="flags">Flags.</param> /// <param name = "selectedDevice">The selected device</param> public static DeviceHandle DetectDevice(MusicDriverTypes flags, string selectedDevice) { var result = new DeviceHandle(); var handle = GetDeviceHandle(selectedDevice); var musicType = GetMusicType(handle); switch (musicType) { case MusicType.PCSpeaker: if (flags.HasFlag(MusicDriverTypes.PCSpeaker)) { result = handle; } break; case MusicType.PCjr: if (flags.HasFlag(MusicDriverTypes.PCjr)) { result = handle; } break; case MusicType.AdLib: if (flags.HasFlag(MusicDriverTypes.AdLib)) { result = handle; } break; case MusicType.CMS: if (flags.HasFlag(MusicDriverTypes.CMS)) { result = handle; } break; case MusicType.FMTowns: if (flags.HasFlag(MusicDriverTypes.FMTowns)) { result = handle; } break; case MusicType.Null: result = handle; break; } if (!result.IsValid) { MusicType mt = MusicType.Null; if (flags.HasFlag(MusicDriverTypes.FMTowns)) { mt = MusicType.FMTowns; } else if (flags.HasFlag(MusicDriverTypes.AdLib)) { mt = MusicType.AdLib; } else if (flags.HasFlag(MusicDriverTypes.PCjr)) { mt = MusicType.PCjr; } else if (flags.HasFlag(MusicDriverTypes.PCSpeaker)) { mt = MusicType.PCSpeaker; } var device = MusicManager.GetPlugins().SelectMany(p => p.GetDevices()).FirstOrDefault(d => d.MusicType == mt); if (device != null) { result = device.Handle; } } return result; }
/// <summary> /// Create music driver matching the given device handle, or NULL if there is no match. /// </summary> /// <returns>The midi.</returns> /// <param name = "mixer"></param> /// <param name="handle">Handle.</param> public static IMidiDriver CreateMidi(IMixer mixer, DeviceHandle handle) { IMidiDriver driver = null; var plugins = MusicManager.GetPlugins(); foreach (var m in plugins) { if (GetDeviceString(handle, DeviceStringType.DriverId) == m.Id) driver = m.CreateInstance(mixer, handle); } return driver; }
public virtual bool CheckDevice(DeviceHandle handle) { return true; }
public abstract IMidiDriver CreateInstance(IMixer mixer, DeviceHandle handle);
public virtual bool CheckDevice(DeviceHandle handle) { return(true); }
/// <summary> /// Returns the device handle based on the present devices and the flags parameter. /// </summary> /// <returns>The device handle based on the present devices and the flags parameter.</returns> /// <param name="flags">Flags.</param> /// <param name = "selectedDevice">The selected device</param> public static DeviceHandle DetectDevice(MusicDriverTypes flags, string selectedDevice) { var result = new DeviceHandle(); var handle = GetDeviceHandle(selectedDevice); var musicType = GetMusicType(handle); switch (musicType) { case MusicType.PCSpeaker: if (flags.HasFlag(MusicDriverTypes.PCSpeaker)) { result = handle; } break; case MusicType.PCjr: if (flags.HasFlag(MusicDriverTypes.PCjr)) { result = handle; } break; case MusicType.AdLib: if (flags.HasFlag(MusicDriverTypes.AdLib)) { result = handle; } break; case MusicType.CMS: if (flags.HasFlag(MusicDriverTypes.CMS)) { result = handle; } break; case MusicType.FMTowns: if (flags.HasFlag(MusicDriverTypes.FMTowns)) { result = handle; } break; case MusicType.Null: result = handle; break; } if (!result.IsValid) { MusicType mt = MusicType.Null; if (flags.HasFlag(MusicDriverTypes.FMTowns)) { mt = MusicType.FMTowns; } else if (flags.HasFlag(MusicDriverTypes.AdLib)) { mt = MusicType.AdLib; } else if (flags.HasFlag(MusicDriverTypes.PCjr)) { mt = MusicType.PCjr; } else if (flags.HasFlag(MusicDriverTypes.PCSpeaker)) { mt = MusicType.PCSpeaker; } var device = MusicManager.GetPlugins().SelectMany(p => p.GetDevices()).FirstOrDefault(d => d.MusicType == mt); if (device != null) { result = device.Handle; } } return(result); }