# HG changeset patch # User StephaneLenclud # Date 1423476573 -3600 # Node ID 5fc39c560179de6b26fdaa88c4356bf90a12d898 # Parent 5c61a13c42413927f4fb21bd05a8e110f614e012 Audio tab now displaying default audio device name. Consolidating audio management, adding comments. diff -r 5c61a13c4241 -r 5fc39c560179 Server/Display.cs --- a/Server/Display.cs Sun Feb 08 20:26:36 2015 +0100 +++ b/Server/Display.cs Mon Feb 09 11:09:33 2015 +0100 @@ -232,7 +232,7 @@ } /// - /// + /// Set all elements of an icon to the given status. /// /// /// @@ -246,7 +246,24 @@ } /// - /// + /// Set all elements of an icon to be either on or off. + /// + /// + /// + public void SetIconOnOff(TMiniDisplayIconType aIcon, bool aOn) + { + if (aOn) + { + SetIconOn(aIcon); + } + else + { + SetIconOff(aIcon); + } + } + + /// + /// Set all elements of an icon to there maximum status. /// /// public void SetIconOn(TMiniDisplayIconType aIcon) @@ -259,7 +276,7 @@ } /// - /// + /// Turn off all elements of an icon. /// /// public void SetIconOff(TMiniDisplayIconType aIcon) diff -r 5c61a13c4241 -r 5fc39c560179 Server/MainForm.Designer.cs --- a/Server/MainForm.Designer.cs Sun Feb 08 20:26:36 2015 +0100 +++ b/Server/MainForm.Designer.cs Mon Feb 09 11:09:33 2015 +0100 @@ -91,13 +91,14 @@ this.checkBoxAutoStart = new System.Windows.Forms.CheckBox(); this.buttonUpdate = new System.Windows.Forms.Button(); this.tabPageAudio = new System.Windows.Forms.TabPage(); + this.labelDefaultAudioDevice = new System.Windows.Forms.Label(); + this.checkBoxShowVolumeLabel = new System.Windows.Forms.CheckBox(); this.checkBoxMute = new System.Windows.Forms.CheckBox(); this.trackBarMasterVolume = new System.Windows.Forms.TrackBar(); this.labelFontWidth = new System.Windows.Forms.Label(); this.labelFontHeight = new System.Windows.Forms.Label(); this.pictureBoxDemo = new System.Windows.Forms.PictureBox(); this.toolTip = new System.Windows.Forms.ToolTip(this.components); - this.checkBoxShowVolumeLabel = new System.Windows.Forms.CheckBox(); this.panelDisplay.SuspendLayout(); this.tableLayoutPanel.SuspendLayout(); this.statusStrip.SuspendLayout(); @@ -692,6 +693,7 @@ // // tabPageAudio // + this.tabPageAudio.Controls.Add(this.labelDefaultAudioDevice); this.tabPageAudio.Controls.Add(this.checkBoxShowVolumeLabel); this.tabPageAudio.Controls.Add(this.checkBoxMute); this.tabPageAudio.Controls.Add(this.trackBarMasterVolume); @@ -703,6 +705,28 @@ this.tabPageAudio.Text = "Audio"; this.tabPageAudio.UseVisualStyleBackColor = true; // + // labelDefaultAudioDevice + // + this.labelDefaultAudioDevice.AutoSize = true; + this.labelDefaultAudioDevice.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.labelDefaultAudioDevice.Location = new System.Drawing.Point(3, 6); + this.labelDefaultAudioDevice.Name = "labelDefaultAudioDevice"; + this.labelDefaultAudioDevice.Size = new System.Drawing.Size(120, 13); + this.labelDefaultAudioDevice.TabIndex = 19; + this.labelDefaultAudioDevice.Text = "Audio Device Unknown"; + // + // checkBoxShowVolumeLabel + // + this.checkBoxShowVolumeLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.checkBoxShowVolumeLabel.AutoSize = true; + this.checkBoxShowVolumeLabel.Location = new System.Drawing.Point(3, 196); + this.checkBoxShowVolumeLabel.Name = "checkBoxShowVolumeLabel"; + this.checkBoxShowVolumeLabel.Size = new System.Drawing.Size(115, 17); + this.checkBoxShowVolumeLabel.TabIndex = 18; + this.checkBoxShowVolumeLabel.Text = "Show volume label"; + this.checkBoxShowVolumeLabel.UseVisualStyleBackColor = true; + this.checkBoxShowVolumeLabel.CheckedChanged += new System.EventHandler(this.checkBoxShowVolumeLabel_CheckedChanged); + // // checkBoxMute // this.checkBoxMute.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); @@ -755,18 +779,6 @@ this.pictureBoxDemo.TabIndex = 21; this.pictureBoxDemo.TabStop = false; // - // checkBoxShowVolumeLabel - // - this.checkBoxShowVolumeLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.checkBoxShowVolumeLabel.AutoSize = true; - this.checkBoxShowVolumeLabel.Location = new System.Drawing.Point(3, 196); - this.checkBoxShowVolumeLabel.Name = "checkBoxShowVolumeLabel"; - this.checkBoxShowVolumeLabel.Size = new System.Drawing.Size(115, 17); - this.checkBoxShowVolumeLabel.TabIndex = 18; - this.checkBoxShowVolumeLabel.Text = "Show volume label"; - this.checkBoxShowVolumeLabel.UseVisualStyleBackColor = true; - this.checkBoxShowVolumeLabel.CheckedChanged += new System.EventHandler(this.checkBoxShowVolumeLabel_CheckedChanged); - // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -871,6 +883,7 @@ private System.Windows.Forms.TrackBar trackBarMasterVolume; private System.Windows.Forms.CheckBox checkBoxMute; private System.Windows.Forms.CheckBox checkBoxShowVolumeLabel; + private System.Windows.Forms.Label labelDefaultAudioDevice; } } diff -r 5c61a13c4241 -r 5fc39c560179 Server/MainForm.cs --- a/Server/MainForm.cs Sun Feb 08 20:26:36 2015 +0100 +++ b/Server/MainForm.cs Mon Feb 09 11:09:33 2015 +0100 @@ -219,6 +219,9 @@ /// private void trackBarMasterVolume_Scroll(object sender, EventArgs e) { + //Just like Windows Volume Mixer we unmute if the volume is adjusted + iMultiMediaDevice.AudioEndpointVolume.Mute = false; + //Set volume level according to our volume slider new position iMultiMediaDevice.AudioEndpointVolume.MasterVolumeLevelScalar = trackBarMasterVolume.Value / 100.0f; } @@ -270,7 +273,8 @@ /// - /// + /// Update master volume indicators based our current system states. + /// This typically includes volume levels and mute status. /// private void UpdateMasterVolumeThreadSafe() { @@ -288,21 +292,26 @@ //Update mute checkbox checkBoxMute.Checked = iMultiMediaDevice.AudioEndpointVolume.Mute; - //TODO: Check our display device too + //If our display connection is open we need to update its icons if (iDisplay.IsOpen()) { + //First take care our our volume level icons int volumeIconCount = iDisplay.IconCount(Display.TMiniDisplayIconType.EMiniDisplayIconVolume); if (volumeIconCount > 0) { - int currentVolume = Convert.ToInt32(volumeLevelScalar * volumeIconCount); - - bool roundedUp = currentVolume > (volumeLevelScalar * volumeIconCount); + //Compute current volume level from system level and the number of segments in our display volume bar. + //That tells us how many segments in our volume bar needs to be turned on. + float currentVolume = volumeLevelScalar * volumeIconCount; + int segmentOnCount = Convert.ToInt32(currentVolume); + //Check if our segment count was rounded up, this will later be used for half brightness segment + bool roundedUp = segmentOnCount > currentVolume; for (int i = 0; i < volumeIconCount; i++) { - if (i < currentVolume) + if (i < segmentOnCount) { - if (i == currentVolume - 1 && roundedUp) + //If we are dealing with our last segment and our segment count was rounded up then we will use half brightness. + if (i == segmentOnCount - 1 && roundedUp) { //Half brightness iDisplay.SetIconStatus(Display.TMiniDisplayIconType.EMiniDisplayIconVolume, i, (iDisplay.IconStatusCount(Display.TMiniDisplayIconType.EMiniDisplayIconVolume) - 1)/2); @@ -320,22 +329,8 @@ } } - int muteIconCount = iDisplay.IconCount(Display.TMiniDisplayIconType.EMiniDisplayIconMute); - if (muteIconCount > 0) - { - for (int i = 0; i < muteIconCount; i++) - { - if (iMultiMediaDevice.AudioEndpointVolume.Mute) - { - iDisplay.SetIconStatus(Display.TMiniDisplayIconType.EMiniDisplayIconMute, i, iDisplay.IconStatusCount(Display.TMiniDisplayIconType.EMiniDisplayIconMute)-1); - } - else - { - iDisplay.SetIconStatus(Display.TMiniDisplayIconType.EMiniDisplayIconMute, i, 0); - } - } - } - + //Take care our our mute icon + iDisplay.SetIconOnOff(Display.TMiniDisplayIconType.EMiniDisplayIconMute, iMultiMediaDevice.AudioEndpointVolume.Mute); } } @@ -358,6 +353,9 @@ { //Get our master volume iMultiMediaDevice = iMultiMediaDeviceEnumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia); + //Update our label + labelDefaultAudioDevice.Text = iMultiMediaDevice.FriendlyName; + //Show our volume in our track bar UpdateMasterVolumeThreadSafe(); diff -r 5c61a13c4241 -r 5fc39c560179 Server/SharpDisplayManager.csproj --- a/Server/SharpDisplayManager.csproj Sun Feb 08 20:26:36 2015 +0100 +++ b/Server/SharpDisplayManager.csproj Mon Feb 09 11:09:33 2015 +0100 @@ -32,7 +32,7 @@ index.htm false 1 - 0.1.3.%2a + 0.1.4.%2a false true true