public Dictionary<string, List<AudioLineInfo>> getDeviceNames(Mixer mixer, Dictionary<string, List<AudioLineInfo>> deviceDictionary) { // Clear dictionary of previously added data (in case some devices have been unplugged or new ones have been plugged in) deviceDictionary.Clear(); foreach (MixerDetail mixerDetail in mixer.Devices) { // Get the device's interface name string deviceInterfaceFriendlyName = mixerDetail.MixerName; // Which is set as a dictionary key if a different line already exists for it... if (!deviceDictionary.ContainsKey(deviceInterfaceFriendlyName)) { // If this device interface name hasn't already set as a dictionary key, then create a new entry for it. deviceDictionary[deviceInterfaceFriendlyName] = new List<AudioLineInfo>(); } // Create a mixer object based on the current deviceId so that we can retrieve the lines. mixers = new Mixers(true); Mixer mixer2 = null; // Get proper mixer type if (mixer.MixerType == MixerType.Playback){ mixer2 = mixers.Playback; } else if(mixer.MixerType == MixerType.Recording){ mixer2 = mixers.Recording; } // Set the device id mixer2.DeviceId = mixerDetail.DeviceId; // Retrieve the mixer lines and set them in the dictionar foreach (MixerLine mixerLine in mixer2.UserLines) { /** * Create the line name and interface friendly name (mixer name) pair to associate with the mixer name. * * But what? We are associating the mixer name with the mixer name? Isn't this unecessary redundancy? * We have too because these two values are only identical under XP. In Vista and Windows7 The will be different so this * is why we structure the response this way. * Check out the Vista implementation for further details. */ //KeyValuePair<string, string> lineNameAndFriendlyNamePair = new KeyValuePair<string, string>(mixerLine.Name, mixerDetail.MixerName); // Gather device line properties to associate with the device's interface name. AudioLineInfo audioLineInfo = new AudioLineInfo(); // Line name is confusingly known as the device friendly name. audioLineInfo.LineName = mixerLine.Name; // The device's friendly name (the REAL friendly name). audioLineInfo.FriendlyName = mixerDetail.MixerName; // Is the device line mutable audioLineInfo.Mutable = mixerLine.ContainsMute; deviceDictionary[mixerDetail.MixerName].Add(audioLineInfo); } } return deviceDictionary; }
private Dictionary<string, List<AudioLineInfo>> getDeviceNames(MMDeviceCollection deviceCollection, Dictionary<string, List<AudioLineInfo>> deviceDictionary) { // Clear dictionary of previously added data (in case some devices have been unplugged or new ones have been plugged in) deviceDictionary.Clear() ; for (int i = 0; i < deviceCollection.Count; i++) { MMDevice device = deviceCollection[i]; // Get the device's interface name string deviceInterfaceFriendlyName = getDeviceInterfaceFriendlyName(device); // Which is set as a dictionary key if a different line already exists for it... if (!deviceDictionary.ContainsKey(deviceInterfaceFriendlyName)) { // If this device interface name hasn't already set as a dictionary key, then create a new entry for its deviceDictionary[deviceInterfaceFriendlyName] = new List<AudioLineInfo>(); } // Get the guid of the device. string deviceGuid = device.ID.Substring(device.ID.LastIndexOf("{") + 1, device.ID.LastIndexOf("}") - device.ID.LastIndexOf("{") -1); // Associate to the device's interface name a pair consisting of line name (confusingly known as the device friendly name) and the device's friendly name (the REAL friendly name) string realDeviceFriendlyName = getDeviceFriendlyName(new Guid(deviceGuid), true); // Gather device line properties to associate with the device's interface name. AudioLineInfo audioLineInfo = new AudioLineInfo(); // Line name is confusingly known as the device friendly name. audioLineInfo.LineName = device.FriendlyName; // The device's friendly name (the REAL friendly name). audioLineInfo.FriendlyName = realDeviceFriendlyName; // Device line is always mutable. audioLineInfo.Mutable = true; // Associate the device's interface name with device line properties. deviceDictionary[deviceInterfaceFriendlyName].Add(audioLineInfo); } return deviceDictionary; }