1.1 --- a/Server/MainForm.cs Sun Feb 08 20:26:36 2015 +0100
1.2 +++ b/Server/MainForm.cs Mon Feb 09 11:09:33 2015 +0100
1.3 @@ -219,6 +219,9 @@
1.4 /// <param name="e"></param>
1.5 private void trackBarMasterVolume_Scroll(object sender, EventArgs e)
1.6 {
1.7 + //Just like Windows Volume Mixer we unmute if the volume is adjusted
1.8 + iMultiMediaDevice.AudioEndpointVolume.Mute = false;
1.9 + //Set volume level according to our volume slider new position
1.10 iMultiMediaDevice.AudioEndpointVolume.MasterVolumeLevelScalar = trackBarMasterVolume.Value / 100.0f;
1.11 }
1.12
1.13 @@ -270,7 +273,8 @@
1.14
1.15
1.16 /// <summary>
1.17 - ///
1.18 + /// Update master volume indicators based our current system states.
1.19 + /// This typically includes volume levels and mute status.
1.20 /// </summary>
1.21 private void UpdateMasterVolumeThreadSafe()
1.22 {
1.23 @@ -288,21 +292,26 @@
1.24 //Update mute checkbox
1.25 checkBoxMute.Checked = iMultiMediaDevice.AudioEndpointVolume.Mute;
1.26
1.27 - //TODO: Check our display device too
1.28 + //If our display connection is open we need to update its icons
1.29 if (iDisplay.IsOpen())
1.30 {
1.31 + //First take care our our volume level icons
1.32 int volumeIconCount = iDisplay.IconCount(Display.TMiniDisplayIconType.EMiniDisplayIconVolume);
1.33 if (volumeIconCount > 0)
1.34 {
1.35 - int currentVolume = Convert.ToInt32(volumeLevelScalar * volumeIconCount);
1.36 -
1.37 - bool roundedUp = currentVolume > (volumeLevelScalar * volumeIconCount);
1.38 + //Compute current volume level from system level and the number of segments in our display volume bar.
1.39 + //That tells us how many segments in our volume bar needs to be turned on.
1.40 + float currentVolume = volumeLevelScalar * volumeIconCount;
1.41 + int segmentOnCount = Convert.ToInt32(currentVolume);
1.42 + //Check if our segment count was rounded up, this will later be used for half brightness segment
1.43 + bool roundedUp = segmentOnCount > currentVolume;
1.44
1.45 for (int i = 0; i < volumeIconCount; i++)
1.46 {
1.47 - if (i < currentVolume)
1.48 + if (i < segmentOnCount)
1.49 {
1.50 - if (i == currentVolume - 1 && roundedUp)
1.51 + //If we are dealing with our last segment and our segment count was rounded up then we will use half brightness.
1.52 + if (i == segmentOnCount - 1 && roundedUp)
1.53 {
1.54 //Half brightness
1.55 iDisplay.SetIconStatus(Display.TMiniDisplayIconType.EMiniDisplayIconVolume, i, (iDisplay.IconStatusCount(Display.TMiniDisplayIconType.EMiniDisplayIconVolume) - 1)/2);
1.56 @@ -320,22 +329,8 @@
1.57 }
1.58 }
1.59
1.60 - int muteIconCount = iDisplay.IconCount(Display.TMiniDisplayIconType.EMiniDisplayIconMute);
1.61 - if (muteIconCount > 0)
1.62 - {
1.63 - for (int i = 0; i < muteIconCount; i++)
1.64 - {
1.65 - if (iMultiMediaDevice.AudioEndpointVolume.Mute)
1.66 - {
1.67 - iDisplay.SetIconStatus(Display.TMiniDisplayIconType.EMiniDisplayIconMute, i, iDisplay.IconStatusCount(Display.TMiniDisplayIconType.EMiniDisplayIconMute)-1);
1.68 - }
1.69 - else
1.70 - {
1.71 - iDisplay.SetIconStatus(Display.TMiniDisplayIconType.EMiniDisplayIconMute, i, 0);
1.72 - }
1.73 - }
1.74 - }
1.75 -
1.76 + //Take care our our mute icon
1.77 + iDisplay.SetIconOnOff(Display.TMiniDisplayIconType.EMiniDisplayIconMute, iMultiMediaDevice.AudioEndpointVolume.Mute);
1.78 }
1.79
1.80 }
1.81 @@ -358,6 +353,9 @@
1.82 {
1.83 //Get our master volume
1.84 iMultiMediaDevice = iMultiMediaDeviceEnumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
1.85 + //Update our label
1.86 + labelDefaultAudioDevice.Text = iMultiMediaDevice.FriendlyName;
1.87 +
1.88 //Show our volume in our track bar
1.89 UpdateMasterVolumeThreadSafe();
1.90