Audio tab now displaying default audio device name.
authorStephaneLenclud
Mon, 09 Feb 2015 11:09:33 +0100
changeset 1165fc39c560179
parent 115 5c61a13c4241
child 117 9e48cc704a69
Audio tab now displaying default audio device name.
Consolidating audio management, adding comments.
Server/Display.cs
Server/MainForm.Designer.cs
Server/MainForm.cs
Server/SharpDisplayManager.csproj
     1.1 --- a/Server/Display.cs	Sun Feb 08 20:26:36 2015 +0100
     1.2 +++ b/Server/Display.cs	Mon Feb 09 11:09:33 2015 +0100
     1.3 @@ -232,7 +232,7 @@
     1.4  		}
     1.5  
     1.6  		/// <summary>
     1.7 -		/// 
     1.8 +		/// Set all elements of an icon to the given status.
     1.9  		/// </summary>
    1.10  		/// <param name="aIcon"></param>
    1.11  		/// <param name="aStatus"></param>
    1.12 @@ -246,7 +246,24 @@
    1.13  		}
    1.14  
    1.15  		/// <summary>
    1.16 -		/// 
    1.17 +		/// Set all elements of an icon to be either on or off.
    1.18 +		/// </summary>
    1.19 +		/// <param name="aIcon"></param>
    1.20 +		/// <param name="aOn"></param>		
    1.21 +		public void SetIconOnOff(TMiniDisplayIconType aIcon, bool aOn)
    1.22 +		{
    1.23 +			if (aOn)
    1.24 +			{
    1.25 +				SetIconOn(aIcon);
    1.26 +			}
    1.27 +			else
    1.28 +			{
    1.29 +				SetIconOff(aIcon);
    1.30 +			}
    1.31 +		}
    1.32 +
    1.33 +		/// <summary>
    1.34 +		/// Set all elements of an icon to there maximum status.
    1.35  		/// </summary>
    1.36  		/// <param name="aIcon"></param>
    1.37  		public void SetIconOn(TMiniDisplayIconType aIcon)
    1.38 @@ -259,7 +276,7 @@
    1.39  		}
    1.40  
    1.41  		/// <summary>
    1.42 -		/// 
    1.43 +		/// Turn off all elements of an icon.
    1.44  		/// </summary>
    1.45  		/// <param name="aIcon"></param>
    1.46  		public void SetIconOff(TMiniDisplayIconType aIcon)
     2.1 --- a/Server/MainForm.Designer.cs	Sun Feb 08 20:26:36 2015 +0100
     2.2 +++ b/Server/MainForm.Designer.cs	Mon Feb 09 11:09:33 2015 +0100
     2.3 @@ -91,13 +91,14 @@
     2.4  			this.checkBoxAutoStart = new System.Windows.Forms.CheckBox();
     2.5  			this.buttonUpdate = new System.Windows.Forms.Button();
     2.6  			this.tabPageAudio = new System.Windows.Forms.TabPage();
     2.7 +			this.labelDefaultAudioDevice = new System.Windows.Forms.Label();
     2.8 +			this.checkBoxShowVolumeLabel = new System.Windows.Forms.CheckBox();
     2.9  			this.checkBoxMute = new System.Windows.Forms.CheckBox();
    2.10  			this.trackBarMasterVolume = new System.Windows.Forms.TrackBar();
    2.11  			this.labelFontWidth = new System.Windows.Forms.Label();
    2.12  			this.labelFontHeight = new System.Windows.Forms.Label();
    2.13  			this.pictureBoxDemo = new System.Windows.Forms.PictureBox();
    2.14  			this.toolTip = new System.Windows.Forms.ToolTip(this.components);
    2.15 -			this.checkBoxShowVolumeLabel = new System.Windows.Forms.CheckBox();
    2.16  			this.panelDisplay.SuspendLayout();
    2.17  			this.tableLayoutPanel.SuspendLayout();
    2.18  			this.statusStrip.SuspendLayout();
    2.19 @@ -692,6 +693,7 @@
    2.20  			// 
    2.21  			// tabPageAudio
    2.22  			// 
    2.23 +			this.tabPageAudio.Controls.Add(this.labelDefaultAudioDevice);
    2.24  			this.tabPageAudio.Controls.Add(this.checkBoxShowVolumeLabel);
    2.25  			this.tabPageAudio.Controls.Add(this.checkBoxMute);
    2.26  			this.tabPageAudio.Controls.Add(this.trackBarMasterVolume);
    2.27 @@ -703,6 +705,28 @@
    2.28  			this.tabPageAudio.Text = "Audio";
    2.29  			this.tabPageAudio.UseVisualStyleBackColor = true;
    2.30  			// 
    2.31 +			// labelDefaultAudioDevice
    2.32 +			// 
    2.33 +			this.labelDefaultAudioDevice.AutoSize = true;
    2.34 +			this.labelDefaultAudioDevice.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
    2.35 +			this.labelDefaultAudioDevice.Location = new System.Drawing.Point(3, 6);
    2.36 +			this.labelDefaultAudioDevice.Name = "labelDefaultAudioDevice";
    2.37 +			this.labelDefaultAudioDevice.Size = new System.Drawing.Size(120, 13);
    2.38 +			this.labelDefaultAudioDevice.TabIndex = 19;
    2.39 +			this.labelDefaultAudioDevice.Text = "Audio Device Unknown";
    2.40 +			// 
    2.41 +			// checkBoxShowVolumeLabel
    2.42 +			// 
    2.43 +			this.checkBoxShowVolumeLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
    2.44 +			this.checkBoxShowVolumeLabel.AutoSize = true;
    2.45 +			this.checkBoxShowVolumeLabel.Location = new System.Drawing.Point(3, 196);
    2.46 +			this.checkBoxShowVolumeLabel.Name = "checkBoxShowVolumeLabel";
    2.47 +			this.checkBoxShowVolumeLabel.Size = new System.Drawing.Size(115, 17);
    2.48 +			this.checkBoxShowVolumeLabel.TabIndex = 18;
    2.49 +			this.checkBoxShowVolumeLabel.Text = "Show volume label";
    2.50 +			this.checkBoxShowVolumeLabel.UseVisualStyleBackColor = true;
    2.51 +			this.checkBoxShowVolumeLabel.CheckedChanged += new System.EventHandler(this.checkBoxShowVolumeLabel_CheckedChanged);
    2.52 +			// 
    2.53  			// checkBoxMute
    2.54  			// 
    2.55  			this.checkBoxMute.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
    2.56 @@ -755,18 +779,6 @@
    2.57  			this.pictureBoxDemo.TabIndex = 21;
    2.58  			this.pictureBoxDemo.TabStop = false;
    2.59  			// 
    2.60 -			// checkBoxShowVolumeLabel
    2.61 -			// 
    2.62 -			this.checkBoxShowVolumeLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
    2.63 -			this.checkBoxShowVolumeLabel.AutoSize = true;
    2.64 -			this.checkBoxShowVolumeLabel.Location = new System.Drawing.Point(3, 196);
    2.65 -			this.checkBoxShowVolumeLabel.Name = "checkBoxShowVolumeLabel";
    2.66 -			this.checkBoxShowVolumeLabel.Size = new System.Drawing.Size(115, 17);
    2.67 -			this.checkBoxShowVolumeLabel.TabIndex = 18;
    2.68 -			this.checkBoxShowVolumeLabel.Text = "Show volume label";
    2.69 -			this.checkBoxShowVolumeLabel.UseVisualStyleBackColor = true;
    2.70 -			this.checkBoxShowVolumeLabel.CheckedChanged += new System.EventHandler(this.checkBoxShowVolumeLabel_CheckedChanged);
    2.71 -			// 
    2.72  			// MainForm
    2.73  			// 
    2.74  			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    2.75 @@ -871,6 +883,7 @@
    2.76  		private System.Windows.Forms.TrackBar trackBarMasterVolume;
    2.77  		private System.Windows.Forms.CheckBox checkBoxMute;
    2.78  		private System.Windows.Forms.CheckBox checkBoxShowVolumeLabel;
    2.79 +		private System.Windows.Forms.Label labelDefaultAudioDevice;
    2.80      }
    2.81  }
    2.82  
     3.1 --- a/Server/MainForm.cs	Sun Feb 08 20:26:36 2015 +0100
     3.2 +++ b/Server/MainForm.cs	Mon Feb 09 11:09:33 2015 +0100
     3.3 @@ -219,6 +219,9 @@
     3.4          /// <param name="e"></param>
     3.5          private void trackBarMasterVolume_Scroll(object sender, EventArgs e)
     3.6          {
     3.7 +			//Just like Windows Volume Mixer we unmute if the volume is adjusted
     3.8 +			iMultiMediaDevice.AudioEndpointVolume.Mute = false;
     3.9 +			//Set volume level according to our volume slider new position
    3.10  			iMultiMediaDevice.AudioEndpointVolume.MasterVolumeLevelScalar = trackBarMasterVolume.Value / 100.0f;
    3.11          }
    3.12  
    3.13 @@ -270,7 +273,8 @@
    3.14          
    3.15  
    3.16  		/// <summary>
    3.17 -		/// 
    3.18 +		/// Update master volume indicators based our current system states.
    3.19 +		/// This typically includes volume levels and mute status.
    3.20  		/// </summary>
    3.21  		private void UpdateMasterVolumeThreadSafe()
    3.22  		{
    3.23 @@ -288,21 +292,26 @@
    3.24  			//Update mute checkbox
    3.25  			checkBoxMute.Checked = iMultiMediaDevice.AudioEndpointVolume.Mute;
    3.26  
    3.27 -			//TODO: Check our display device too
    3.28 +			//If our display connection is open we need to update its icons
    3.29  			if (iDisplay.IsOpen())
    3.30  			{
    3.31 +				//First take care our our volume level icons
    3.32  				int volumeIconCount = iDisplay.IconCount(Display.TMiniDisplayIconType.EMiniDisplayIconVolume);
    3.33  				if (volumeIconCount > 0)
    3.34  				{					
    3.35 -					int currentVolume = Convert.ToInt32(volumeLevelScalar * volumeIconCount);
    3.36 -
    3.37 -					bool roundedUp = currentVolume > (volumeLevelScalar * volumeIconCount);
    3.38 +					//Compute current volume level from system level and the number of segments in our display volume bar.
    3.39 +					//That tells us how many segments in our volume bar needs to be turned on.
    3.40 +					float currentVolume = volumeLevelScalar * volumeIconCount;
    3.41 +					int segmentOnCount = Convert.ToInt32(currentVolume);
    3.42 +					//Check if our segment count was rounded up, this will later be used for half brightness segment
    3.43 +					bool roundedUp = segmentOnCount > currentVolume;
    3.44  
    3.45  					for (int i = 0; i < volumeIconCount; i++)
    3.46  					{
    3.47 -						if (i < currentVolume)
    3.48 +						if (i < segmentOnCount)
    3.49  						{
    3.50 -							if (i == currentVolume - 1 && roundedUp)
    3.51 +							//If we are dealing with our last segment and our segment count was rounded up then we will use half brightness.
    3.52 +							if (i == segmentOnCount - 1 && roundedUp)
    3.53  							{
    3.54  								//Half brightness
    3.55  								iDisplay.SetIconStatus(Display.TMiniDisplayIconType.EMiniDisplayIconVolume, i, (iDisplay.IconStatusCount(Display.TMiniDisplayIconType.EMiniDisplayIconVolume) - 1)/2);
    3.56 @@ -320,22 +329,8 @@
    3.57  					}
    3.58  				}
    3.59  
    3.60 -				int muteIconCount = iDisplay.IconCount(Display.TMiniDisplayIconType.EMiniDisplayIconMute);
    3.61 -				if (muteIconCount > 0)
    3.62 -				{
    3.63 -					for (int i = 0; i < muteIconCount; i++)
    3.64 -					{
    3.65 -						if (iMultiMediaDevice.AudioEndpointVolume.Mute)
    3.66 -						{
    3.67 -							iDisplay.SetIconStatus(Display.TMiniDisplayIconType.EMiniDisplayIconMute, i, iDisplay.IconStatusCount(Display.TMiniDisplayIconType.EMiniDisplayIconMute)-1);
    3.68 -						}
    3.69 -						else
    3.70 -						{
    3.71 -							iDisplay.SetIconStatus(Display.TMiniDisplayIconType.EMiniDisplayIconMute, i, 0);
    3.72 -						}
    3.73 -					}
    3.74 -				}
    3.75 -
    3.76 +				//Take care our our mute icon
    3.77 +				iDisplay.SetIconOnOff(Display.TMiniDisplayIconType.EMiniDisplayIconMute, iMultiMediaDevice.AudioEndpointVolume.Mute);
    3.78  			}
    3.79  
    3.80  		}
    3.81 @@ -358,6 +353,9 @@
    3.82              {                
    3.83                  //Get our master volume            
    3.84  				iMultiMediaDevice = iMultiMediaDeviceEnumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
    3.85 +				//Update our label
    3.86 +				labelDefaultAudioDevice.Text = iMultiMediaDevice.FriendlyName;
    3.87 +
    3.88                  //Show our volume in our track bar
    3.89  				UpdateMasterVolumeThreadSafe();
    3.90  
     4.1 --- a/Server/SharpDisplayManager.csproj	Sun Feb 08 20:26:36 2015 +0100
     4.2 +++ b/Server/SharpDisplayManager.csproj	Mon Feb 09 11:09:33 2015 +0100
     4.3 @@ -32,7 +32,7 @@
     4.4      <WebPage>index.htm</WebPage>
     4.5      <OpenBrowserOnPublish>false</OpenBrowserOnPublish>
     4.6      <ApplicationRevision>1</ApplicationRevision>
     4.7 -    <ApplicationVersion>0.1.3.%2a</ApplicationVersion>
     4.8 +    <ApplicationVersion>0.1.4.%2a</ApplicationVersion>
     4.9      <UseApplicationTrust>false</UseApplicationTrust>
    4.10      <CreateDesktopShortcut>true</CreateDesktopShortcut>
    4.11      <PublishWizardCompleted>true</PublishWizardCompleted>