|
|
2018/3/12(Mon) 18:28:06|NO.82731
HSPでアプリケーション単体の音量を変更する方法はありませんか?
|
|
2018/3/12(Mon) 19:37:17|NO.82732
mmvol や dmmvol を使うとか?
|
|
2018/3/12(Mon) 20:58:20|NO.82734
説明不足ですみません
私がやりたいのはwindowsの音量ミキサーをソフトから動かすことです
|
|
2018/3/12(Mon) 21:13:33|NO.82735
かなり複雑なので詳しくは説明できませんが
下記の過去ログのソースを使えば出来るかもしれません。
http://hsp.tv/play/pforum.php?mode=all&num=82061
音量を半分にする場合はこのようにすればいいのですが、
ISimpleAudioVolume_SetMasterVolume sav, tofloat(0.5), 0
問題はsavで指定するアプリケーションを特定するところが私にはよくわからないんですよね。
ついでに言うと、音量の設定は0.0〜1.0のfloat値で行なうみたいなんですが
システム全体のマスター音量が50の場合、
アプリケーションの音量を1.0にしても50にしかならなかったりします。
|
|
2018/3/12(Mon) 22:41:46|NO.82736
有益な情報をありがとうございます
savにはたとえばどんな文字列が入るのですか?
|
|
2018/3/12(Mon) 23:15:36|NO.82738
繰り返しますが、私もよくわかっていないという事を理解した上で読んで下さい。
上記のsavはCOMポインタであって直接なんらかの名前等が入るわけではありません。
一部ソースを抜粋しますが、
newcom sEnum, IAudioSessionEnumerator, -1, p
〜省略〜
IAudioSessionEnumerator_GetSession sEnum, cnt, p
newcom sc, IAudioSessionControl2, -1, p
〜省略〜
querycom sav, sc, ISimpleAudioVolume
pは一時的な変数だと思ってください。
・IAudioSessionEnumeratorインターフェイスのCOMオブジェクト変数sEnumを作成
・IAudioSessionEnumeratorインターフェイスの
GetSessionメソッドで番号順にセッションを取得
・IAudioSessionControl2インターフェイスのCOMオブジェクト変数scを作成
・IAudioSessionControl2インターフェイスに対してISimpleAudioVolumeインターフェイスを
問い合わせたCOMオブジェクト変数savを作成
という訳の分からない流れでsavの値を特定しているようです。
Core Audio APIs のHSPソース付き日本語解説が本気で欲しいですね。
|
|
2018/3/13(Tue) 14:29:54|NO.82741
だめだ、まったくわからない(笑)
いろいろと調べてみます...
ありがとうございます
|
|
2018/3/14(Wed) 21:41:30|NO.82748
不具合もありますが、私のわかる範囲でモジュール化してみました。
何度も実行、終了を繰り返していると何故かdelcomの辺りでエラーになることがあります。
各命令の仕様はモジュールの下に書いておきました。
更にその下には簡単なサンプルもあります。
Core Audio APIsでのアプリ名やアイコン取得などは
アプリ自体がCore Audio APIsを使って設定していないと
取得できないらしいという微妙な罠があったので、
不完全ですがプロセスIDからウィンドウ名やアイコンの取得という形にしました。
///////////////////////////////////////////////////////////////////////////////////////////////
/////
///// 音量ミキサーモジュール 2018 / 03 / 14
/////
/////
///// <<参考ページ>>
/////
///// スピーカーの音量 http://hsp.tv/play/pforum.php?mode=pastwch&num=34666
///// 各アプリケーション音量 http://hsp.tv/play/pforum.php?mode=all&num=82061
///// EnumWindows http://hsp.tv/play/pforum.php?mode=all&num=82152
/////
/////
/////
#module VolumeMixer
#define NoTitle "タイトル不明"
#uselib "user32.dll"
#func EnumWindows "EnumWindows" sptr, sptr
#define GetWindowText GetWindowTextA
#func GetWindowTextA "GetWindowTextA" int, int, int
#func GetWindowThreadProcessId "GetWindowThreadProcessId" int, var
#cfunc GetWindow "GetWindow" int, int
#cfunc IsWindowVisible "IsWindowVisible" int
#define GetClassLong GetClassLongA
#cfunc GetClassLongA "GetClassLongA" int, int
#func DrawIconEx "DrawIconEx" int, int, int, int, int, int, int, int, int
#uselib "shell32.dll"
#define ExtractIcon ExtractIconA
#cfunc ExtractIconA "ExtractIconA" int, str, int
#uselib "kernel32.dll"
#func VirtualProtect@_xdim "VirtualProtect" var,int,int,var
#define xdim(%1,%2) dim %1,%2: VirtualProtect@_xdim %1,%2*4,$40,x@_xdim
#define GW_OWNER 4
#define GCL_HICON -14
#define DI_MASK 0x0001
#define DI_IMAGE 0x0002
#define DI_NORMAL 0x0003
#define CLSID_IMMDeviceEnumerator "{BCDE0395-E52F-467C-8E3D-C4579291692E}"
#define IID_IMMDeviceEnumerator "{A95664D2-9614-4F35-A746-DE8DB63617E6}"
#define IID_IMMDevice "{D666063F-1587-4E43-81F1-B948E807363F}"
#define IID_IAudioEndpointVolume "{5CDF2C82-841E-4546-9722-0CF74078229A}"
#define IID_IAudioClient "{1CB9AD4C-DBFA-4C32-B178-C2F568A703B2}"
#define IID_IAudioSessionManager2 "{77AA99A0-1BD6-484F-8BC7-2C654C9A9B6F}"
#define IID_IAudioSessionEnumerator "{E2F5BB11-0570-40CA-ACDD-3AA01277DEE8}"
#define IID_ISimpleAudioVolume "{87CE5498-68D6-44E5-9215-6DA47EF883D8}"
#define IID_IAudioSessionControl "{F4B1A599-7266-4319-A8CA-E70ACB11E8CD}"
#define IID_IAudioSessionControl2 "{bfb7ff88-7239-4fc9-8fa2-07c950be9c6d}"
#define ERender 0x00000000
#define Console 0x00000000
#usecom IMMDeviceEnumerator IID_IMMDeviceEnumerator CLSID_IMMDeviceEnumerator
#comfunc Enumerator_GetDefaultAudioEndpoint 4 int, int, var
#usecom IMMDevice IID_IMMDevice CLSID_IMMDeviceEnumerator
#comfunc Device_Activate 3 var, int, int, var
#usecom IAudioEndpointVolume IID_IAudioEndpointVolume CLSID_IMMDeviceEnumerator
#comfunc Volume_SetMasterVolumeLevelScalar 7 float, var
#comfunc Volume_GetMasterVolumeLevelScalar 9 var
#comfunc Volume_SetMute 14 int,int
#comfunc Volume_GetMute 15 var
#usecom IAudioClient IID_IAudioClient CLSID_IMMDeviceEnumerator
#comfunc IAudioClient_GetService 14 int, var
#usecom IAudioSessionManager2 IID_IAudioSessionManager2 CLSID_IMMDeviceEnumerator
#comfunc IAudioSessionManager2_GetSessionEnumerator 5 var
#comfunc IAudioSessionManager2_RegisterSessionNotification 6 int
#comfunc IAudioSessionManager2_UnregisterSessionNotification 7 int
#comfunc IAudioSessionManager2_RegisterDuckNotification 8 wstr, int
#comfunc IAudioSessionManager2_UnregisterDuckNotification 9 int
#usecom IAudioSessionEnumerator IID_IAudioSessionEnumerator CLSID_IMMDeviceEnumerator
#comfunc IAudioSessionEnumerator_GetCount 3 var
#comfunc IAudioSessionEnumerator_GetSession 4 int, var
#usecom ISimpleAudioVolume IID_ISimpleAudioVolume CLSID_IMMDeviceEnumerator
#comfunc ISimpleAudioVolume_SetMasterVolume 3 int, int
#comfunc ISimpleAudioVolume_GetMasterVolume 4 var
#comfunc ISimpleAudioVolume_SetMute 5 int,int
#comfunc ISimpleAudioVolume_GetMute 6 var
#usecom IAudioSessionControl IID_IAudioSessionControl CLSID_IMMDeviceEnumerator
#comfunc IAudioSessionControl_GetState 3 var
#comfunc IAudioSessionControl_GetDisplayName 4 var
#comfunc IAudioSessionControl_SetDisplayName 5 wstr, int
#comfunc IAudioSessionControl_GetIconPath 6 var
#comfunc IAudioSessionControl_SetIconPath 7 wstr, int
#comfunc IAudioSessionControl_GetGroupingParam 8 var
#comfunc IAudioSessionControl_SetGroupingParam 9 var, int
#comfunc IAudioSessionControl_RegisterAudioSessionNotification 10 int
#comfunc IAudioSessionControl_UnregisterAudioSessionNotification 11 int
#usecom IAudioSessionControl2 IID_IAudioSessionControl2 CLSID_IMMDeviceEnumerator
#comfunc IAudioSessionControl2_Release 2
#comfunc IAudioSessionControl2_GetState 3 var
#comfunc IAudioSessionControl2_GetDisplayName 4 var
#comfunc IAudioSessionControl2_SetDisplayName 5 wstr, int
#comfunc IAudioSessionControl2_GetIconPath 6 var
#comfunc IAudioSessionControl2_SetIconPath 7 wstr, int
#comfunc IAudioSessionControl2_GetGroupingParam 8 var
#comfunc IAudioSessionControl2_SetGroupingParam 9 var, int
#comfunc IAudioSessionControl2_RegisterAudioSessionNotification 10 int
#comfunc IAudioSessionControl2_UnregisterAudioSessionNotification 11 int
#comfunc IAudioSessionControl2_GetSessionIdentifier 12 var
#comfunc IAudioSessionControl2_GetSessionInstanceIdentifier 13 var
#comfunc IAudioSessionControl2_GetProcessId 14 var
#comfunc IAudioSessionControl2_IsSystemSoundsSession 15
#comfunc IAudioSessionControl2_SetDuckingPreference 16 int
#defcfunc todouble int p1
temp = 0.0;
lpoke temp, 4, (p1 & 0x80000000) | (((p1 & 0x7fffffff) >> 3) + ((p1 & 0x7fffffff) ! 0) * 0x38000000);
lpoke temp, 0, p1 << 29;
return temp;
#defcfunc tofloat double p1
temp = p1;
return lpeek(temp) >> 29 & 7 | (p1 < 0) << 31 |lpeek(temp, 4) - (p1 ! 0) * 0x38000000 << 3;
#deffunc _OpenDevice
newcom pMMDeviceEnumerator, IMMDeviceEnumerator;
if varuse(pMMDeviceEnumerator) = 0 : _CloseDevice : return -1;
newcom pMMDevice, IMMDevice, -1, 0;
newcom pAudioEndpointVolume, IAudioEndpointVolume, -1, 0;
Enumerator_GetDefaultAudioEndpoint pMMDeviceEnumerator, ERender, Console, pMMDevice;
if varuse(pMMDevice) = 0 : _CloseDevice : return -2;
guid = 0x5CDF2C82 , 0x4546841E , 0xF70C2297 , 0x9A227840;
Device_Activate pMMDevice, guid, 1, 0, pAudioEndpointVolume;
if varuse(pAudioEndpointVolume) = 0 : _CloseDevice : return -3;
return 0;
#deffunc _OpenDevice_AudioSessionManager2
newcom pMMDeviceEnumerator, IMMDeviceEnumerator;
if varuse(pMMDeviceEnumerator) = 0 : _CloseDevice : return -1;
newcom pMMDevice, IMMDevice, -1, 0;
newcom pAudioSessionManager2, IAudioSessionManager2, -1, 0;
Enumerator_GetDefaultAudioEndpoint pMMDeviceEnumerator, ERender, Console, pMMDevice;
if varuse(pMMDevice) = 0 : _CloseDevice_AudioSessionManager2 : return -2;
guid = 0x77AA99A0, 0x484F1BD6, 0x652CC78B, 0x6F9B9A4C;
Device_Activate pMMDevice, guid, 1, 0, pAudioSessionManager2;
if varuse(pAudioSessionManager2) = 0 : _CloseDevice_AudioSessionManager2 : return -3;
ptr = 0;
memcpy ptr, pAudioSessionManager2, 4, 0, 0;
newcom pSessionManager2, IAudioSessionManager2, -1, ptr;
IAudioSessionManager2_GetSessionEnumerator pSessionManager2, SessionList;
if ( stat ): _CloseDevice_AudioSessionManager2: return -4;
newcom pSessionEnumerator, IAudioSessionEnumerator, -1, SessionList;
return 0;
#deffunc _CloseDevice
if vartype(pAudioEndpointVolume) = 6{
if varuse(pAudioEndpointVolume) != 0{
delcom pAudioEndpointVolume;
}
}
if vartype(pMMDevice) = 6{
if varuse(pMMDevice) != 0{
delcom pMMDevice;
}
}
if vartype(pMMDeviceEnumerator) = 6{
if varuse(pMMDeviceEnumerator) != 0{
delcom pMMDeviceEnumerator;
}
}
return;
#deffunc _CloseDevice_AudioSessionManager2
if vartype(pMMDevice) = 6{
if varuse(pMMDevice) != 0{
delcom pMMDevice;
}
}
if vartype(pMMDeviceEnumerator) = 6{
if varuse(pMMDeviceEnumerator) != 0{
delcom pMMDeviceEnumerator;
}
}
if vartype(pSessionManager2) = 6{
if varuse(pSessionManager2) != 0{
delcom pSessionManager2;
}
}
if vartype(pAudioSessionManager2) = 6{
if varuse(pAudioSessionManager2) != 0{
delcom pAudioSessionManager2;
}
}
if vartype(pSessionEnumerator) = 6{
if varuse(pSessionEnumerator) != 0{
delcom pSessionEnumerator;
}
}
return;
#deffunc SetMasterVolume int vol
_OpenDevice;
if stat<0 : return stat;
guid = 0, 0, 0, 0;
Volume_SetMasterVolumeLevelScalar pAudioEndpointVolume, 1.0f*(double(vol)/100.0f), guid;
_CloseDevice;
return;
#defcfunc GetMasterVolume
_OpenDevice;
if stat<0 : return stat;
vol = 0;
Volume_GetMasterVolumeLevelScalar pAudioEndpointVolume, vol;
_CloseDevice;
return int(todouble(vol)*100.0f);
#deffunc SetMasterMute int flag
_OpenDevice;
if stat<0 : return stat;
Volume_SetMute pAudioEndpointVolume, flag, 0;
_CloseDevice;
return;
#defcfunc GetMasterMute
_OpenDevice;
if stat<0 : return stat;
res = 0;
Volume_GetMute pAudioEndpointVolume, res;
_CloseDevice;
return res;
#defcfunc GetSessionNum
_OpenDevice_AudioSessionManager2;
if(stat < 0 ): return stat;
IAudioSessionEnumerator_GetCount pSessionEnumerator, num;
_CloseDevice_AudioSessionManager2;
return num
#deffunc _Open_App
ptr = 0;
IAudioSessionEnumerator_GetSession pSessionEnumerator, idx, ptr;
newcom pSessionControl2, IAudioSessionControl2, -1, ptr;
querycom pSimpleAudioVolume, pSessionControl2, ISimpleAudioVolume;
return 0;
#deffunc _Close_App
delcom pSimpleAudioVolume;
delcom pSessionControl2;
return;
#defcfunc GetAppVolume int p1
sn = GetSessionNum();
if((sn < p1)||(p1 < 0)): return -5;
_OpenDevice_AudioSessionManager2;
if(stat < 0 ): return stat;
idx = p1;
_Open_App;
vol = 0;
ISimpleAudioVolume_GetMasterVolume pSimpleAudioVolume, vol;
_CloseDevice_AudioSessionManager2;
_Close_App;
appvol = int(todouble(vol)*GetMasterVolume()+0.5)
return appvol;
#deffunc SetAppVolume int p1, double p2
sn = GetSessionNum();
if((sn < p1)||(p1 < 0)): return -5;
dvol = p2;
if( dvol < 0.0 ) : dvol = 0.0;
if( dvol > 1.0 ) : dvol = 1.0;
_OpenDevice_AudioSessionManager2;
if(stat < 0 ): return stat;
idx = p1;
_Open_App;
ISimpleAudioVolume_SetMasterVolume pSimpleAudioVolume, tofloat(dvol), 0;
_CloseDevice_AudioSessionManager2;
_Close_App;
return appvol;
#defcfunc GetAppMute int p1
sn = GetSessionNum();
if((sn < p1)||(p1 < 0)): return -5;
_OpenDevice_AudioSessionManager2;
if(stat < 0 ): return stat;
idx = p1;
_Open_App;
res = 0;
ISimpleAudioVolume_GetMute pSimpleAudioVolume, res;
_CloseDevice_AudioSessionManager2;
_Close_App;
return res;
#deffunc SetAppMute int p1, int flag
sn = GetSessionNum();
if((sn < p1)||(p1 < 0)): return -5;
_OpenDevice_AudioSessionManager2;
if(stat < 0 ): return stat;
idx = p1;
_Open_App;
ISimpleAudioVolume_SetMute pSimpleAudioVolume, flag, 0;
_CloseDevice_AudioSessionManager2;
_Close_App;
return;
#deffunc _EnumWin int procid
xdim xcode, 19
xcode( 0) = 0x83EC8B55, 0x45C70CEC, 0x111111F4, 0xFC45C711, 0x22222222, 0x33F845C7
xcode( 6) = 0x8B333333, 0x458BF84D, 0x7C0839FC, 0x8BC03308, 0x08C25DE5, 0xFC458B00
xcode(12) = 0x8BF44D8B, 0x08458B10, 0x8B910489, 0x00FFFC45, 0x000001B8, 0x5DE58B00
xcode(18) = 0x000008C2
pfn = varptr(xcode);
t = varptr(wndcnt);
memcpy xcode, t, 4, 16;
t = 256;
memcpy xcode, t, 4, 23;
dim ahwnd, 512;
t = varptr(ahwnd);
memcpy xcode, t, 4, 9;
wndcnt = 0;
EnumWindows pfn, 0;
dim tit, 1;
tit = 0;
repeat wndcnt
hw0 = ahwnd(cnt);
GetWindowThreadProcessId hw0, pid0;
if( pid0 == procid ) {
hw = GetWindow(hw0, GW_OWNER);
vflag = IsWindowVisible(hw0);
if( (hw == 0) && (vflag != 0) ) {
sdim tit, 256;
GetWindowText hw0, varptr(tit), 256;
if( tit != "" ) {
break;
}
}
}
loop
if(tit == 0) {
return NoTitle;
}
return tit;
#deffunc GetAppName int p1
sn = GetSessionNum();
if((sn < p1)||(p1 < 0)): return -5;
_OpenDevice_AudioSessionManager2;
if(stat < 0 ): return stat;
idx = p1;
_Open_App;
IAudioSessionControl2_GetProcessId pSessionControl2, pID;
sdim appname, 256;
if( pID == 0 ) {
appname = "システム音";
}
else {
_EnumWin pID;
appname = refstr;
}
_CloseDevice_AudioSessionManager2;
_Close_App;
return appname;
#deffunc DrawAppIcon int p1, int xLeft, int yTop, int cxWidth, int cyHeight
GetAppName p1;
if(tit == 0) {
if( refstr == "システム音" ) {
hIcon = ExtractIcon( hInstance, "shell32.dll", 0);
}
else {
hIcon = GetClassLong(hWnd, GCL_HICON);
}
}
else {
hIcon = GetClassLong(hw0, GCL_HICON);
if( hIcon == 0 ) {
hIcon = ExtractIcon( hInstance, "shell32.dll", 0);
}
}
DrawIconEx hdc, xLeft, yTop, hIcon, cxWidth, cyHeight, 0, 0, DI_NORMAL;
return;
#global
////////// スピーカーの音量を設定する //////////
; SetMasterVolume p1
; p1 : 0〜100 整数値 0が無音 100が最大音量
////////// スピーカーの音量を取得する //////////
; p1 = GetMasterVolume()
; p1 : 0〜100 整数値 0が無音 100が最大音量
////////// スピーカーのミュート状態を設定する //////////
; SetMasterMute p1
; p1 : 0or1 0は通常 1はミュート(消音)
////////// スピーカーのミュート状態を取得する //////////
; p1 = GetMasterMute()
; p1 : 0or1 0は通常 1はミュート(消音)
////////// セッション数(サウンドを使用しているアプリの数)を取得する //////////
; p1 = GetSessionNum()
; p1 : 1〜 システム音が存在するため通常は最低でも1になっているはず
////////// アプリの音量を設定する //////////
; SetAppVolume p1, p2
; p1 : 0〜 音量を設定するアプリの番号 通常時は0がシステム音、以降はアプリを起動した順番による
; p2 : 0.0〜1.0 実数値 0.0が無音 1.0が最大音量だが、スピーカーの音量を超えることはない
; (スピーカーの音量 * p2 がアプリの音量になる)
////////// アプリの音量を取得する //////////
; p2 = GetAppVolume(p1)
; p1 : 0〜 音量を設定するアプリの番号 通常時は0がシステム音、以降はアプリを起動した順番による
; p2 : 0〜100 整数値 0が無音 100が最大音量だが、スピーカーの音量が100未満のときはそれが最大値
////////// アプリのミュート状態を設定する //////////
; SetAppMute p1, p2
; p1 : 0〜 音量を設定するアプリの番号 通常時は0がシステム音、以降はアプリを起動した順番による
; p2 : 0or1 0は通常 1はミュート(消音)
////////// アプリのミュート状態を取得する //////////
; p2 = GetAppMute(p1)
; p1 : 0〜 音量を設定するアプリの番号 通常時は0がシステム音、以降はアプリを起動した順番による
; p2 : 0or1 0は通常 1はミュート(消音)
////////// アプリの名前を取得する(不完全) //////////
; GetAppName p1
; p1 : 0〜 音量を設定するアプリの番号 通常時は0がシステム音、以降はアプリを起動した順番による
;
; アプリ名は文字列として refstr に返る アプリ名が不明の場合は"タイトル不明"となる
; ブラウザのように1つのウィンドウに複数の子ウィンドウがある場合などは
; 間違った名前が入る可能性がある
////////// 現在の描画対象ウィンドウにアプリのアイコンを描画する(不完全) //////////
; DrawAppIcon p1, x1, y1, x2, y2
; p1 : 0〜 音量を設定するアプリの番号 通常時は0がシステム音、以降はアプリを起動した順番による
; x1, y1 アイコン描画先の左上X,Y座標
; x2, y2 アイコンを描画するサイズX,Y
;
; GetAppNameで取得されるウィンドウで使用しているアイコンを描画するため
; こちらも間違える可能性がある
; 描画後はredrawで画面更新する必要あり
// スピーカーの音量取得
mes "スピーカーの音量:\t\t"+GetMasterVolume()+"";
// スピーカーのミュート状態取得
mes "スピーカーのミュート状態:\t"+GetMasterMute()+"";
// アプリの音量取得
mes "1番目のアプリの音量:\t\t"+GetAppVolume(0)+"";
// アプリのミュート状態取得
mes "1番目のアプリのミュート状態:\t"+GetAppMute(0)+"";
// アプリ名取得
GetAppName 0;
mes "1番目のアプリ:\t\t\t"+refstr+"\n(プロセスIDが0の場合は『システム音』と判断する)";
// アイコン描画(100, 100)の位置に(32, 32)のサイズで描画する
pos 0, 120;
mes "1番目のアプリのアイコン:\n\n(アイコンが取得出来なかった場合は拡張子無しのアイコンや\n HSP(自身)のアイコンになる)";
DrawAppIcon 0, 250, 114, 32, 32;
redraw 1;
| |
|
2018/3/15(Thu) 18:18:14|NO.82754
アイコン取得の所に変なバグがあったので修正しました。
ついでにサンプルソースも少々変更。
アプリ名取得等の不具合は相変わらず、というか現状ではどうしようもないです。
///////////////////////////////////////////////////////////////////////////////////////////////
/////
///// 音量ミキサーモジュール 2018 / 03 / 14
///// (修正 2018 / 03 / 15)
/////
///// <<参考ページ>>
/////
///// スピーカーの音量 http://hsp.tv/play/pforum.php?mode=pastwch&num=34666
///// 各アプリケーション音量 http://hsp.tv/play/pforum.php?mode=all&num=82061
///// EnumWindows http://hsp.tv/play/pforum.php?mode=all&num=82152
/////
/////
/////
#module VolumeMixer
#define NoTitle "タイトル不明"
#uselib "user32.dll"
#func EnumWindows "EnumWindows" sptr, sptr
#define GetWindowText GetWindowTextA
#func GetWindowTextA "GetWindowTextA" int, int, int
#func GetWindowThreadProcessId "GetWindowThreadProcessId" int, var
#cfunc GetWindow "GetWindow" int, int
#cfunc IsWindowVisible "IsWindowVisible" int
#define GetClassLong GetClassLongA
#cfunc GetClassLongA "GetClassLongA" int, int
#func DrawIconEx "DrawIconEx" int, int, int, int, int, int, int, int, int
#uselib "shell32.dll"
#define ExtractIcon ExtractIconA
#cfunc ExtractIconA "ExtractIconA" int, str, int
#uselib "kernel32.dll"
#func VirtualProtect@_xdim "VirtualProtect" var,int,int,var
#define xdim(%1,%2) dim %1,%2: VirtualProtect@_xdim %1,%2*4,$40,x@_xdim
#define GW_OWNER 4
#define GCL_HICON -14
#define DI_MASK 0x0001
#define DI_IMAGE 0x0002
#define DI_NORMAL 0x0003
#define CLSID_IMMDeviceEnumerator "{BCDE0395-E52F-467C-8E3D-C4579291692E}"
#define IID_IMMDeviceEnumerator "{A95664D2-9614-4F35-A746-DE8DB63617E6}"
#define IID_IMMDevice "{D666063F-1587-4E43-81F1-B948E807363F}"
#define IID_IAudioEndpointVolume "{5CDF2C82-841E-4546-9722-0CF74078229A}"
#define IID_IAudioClient "{1CB9AD4C-DBFA-4C32-B178-C2F568A703B2}"
#define IID_IAudioSessionManager2 "{77AA99A0-1BD6-484F-8BC7-2C654C9A9B6F}"
#define IID_IAudioSessionEnumerator "{E2F5BB11-0570-40CA-ACDD-3AA01277DEE8}"
#define IID_ISimpleAudioVolume "{87CE5498-68D6-44E5-9215-6DA47EF883D8}"
#define IID_IAudioSessionControl "{F4B1A599-7266-4319-A8CA-E70ACB11E8CD}"
#define IID_IAudioSessionControl2 "{bfb7ff88-7239-4fc9-8fa2-07c950be9c6d}"
#define ERender 0x00000000
#define Console 0x00000000
#usecom IMMDeviceEnumerator IID_IMMDeviceEnumerator CLSID_IMMDeviceEnumerator
#comfunc Enumerator_GetDefaultAudioEndpoint 4 int, int, var
#usecom IMMDevice IID_IMMDevice CLSID_IMMDeviceEnumerator
#comfunc Device_Activate 3 var, int, int, var
#usecom IAudioEndpointVolume IID_IAudioEndpointVolume CLSID_IMMDeviceEnumerator
#comfunc Volume_SetMasterVolumeLevelScalar 7 float, var
#comfunc Volume_GetMasterVolumeLevelScalar 9 var
#comfunc Volume_SetMute 14 int,int
#comfunc Volume_GetMute 15 var
#usecom IAudioClient IID_IAudioClient CLSID_IMMDeviceEnumerator
#comfunc IAudioClient_GetService 14 int, var
#usecom IAudioSessionManager2 IID_IAudioSessionManager2 CLSID_IMMDeviceEnumerator
#comfunc IAudioSessionManager2_GetSessionEnumerator 5 var
#comfunc IAudioSessionManager2_RegisterSessionNotification 6 int
#comfunc IAudioSessionManager2_UnregisterSessionNotification 7 int
#comfunc IAudioSessionManager2_RegisterDuckNotification 8 wstr, int
#comfunc IAudioSessionManager2_UnregisterDuckNotification 9 int
#usecom IAudioSessionEnumerator IID_IAudioSessionEnumerator CLSID_IMMDeviceEnumerator
#comfunc IAudioSessionEnumerator_GetCount 3 var
#comfunc IAudioSessionEnumerator_GetSession 4 int, var
#usecom ISimpleAudioVolume IID_ISimpleAudioVolume CLSID_IMMDeviceEnumerator
#comfunc ISimpleAudioVolume_SetMasterVolume 3 int, int
#comfunc ISimpleAudioVolume_GetMasterVolume 4 var
#comfunc ISimpleAudioVolume_SetMute 5 int,int
#comfunc ISimpleAudioVolume_GetMute 6 var
#usecom IAudioSessionControl IID_IAudioSessionControl CLSID_IMMDeviceEnumerator
#comfunc IAudioSessionControl_GetState 3 var
#comfunc IAudioSessionControl_GetDisplayName 4 var
#comfunc IAudioSessionControl_SetDisplayName 5 wstr, int
#comfunc IAudioSessionControl_GetIconPath 6 var
#comfunc IAudioSessionControl_SetIconPath 7 wstr, int
#comfunc IAudioSessionControl_GetGroupingParam 8 var
#comfunc IAudioSessionControl_SetGroupingParam 9 var, int
#comfunc IAudioSessionControl_RegisterAudioSessionNotification 10 int
#comfunc IAudioSessionControl_UnregisterAudioSessionNotification 11 int
#usecom IAudioSessionControl2 IID_IAudioSessionControl2 CLSID_IMMDeviceEnumerator
#comfunc IAudioSessionControl2_Release 2
#comfunc IAudioSessionControl2_GetState 3 var
#comfunc IAudioSessionControl2_GetDisplayName 4 var
#comfunc IAudioSessionControl2_SetDisplayName 5 wstr, int
#comfunc IAudioSessionControl2_GetIconPath 6 var
#comfunc IAudioSessionControl2_SetIconPath 7 wstr, int
#comfunc IAudioSessionControl2_GetGroupingParam 8 var
#comfunc IAudioSessionControl2_SetGroupingParam 9 var, int
#comfunc IAudioSessionControl2_RegisterAudioSessionNotification 10 int
#comfunc IAudioSessionControl2_UnregisterAudioSessionNotification 11 int
#comfunc IAudioSessionControl2_GetSessionIdentifier 12 var
#comfunc IAudioSessionControl2_GetSessionInstanceIdentifier 13 var
#comfunc IAudioSessionControl2_GetProcessId 14 var
#comfunc IAudioSessionControl2_IsSystemSoundsSession 15
#comfunc IAudioSessionControl2_SetDuckingPreference 16 int
#defcfunc todouble int p1
temp = 0.0;
lpoke temp, 4, (p1 & 0x80000000) | (((p1 & 0x7fffffff) >> 3) + ((p1 & 0x7fffffff) ! 0) * 0x38000000);
lpoke temp, 0, p1 << 29;
return temp;
#defcfunc tofloat double p1
temp = p1;
return lpeek(temp) >> 29 & 7 | (p1 < 0) << 31 |lpeek(temp, 4) - (p1 ! 0) * 0x38000000 << 3;
#deffunc _OpenDevice
newcom pMMDeviceEnumerator, IMMDeviceEnumerator;
if varuse(pMMDeviceEnumerator) = 0 : _CloseDevice : return -1;
newcom pMMDevice, IMMDevice, -1, 0;
newcom pAudioEndpointVolume, IAudioEndpointVolume, -1, 0;
Enumerator_GetDefaultAudioEndpoint pMMDeviceEnumerator, ERender, Console, pMMDevice;
if varuse(pMMDevice) = 0 : _CloseDevice : return -2;
guid = 0x5CDF2C82 , 0x4546841E , 0xF70C2297 , 0x9A227840;
Device_Activate pMMDevice, guid, 1, 0, pAudioEndpointVolume;
if varuse(pAudioEndpointVolume) = 0 : _CloseDevice : return -3;
return 0;
#deffunc _OpenDevice_AudioSessionManager2
newcom pMMDeviceEnumerator, IMMDeviceEnumerator;
if varuse(pMMDeviceEnumerator) = 0 : _CloseDevice : return -1;
newcom pMMDevice, IMMDevice, -1, 0;
newcom pAudioSessionManager2, IAudioSessionManager2, -1, 0;
Enumerator_GetDefaultAudioEndpoint pMMDeviceEnumerator, ERender, Console, pMMDevice;
if varuse(pMMDevice) = 0 : _CloseDevice_AudioSessionManager2 : return -2;
guid = 0x77AA99A0, 0x484F1BD6, 0x652CC78B, 0x6F9B9A4C;
Device_Activate pMMDevice, guid, 1, 0, pAudioSessionManager2;
if varuse(pAudioSessionManager2) = 0 : _CloseDevice_AudioSessionManager2 : return -3;
ptr = 0;
memcpy ptr, pAudioSessionManager2, 4, 0, 0;
newcom pSessionManager2, IAudioSessionManager2, -1, ptr;
IAudioSessionManager2_GetSessionEnumerator pSessionManager2, SessionList;
if ( stat ): _CloseDevice_AudioSessionManager2: return -4;
newcom pSessionEnumerator, IAudioSessionEnumerator, -1, SessionList;
return 0;
#deffunc _CloseDevice
if vartype(pAudioEndpointVolume) = 6{
if varuse(pAudioEndpointVolume) != 0{
delcom pAudioEndpointVolume;
}
}
if vartype(pMMDevice) = 6{
if varuse(pMMDevice) != 0{
delcom pMMDevice;
}
}
if vartype(pMMDeviceEnumerator) = 6{
if varuse(pMMDeviceEnumerator) != 0{
delcom pMMDeviceEnumerator;
}
}
return;
#deffunc _CloseDevice_AudioSessionManager2
if vartype(pMMDevice) = 6{
if varuse(pMMDevice) != 0{
delcom pMMDevice;
}
}
if vartype(pMMDeviceEnumerator) = 6{
if varuse(pMMDeviceEnumerator) != 0{
delcom pMMDeviceEnumerator;
}
}
if vartype(pSessionManager2) = 6{
if varuse(pSessionManager2) != 0{
delcom pSessionManager2;
}
}
if vartype(pAudioSessionManager2) = 6{
if varuse(pAudioSessionManager2) != 0{
delcom pAudioSessionManager2;
}
}
if vartype(pSessionEnumerator) = 6{
if varuse(pSessionEnumerator) != 0{
delcom pSessionEnumerator;
}
}
return;
#deffunc SetMasterVolume int vol
_OpenDevice;
if stat<0 : return stat;
guid = 0, 0, 0, 0;
Volume_SetMasterVolumeLevelScalar pAudioEndpointVolume, 1.0f*(double(vol)/100.0f), guid;
_CloseDevice;
return;
#defcfunc GetMasterVolume
_OpenDevice;
if stat<0 : return stat;
vol = 0;
Volume_GetMasterVolumeLevelScalar pAudioEndpointVolume, vol;
_CloseDevice;
return int(todouble(vol)*100.0f);
#deffunc SetMasterMute int flag
_OpenDevice;
if stat<0 : return stat;
Volume_SetMute pAudioEndpointVolume, flag, 0;
_CloseDevice;
return;
#defcfunc GetMasterMute
_OpenDevice;
if stat<0 : return stat;
res = 0;
Volume_GetMute pAudioEndpointVolume, res;
_CloseDevice;
return res;
#defcfunc GetSessionNum
_OpenDevice_AudioSessionManager2;
if(stat < 0 ): return stat;
IAudioSessionEnumerator_GetCount pSessionEnumerator, num;
_CloseDevice_AudioSessionManager2;
return num
#deffunc _Open_App
ptr = 0;
IAudioSessionEnumerator_GetSession pSessionEnumerator, idx, ptr;
newcom pSessionControl2, IAudioSessionControl2, -1, ptr;
querycom pSimpleAudioVolume, pSessionControl2, ISimpleAudioVolume;
return 0;
#deffunc _Close_App
if vartype(pSimpleAudioVolume) = 6{
if varuse(pSimpleAudioVolume) != 0{
delcom pSimpleAudioVolume;
}
}
if vartype(pSessionControl2) = 6{
if varuse(pSessionControl2) != 0{
delcom pSessionControl2;
}
}
return;
#defcfunc GetAppVolume int p1
sn = GetSessionNum();
if((sn < p1)||(p1 < 0)): return -5;
_OpenDevice_AudioSessionManager2;
if(stat < 0 ): return stat;
idx = p1;
_Open_App;
vol = 0;
ISimpleAudioVolume_GetMasterVolume pSimpleAudioVolume, vol;
_CloseDevice_AudioSessionManager2;
_Close_App;
appvol = int(todouble(vol)*GetMasterVolume()+0.5)
return appvol;
#deffunc SetAppVolume int p1, double p2
sn = GetSessionNum();
if((sn < p1)||(p1 < 0)): return -5;
dvol = p2;
if( dvol < 0.0 ) : dvol = 0.0;
if( dvol > 1.0 ) : dvol = 1.0;
_OpenDevice_AudioSessionManager2;
if(stat < 0 ): return stat;
idx = p1;
_Open_App;
ISimpleAudioVolume_SetMasterVolume pSimpleAudioVolume, tofloat(dvol), 0;
_CloseDevice_AudioSessionManager2;
_Close_App;
return appvol;
#defcfunc GetAppMute int p1
sn = GetSessionNum();
if((sn < p1)||(p1 < 0)): return -5;
_OpenDevice_AudioSessionManager2;
if(stat < 0 ): return stat;
idx = p1;
_Open_App;
res = 0;
ISimpleAudioVolume_GetMute pSimpleAudioVolume, res;
_CloseDevice_AudioSessionManager2;
_Close_App;
return res;
#deffunc SetAppMute int p1, int flag
sn = GetSessionNum();
if((sn < p1)||(p1 < 0)): return -5;
_OpenDevice_AudioSessionManager2;
if(stat < 0 ): return stat;
idx = p1;
_Open_App;
ISimpleAudioVolume_SetMute pSimpleAudioVolume, flag, 0;
_CloseDevice_AudioSessionManager2;
_Close_App;
return;
#deffunc _EnumWin int procid
xdim xcode, 19
xcode( 0) = 0x83EC8B55, 0x45C70CEC, 0x111111F4, 0xFC45C711, 0x22222222, 0x33F845C7
xcode( 6) = 0x8B333333, 0x458BF84D, 0x7C0839FC, 0x8BC03308, 0x08C25DE5, 0xFC458B00
xcode(12) = 0x8BF44D8B, 0x08458B10, 0x8B910489, 0x00FFFC45, 0x000001B8, 0x5DE58B00
xcode(18) = 0x000008C2
pfn = varptr(xcode);
t = varptr(wndcnt);
memcpy xcode, t, 4, 16;
t = 256;
memcpy xcode, t, 4, 23;
dim ahwnd, 512;
t = varptr(ahwnd);
memcpy xcode, t, 4, 9;
wndcnt = 0;
EnumWindows pfn, 0;
hw0 = 0;
hw = 0;
vflag = 0;
repeat wndcnt
hw0 = ahwnd(cnt);
GetWindowThreadProcessId hw0, pid0;
if( pid0 == procid ) {
hw = GetWindow(hw0, GW_OWNER);
vflag = IsWindowVisible(hw0);
if( (hw == 0) && (vflag != 0) ) {
sdim tit, 256;
GetWindowText hw0, varptr(tit), 256;
if( tit != "" ) {
break;
}
}
}
loop
if(tit == 0) {
return NoTitle;
}
return tit;
#deffunc GetAppName int p1
sn = GetSessionNum();
if((sn < p1)||(p1 < 0)): return -5;
_OpenDevice_AudioSessionManager2;
if(stat < 0 ): return stat;
idx = p1;
_Open_App;
IAudioSessionControl2_GetProcessId pSessionControl2, pID;
sdim appname, 256;
dim tit, 1;
tit = 0;
if( pID == 0 ) {
appname = "システム音";
}
else {
_EnumWin pID;
appname = refstr;
}
_CloseDevice_AudioSessionManager2;
_Close_App;
return appname;
#deffunc DrawAppIcon int id, int xLeft, int yTop, int cxWidth, int cyHeight
GetAppName id;
if( stat < 0 ) {
tit = -1;
}
iconflag = 0;
hIcon = 0;
hIcon1 = 0;
hIcon2 = 0;
if(tit == 0) {
if( refstr == "システム音" ) {
iconflag = 1;
hIcon1 = ExtractIcon( hInstance, "mstsc.exe", 10);
hIcon2 = ExtractIcon( hInstance, "wmploc.dll", 24);
if( (hIcon1 == 0) || (hIcon2 == 0) ) {
hIcon = ExtractIcon( hInstance, "shell32.dll", 109);
}
}
else {
hIcon = ExtractIcon( hInstance, "shell32.dll", 109);
}
}
else {
if( tit != -1 ) {
hIcon = GetClassLong(hw0, GCL_HICON);
}
if( hIcon == 0 ) {
hIcon = ExtractIcon( hInstance, "shell32.dll", 109);
}
}
if( iconflag == 0 ) {
DrawIconEx hdc, xLeft, yTop, hIcon, cxWidth, cyHeight, 0, 0, DI_NORMAL;
}
else {
DrawIconEx hdc, xLeft, yTop, hIcon1, cxWidth, cyHeight, 0, 0, DI_NORMAL;
DrawIconEx hdc, xLeft+cxWidth*2/5, yTop, hIcon2, cxWidth/2, cyHeight/2, 0, 0, DI_NORMAL;
}
return;
#global
////////// スピーカーの音量を設定する //////////
; SetMasterVolume p1
; p1 : 0〜100 整数値 0が無音 100が最大音量
////////// スピーカーの音量を取得する //////////
; p1 = GetMasterVolume()
; p1 : 0〜100 整数値 0が無音 100が最大音量
////////// スピーカーのミュート状態を設定する //////////
; SetMasterMute p1
; p1 : 0or1 0は通常 1はミュート(消音)
////////// スピーカーのミュート状態を取得する //////////
; p1 = GetMasterMute()
; p1 : 0or1 0は通常 1はミュート(消音)
////////// セッション数(サウンドを使用しているアプリの数)を取得する //////////
; p1 = GetSessionNum()
; p1 : 1〜 システム音が存在するため通常は最低でも1になっている
////////// アプリの音量を設定する //////////
; SetAppVolume p1, p2
; p1 : 0〜 音量を設定するアプリの番号 通常時は0がシステム音、以降はアプリを起動した順番による
; p2 : 0.0〜1.0 実数値 0.0が無音 1.0が最大音量だが、スピーカーの音量を超えることはない
; (スピーカーの音量 * p2 がアプリの音量になる)
////////// アプリの音量を取得する //////////
; p2 = GetAppVolume(p1)
; p1 : 0〜 音量を設定するアプリの番号 通常時は0がシステム音、以降はアプリを起動した順番による
; p2 : 0〜100 整数値 0が無音 100が最大音量だが、スピーカーの音量が100未満のときはそれが最大値
////////// アプリのミュート状態を設定する //////////
; SetAppMute p1, p2
; p1 : 0〜 音量を設定するアプリの番号 通常時は0がシステム音、以降はアプリを起動した順番による
; p2 : 0or1 0は通常 1はミュート(消音)
////////// アプリのミュート状態を取得する //////////
; p2 = GetAppMute(p1)
; p1 : 0〜 音量を設定するアプリの番号 通常時は0がシステム音、以降はアプリを起動した順番による
; p2 : 0or1 0は通常 1はミュート(消音)
////////// アプリの名前を取得する(不完全) //////////
; GetAppName p1
; p1 : 0〜 音量を設定するアプリの番号 通常時は0がシステム音、以降はアプリを起動した順番による
;
; アプリ名は文字列として refstr に返る アプリ名が不明の場合は"タイトル不明"となる
; ブラウザのように1つのウィンドウに複数の子ウィンドウがある場合などは
; 間違った名前が入る可能性がある
////////// 現在の描画対象ウィンドウにアプリのアイコンを描画する(不完全) //////////
; DrawAppIcon p1, x1, y1, x2, y2
; p1 : 0〜 音量を設定するアプリの番号 通常時は0がシステム音、以降はアプリを起動した順番による
; x1, y1 アイコン描画先の左上X,Y座標
; x2, y2 アイコンを描画するサイズX,Y
;
; GetAppNameで取得されるウィンドウで使用しているアイコンを描画するため
; こちらも間違える可能性がある
; 描画後はredrawで画面更新する必要あり
title "音量情報表示サンプル"
*sample
redraw 0
color 255, 255, 255:boxf;
color 0, 0, 0:pos 0, 0;
// スピーカー情報取得
mstmute = GetMasterMute();
if( mstmute ) {
mststr = "ミュートしている";
}
else {
mststr = "ミュートではない";
}
mes "スピーカー:\t"+GetMasterVolume()+"\t"+mststr+"\n"
mes "―――――――――――――――アプリケーション――――――――――――――――";
// セッション数取得
session = GetSessionNum();
if( session > 6 ) :session = 6; // 表示領域の関係でセッション数は6つまでにする
// アプリ情報取得
buf1 = "\t名前(半角で20文字まで)\t音量\tミュート\n\n";
buf2 = "\n\n";
buf3 = "\n\n";
y = 86;
repeat session
appvol = GetAppVolume(cnt);
appmute = GetAppMute(cnt);
if( appmute ) {
appstr = "ミュートしている";
}
else {
appstr = "ミュートではない";
}
GetAppName cnt;
appname = refstr;
buf1 += strf("\t%.20s \n\n", appname);
buf2 += strf("%d\n\n", appvol);
buf3 += strf("%s\n\n", appstr);
DrawAppIcon cnt, 0, y+cnt*38, 32, 32;
loop
pos 0, 59: mes buf1;
pos 320, 59: mes buf2;
pos 384, 59: mes buf3;
// 蛇足
pos 0, 360;
mes "―――――――――――――――――注意事項――――――――――――――――――";
mes "プロセスIDが0だった場合はアプリの名前が取得できないので";
mes "『システム音』とし、アイコンも適当に合成した物を描画する。\n"
mes "アイコンが取得出来なかった場合や";
mes "無効なアプリ番号を入力した場合はこちらのアイコンになる";
DrawAppIcon -1, 450, 440, 32, 32;
redraw 1;
wait 10
goto *sample;
| |
|
2018/3/22(Thu) 20:37:06|NO.82794
返信遅れてすみません!
ソースコードまで書いていただきありがとうございます!!!
使わせていただきます
ですがまだ根本的な解決には至らないので
引き続き回答を待ちます
|
|