Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial Commit. Kind of sloppy first-pass at the intended functionality.
Arguably rushed for purpose of posting to forum before I forgot why I was creating it, heh.
- Loading branch information
0 parents
commit 1847e96
Showing
5 changed files
with
272 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.3" /> | ||
</startup> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Runtime.InteropServices; | ||
using System.Runtime.Remoting.Channels; | ||
using System.Security.AccessControl; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Vannatech.CoreAudio.Enumerations; | ||
using Vannatech.CoreAudio.Interfaces; | ||
|
||
namespace VolumeSlapper | ||
{ | ||
//quick console program slapped together to retrieve/set volume on Windows Vista and later. | ||
//I guess I should have checked the OS of the issue, oh well. | ||
class Program | ||
{ | ||
private static String HelpText = @" | ||
VolumeSlapper Command-Line Volume Utility. v" + Assembly.GetEntryAssembly().GetName().Version.ToString() + @". | ||
Syntax: | ||
VolumeSlapper (operation) [volumelevel] | ||
operation: either get or set. get doesn't require an argument; set requires the volumelevel argument. | ||
volumelevel: a value parsable as a floating point value between 0 and 1 to use as the volume level. used only for the set operation. | ||
examples: | ||
Retrieve current audio level: | ||
{0} get | ||
set current audio level to 50%: | ||
{0} set 0.5 | ||
"; | ||
static void Main(string[] args) | ||
{ | ||
|
||
//we won't bother with fancy argument parsing here, just look at the buggers directly. | ||
if(args.Length==0) | ||
{ | ||
ShowHelp(); | ||
return; | ||
} | ||
else if(args.Length>0) | ||
{ | ||
if(String.Compare(args[0],"get",StringComparison.OrdinalIgnoreCase)==0) | ||
{ | ||
//get logic | ||
float currvolume = VolumeUtilities.GetMasterVolume(); | ||
Console.WriteLine(currvolume); | ||
} | ||
else if(String.Compare(args[0],"set",StringComparison.OrdinalIgnoreCase)==0) | ||
{ | ||
//set logic. | ||
float assignvolume; | ||
if(!float.TryParse(args[1],out assignvolume)) | ||
{ | ||
Console.WriteLine("Specified volume level not valid:" + args[1]); | ||
Console.WriteLine(); | ||
ShowHelp(); | ||
return; | ||
} | ||
else | ||
{ | ||
VolumeUtilities.SetMasterVolume(assignvolume); | ||
Console.WriteLine("Volume Level set to " + assignvolume); | ||
} | ||
} | ||
else | ||
{ | ||
Console.WriteLine("unrecognized parameter:" + args[0]); | ||
Console.WriteLine(); | ||
ShowHelp(); | ||
return; | ||
} | ||
|
||
|
||
} | ||
|
||
|
||
Console.ReadKey(); | ||
} | ||
static void ShowHelp() | ||
{ | ||
String sHelpText = String.Format(HelpText, Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location)); | ||
Console.Write(sHelpText); | ||
} | ||
} | ||
|
||
|
||
public static class VolumeUtilities | ||
{ | ||
public static float GetMasterVolume() | ||
{ | ||
// retrieve audio device... | ||
IMMDeviceEnumerator useenumerator = (IMMDeviceEnumerator)(new MMDeviceEnumerator()); | ||
IMMDevice speakers; | ||
const int eRender = 0; | ||
const int eMultimedia = 1; | ||
//retrieve the actual endpoint | ||
useenumerator.GetDefaultAudioEndpoint(eRender, ERole.eMultimedia, out speakers); | ||
|
||
object o; | ||
//retrieve the actual interface instance to retrieve the volume information from. | ||
speakers.Activate(typeof(IAudioEndpointVolume).GUID, 0, IntPtr.Zero, out o); | ||
IAudioEndpointVolume aepv = (IAudioEndpointVolume)o; | ||
float result; | ||
aepv.GetMasterVolumeLevelScalar(out result); | ||
Marshal.ReleaseComObject(aepv); | ||
Marshal.ReleaseComObject(speakers); | ||
Marshal.ReleaseComObject(useenumerator); | ||
return result; | ||
} | ||
public static float SetMasterVolume(float newValue) | ||
{ | ||
// retrieve audio device... | ||
|
||
IMMDeviceEnumerator useenumerator = (IMMDeviceEnumerator)(new MMDeviceEnumerator()); | ||
IMMDevice speakers; | ||
const int eRender = 0; | ||
const int eMultimedia = 1; | ||
//retrieve the actual endpoint | ||
useenumerator.GetDefaultAudioEndpoint(eRender, ERole.eMultimedia, out speakers); | ||
|
||
object o; | ||
//retrieve the actual interface instance to retrieve the volume information from. | ||
speakers.Activate(typeof(IAudioEndpointVolume).GUID, 0, IntPtr.Zero, out o); | ||
IAudioEndpointVolume aepv = (IAudioEndpointVolume)o; | ||
float result; | ||
int hresult = aepv.GetMasterVolumeLevelScalar(out result); | ||
aepv.SetMasterVolumeLevelScalar(newValue,new System.Guid()); | ||
Marshal.ReleaseComObject(aepv); | ||
Marshal.ReleaseComObject(speakers); | ||
Marshal.ReleaseComObject(useenumerator); | ||
return result; | ||
} | ||
[ComImport] | ||
[Guid("BCDE0395-E52F-467C-8E3D-C4579291692E")] | ||
private class MMDeviceEnumerator | ||
{ | ||
} | ||
|
||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyTitle("VolumeSlapper")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("VolumeSlapper")] | ||
[assembly: AssemblyCopyright("Copyright © 2015")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
[assembly: Guid("527092e8-5000-406d-8bff-662e371b3d1c")] | ||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// You can specify all the values or you can default the Build and Revision Numbers | ||
// by using the '*' as shown below: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{09C31B32-7D6A-420A-830A-72BA62D244F4}</ProjectGuid> | ||
<OutputType>Exe</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>VolumeSlapper</RootNamespace> | ||
<AssemblyName>VolumeSlapper</AssemblyName> | ||
<TargetFrameworkVersion>v4.5.3</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Xml" /> | ||
<Reference Include="Vannatech.CoreAudio"> | ||
<HintPath>..\..\..\..\Downloads\Vannatech.CoreAudio.dll</HintPath> | ||
</Reference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Program.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="App.config" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 2013 | ||
VisualStudioVersion = 12.0.31101.0 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VolumeSlapper", "VolumeSlapper.csproj", "{09C31B32-7D6A-420A-830A-72BA62D244F4}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{09C31B32-7D6A-420A-830A-72BA62D244F4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{09C31B32-7D6A-420A-830A-72BA62D244F4}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{09C31B32-7D6A-420A-830A-72BA62D244F4}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{09C31B32-7D6A-420A-830A-72BA62D244F4}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |