-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d716140
commit 86d16fd
Showing
10 changed files
with
390 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,19 @@ | ||
【ソフト名】音量調整ソフト | ||
【著作権者】赤西真論 | ||
【公開日】2016/06/08 | ||
【種 別】ユーティリティ | ||
【連絡先】[email protected] | ||
【圧縮形式】zip | ||
【動作環境】Windows vista/7/8/10 | ||
【開発環境】Windows10 Pro | ||
C# + Visual Studio 2015 Community | ||
|
||
――――――――――――――――――――――――――――――――――――― | ||
≪著作権および免責事項≫ | ||
|
||
本ソフトはフリーソフトです。自由にご使用ください。なお,著作権は作者 | ||
である"赤西真論"が保有しています。 | ||
|
||
このソフトウェアを使用したことによって生じたすべての障害・損害・不具 | ||
合等に関しては、私と私の関係者および私の所属するいかなる団体・組織とも、 | ||
一切の責任を負いません。各自の責任においてご使用ください。 |
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,115 @@ | ||
#include "stdafx.h" | ||
|
||
#define GetBool(buf) strcmp(buf,"True") ? TRUE : FALSE | ||
|
||
using namespace::Microsoft::WRL; | ||
using namespace::Microsoft::WRL::Details; | ||
|
||
class ComInitializer { | ||
private: | ||
HRESULT m_hr; | ||
public: | ||
ComInitializer() { m_hr = CoInitialize(nullptr); } | ||
ComInitializer(LPVOID pvReserved) { m_hr = CoInitialize(pvReserved); } | ||
~ComInitializer() { CoUninitialize(); } | ||
operator HRESULT() const { return m_hr; } | ||
}; | ||
|
||
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) { | ||
ComInitializer initializer; | ||
if (FAILED(initializer)) | ||
return -1; | ||
|
||
// デバイス列挙オブジェクトを取得する | ||
ComPtr<IMMDeviceEnumerator> deviceEnumerator; | ||
HRESULT hr = CoCreateInstance( | ||
__uuidof(MMDeviceEnumerator), | ||
nullptr, | ||
CLSCTX_INPROC_SERVER, | ||
IID_PPV_ARGS(&deviceEnumerator)); | ||
if (FAILED(initializer)) | ||
RaiseException(hr); | ||
|
||
// 既定のマルチメディア出力デバイス(スピーカー)を取得する | ||
ComPtr<IMMDevice> device; | ||
hr = deviceEnumerator->GetDefaultAudioEndpoint( | ||
EDataFlow::eRender, | ||
ERole::eMultimedia, | ||
&device); | ||
if (FAILED(initializer)) | ||
RaiseException(hr); | ||
|
||
// オーディオエンドポイントのボリュームオブジェクトを作成する | ||
ComPtr<IAudioEndpointVolume> audioEndpointVolume; | ||
hr = device->Activate( | ||
__uuidof(IAudioEndpointVolume), | ||
CLSCTX_INPROC_SERVER, | ||
nullptr, | ||
&audioEndpointVolume); | ||
if (FAILED(hr)) | ||
RaiseException(hr); | ||
|
||
// ジャックまでの情報を取得する | ||
ComPtr<IDeviceTopology> pDeviceTopology; | ||
ComPtr<IConnector> pConnEP; | ||
IConnector* pConnDeviceTo; | ||
ComPtr<IPart> pPart; | ||
device->Activate(__uuidof(IDeviceTopology), CLSCTX_INPROC_SERVER, NULL, (void**)&pDeviceTopology); | ||
pDeviceTopology->GetConnector(0, &pConnEP); | ||
pConnEP->GetConnectedTo(&pConnDeviceTo); | ||
pConnDeviceTo->QueryInterface(__uuidof(IPart), (void**)&pPart); | ||
|
||
// 音量調整をする | ||
ComPtr<IKsJackDescription> pJackDesc = NULL; | ||
UINT nNumJacks = 0; | ||
UINT SpeakerCount = 1; | ||
float HeadphoneVol = 0.1; | ||
float SpeakerVol = 0.2; | ||
BOOL SpeakerMute = TRUE; | ||
UINT LoopDelay = 200; | ||
UINT oldNumJacks = 0; | ||
// 設定の読み込み | ||
char buf[64]; | ||
GetPrivateProfileString(TEXT("Default"), TEXT("SpeakerCount"), TEXT("1"), buf, 64, TEXT("./setting.ini")); | ||
SpeakerCount = atoi(buf); | ||
GetPrivateProfileString(TEXT("Default"), TEXT("SpeakerVol"), TEXT("0.2"), buf, 64, TEXT("./setting.ini")); | ||
SpeakerVol = atof(buf); | ||
GetPrivateProfileString(TEXT("Default"), TEXT("SpeakerMute"), TEXT("True"), buf, 64, TEXT("./setting.ini")); | ||
SpeakerMute = GetBool(buf); | ||
GetPrivateProfileString(TEXT("Default"), TEXT("HeadphoneVol"), TEXT("0.1"), buf, 64, TEXT("./setting.ini")); | ||
HeadphoneVol = atof(buf); | ||
GetPrivateProfileString(TEXT("Default"), TEXT("LoopDelay"), TEXT("200"), buf, 64, TEXT("./setting.ini")); | ||
LoopDelay = atoi(buf); | ||
// メインループ | ||
while (1) { | ||
pPart->Activate(CLSCTX_INPROC_SERVER, __uuidof(IKsJackDescription), &pJackDesc); | ||
pJackDesc->GetJackCount(&nNumJacks); | ||
if (nNumJacks != oldNumJacks) { | ||
// 起動時の処理 | ||
if (oldNumJacks == 0) { | ||
if (nNumJacks == SpeakerCount) { | ||
hr = audioEndpointVolume->GetMute(&SpeakerMute); | ||
hr = audioEndpointVolume->GetMasterVolumeLevelScalar(&SpeakerVol); //スピーカー音量の取得 | ||
} else { | ||
hr = audioEndpointVolume->GetMasterVolumeLevelScalar(&HeadphoneVol); //ヘッドホン音量の取得 | ||
} | ||
MessageBox(NULL, TEXT("起動しました\nデバイスの抜き差しが可能です"), TEXT("VolumeChanger"), MB_OK); | ||
} else { | ||
if (nNumJacks == SpeakerCount) { | ||
hr = audioEndpointVolume->GetMasterVolumeLevelScalar(&HeadphoneVol); //ヘッドホン音量の取得 | ||
hr = audioEndpointVolume->SetMute(SpeakerMute, nullptr); //ミュート状態を設定 | ||
hr = audioEndpointVolume->SetMasterVolumeLevelScalar(SpeakerVol, nullptr); | ||
} else { | ||
hr = audioEndpointVolume->GetMute(&SpeakerMute); //スピーカーでのミュート状態を取得 | ||
hr = audioEndpointVolume->GetMasterVolumeLevelScalar(&SpeakerVol); //スピーカー音量の取得 | ||
hr = audioEndpointVolume->SetMute(FALSE, nullptr); //ミュート解除 | ||
hr = audioEndpointVolume->SetMasterVolumeLevelScalar(HeadphoneVol, nullptr); | ||
} | ||
} | ||
oldNumJacks = nNumJacks; | ||
} | ||
Sleep(LoopDelay); | ||
} | ||
|
||
return 0; | ||
} |
Binary file not shown.
Binary file not shown.
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,28 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 14 | ||
VisualStudioVersion = 14.0.25420.1 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "VolumeChanger", "VolumeChanger.vcxproj", "{A1C56A19-9533-496D-8A58-B5CEA06AEB10}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|x64 = Debug|x64 | ||
Debug|x86 = Debug|x86 | ||
Release|x64 = Release|x64 | ||
Release|x86 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{A1C56A19-9533-496D-8A58-B5CEA06AEB10}.Debug|x64.ActiveCfg = Debug|x64 | ||
{A1C56A19-9533-496D-8A58-B5CEA06AEB10}.Debug|x64.Build.0 = Debug|x64 | ||
{A1C56A19-9533-496D-8A58-B5CEA06AEB10}.Debug|x86.ActiveCfg = Debug|Win32 | ||
{A1C56A19-9533-496D-8A58-B5CEA06AEB10}.Debug|x86.Build.0 = Debug|Win32 | ||
{A1C56A19-9533-496D-8A58-B5CEA06AEB10}.Release|x64.ActiveCfg = Release|x64 | ||
{A1C56A19-9533-496D-8A58-B5CEA06AEB10}.Release|x64.Build.0 = Release|x64 | ||
{A1C56A19-9533-496D-8A58-B5CEA06AEB10}.Release|x86.ActiveCfg = Release|Win32 | ||
{A1C56A19-9533-496D-8A58-B5CEA06AEB10}.Release|x86.Build.0 = Release|Win32 | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
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,157 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<ItemGroup Label="ProjectConfigurations"> | ||
<ProjectConfiguration Include="Debug|Win32"> | ||
<Configuration>Debug</Configuration> | ||
<Platform>Win32</Platform> | ||
</ProjectConfiguration> | ||
<ProjectConfiguration Include="Release|Win32"> | ||
<Configuration>Release</Configuration> | ||
<Platform>Win32</Platform> | ||
</ProjectConfiguration> | ||
<ProjectConfiguration Include="Debug|x64"> | ||
<Configuration>Debug</Configuration> | ||
<Platform>x64</Platform> | ||
</ProjectConfiguration> | ||
<ProjectConfiguration Include="Release|x64"> | ||
<Configuration>Release</Configuration> | ||
<Platform>x64</Platform> | ||
</ProjectConfiguration> | ||
</ItemGroup> | ||
<PropertyGroup Label="Globals"> | ||
<ProjectGuid>{A1C56A19-9533-496D-8A58-B5CEA06AEB10}</ProjectGuid> | ||
<Keyword>Win32Proj</Keyword> | ||
<RootNamespace>VolumeChanger</RootNamespace> | ||
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion> | ||
</PropertyGroup> | ||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> | ||
<ConfigurationType>Application</ConfigurationType> | ||
<UseDebugLibraries>true</UseDebugLibraries> | ||
<PlatformToolset>v140</PlatformToolset> | ||
<CharacterSet>MultiByte</CharacterSet> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> | ||
<ConfigurationType>Application</ConfigurationType> | ||
<UseDebugLibraries>false</UseDebugLibraries> | ||
<PlatformToolset>v140</PlatformToolset> | ||
<WholeProgramOptimization>true</WholeProgramOptimization> | ||
<CharacterSet>MultiByte</CharacterSet> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> | ||
<ConfigurationType>Application</ConfigurationType> | ||
<UseDebugLibraries>true</UseDebugLibraries> | ||
<PlatformToolset>v140</PlatformToolset> | ||
<CharacterSet>Unicode</CharacterSet> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> | ||
<ConfigurationType>Application</ConfigurationType> | ||
<UseDebugLibraries>false</UseDebugLibraries> | ||
<PlatformToolset>v140</PlatformToolset> | ||
<WholeProgramOptimization>true</WholeProgramOptimization> | ||
<CharacterSet>Unicode</CharacterSet> | ||
</PropertyGroup> | ||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> | ||
<ImportGroup Label="ExtensionSettings"> | ||
</ImportGroup> | ||
<ImportGroup Label="Shared"> | ||
</ImportGroup> | ||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
</ImportGroup> | ||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
</ImportGroup> | ||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | ||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
</ImportGroup> | ||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | ||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
</ImportGroup> | ||
<PropertyGroup Label="UserMacros" /> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||
<LinkIncremental>true</LinkIncremental> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | ||
<LinkIncremental>true</LinkIncremental> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||
<LinkIncremental>false</LinkIncremental> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | ||
<LinkIncremental>false</LinkIncremental> | ||
</PropertyGroup> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||
<ClCompile> | ||
<PrecompiledHeader>NotUsing</PrecompiledHeader> | ||
<WarningLevel>Level3</WarningLevel> | ||
<Optimization>Disabled</Optimization> | ||
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||
</ClCompile> | ||
<Link> | ||
<SubSystem>Windows</SubSystem> | ||
<GenerateDebugInformation>true</GenerateDebugInformation> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | ||
<ClCompile> | ||
<PrecompiledHeader>Use</PrecompiledHeader> | ||
<WarningLevel>Level3</WarningLevel> | ||
<Optimization>Disabled</Optimization> | ||
<PreprocessorDefinitions>_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||
</ClCompile> | ||
<Link> | ||
<SubSystem>Windows</SubSystem> | ||
<GenerateDebugInformation>true</GenerateDebugInformation> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||
<ClCompile> | ||
<WarningLevel>Level3</WarningLevel> | ||
<PrecompiledHeader>NotUsing</PrecompiledHeader> | ||
<Optimization>MaxSpeed</Optimization> | ||
<FunctionLevelLinking>true</FunctionLevelLinking> | ||
<IntrinsicFunctions>true</IntrinsicFunctions> | ||
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||
</ClCompile> | ||
<Link> | ||
<SubSystem>Windows</SubSystem> | ||
<EnableCOMDATFolding>true</EnableCOMDATFolding> | ||
<OptimizeReferences>true</OptimizeReferences> | ||
<GenerateDebugInformation>true</GenerateDebugInformation> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | ||
<ClCompile> | ||
<WarningLevel>Level3</WarningLevel> | ||
<PrecompiledHeader>Use</PrecompiledHeader> | ||
<Optimization>MaxSpeed</Optimization> | ||
<FunctionLevelLinking>true</FunctionLevelLinking> | ||
<IntrinsicFunctions>true</IntrinsicFunctions> | ||
<PreprocessorDefinitions>NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||
</ClCompile> | ||
<Link> | ||
<SubSystem>Windows</SubSystem> | ||
<EnableCOMDATFolding>true</EnableCOMDATFolding> | ||
<OptimizeReferences>true</OptimizeReferences> | ||
<GenerateDebugInformation>true</GenerateDebugInformation> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemGroup> | ||
<Text Include="ReadMe.txt" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ClInclude Include="stdafx.h" /> | ||
<ClInclude Include="targetver.h" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ClCompile Include="VolumeChanger.cpp" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Image Include="small.ico" /> | ||
<Image Include="VolumeChanger.ico" /> | ||
</ItemGroup> | ||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | ||
<ImportGroup Label="ExtensionTargets"> | ||
</ImportGroup> | ||
</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,41 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<ItemGroup> | ||
<Filter Include="ソース ファイル"> | ||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier> | ||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions> | ||
</Filter> | ||
<Filter Include="ヘッダー ファイル"> | ||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier> | ||
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions> | ||
</Filter> | ||
<Filter Include="リソース ファイル"> | ||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier> | ||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions> | ||
</Filter> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Text Include="ReadMe.txt" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ClInclude Include="stdafx.h"> | ||
<Filter>ヘッダー ファイル</Filter> | ||
</ClInclude> | ||
<ClInclude Include="targetver.h"> | ||
<Filter>ヘッダー ファイル</Filter> | ||
</ClInclude> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ClCompile Include="VolumeChanger.cpp"> | ||
<Filter>ソース ファイル</Filter> | ||
</ClCompile> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Image Include="small.ico"> | ||
<Filter>リソース ファイル</Filter> | ||
</Image> | ||
<Image Include="VolumeChanger.ico"> | ||
<Filter>リソース ファイル</Filter> | ||
</Image> | ||
</ItemGroup> | ||
</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 @@ | ||
// stdafx.h : 標準のシステム インクルード ファイルのインクルード ファイル、または | ||
// 参照回数が多く、かつあまり変更されない、プロジェクト専用のインクルード ファイル | ||
// を記述します。 | ||
// | ||
|
||
#pragma once | ||
|
||
#include "targetver.h" | ||
|
||
// Windows ヘッダー ファイル: | ||
#include <windows.h> | ||
|
||
// C ランタイム ヘッダー ファイル | ||
#include <stdlib.h> | ||
#include <malloc.h> | ||
#include <memory.h> | ||
#include <tchar.h> | ||
|
||
// TODO: プログラムに必要な追加ヘッダーをここで参照してください | ||
#include <wrl.h> | ||
#include <mmdeviceapi.h> | ||
#include <endpointvolume.h> |
Oops, something went wrong.