Skip to content

Commit 2ed09e6

Browse files
committed
[SNDVOL32] Update master volume and mute on external events
1 parent d59d354 commit 2ed09e6

File tree

1 file changed

+66
-0
lines changed
  • base/applications/sndvol32

1 file changed

+66
-0
lines changed

base/applications/sndvol32/tray.c

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,68 @@ OnVScroll(
256256
}
257257
}
258258

259+
static
260+
VOID
261+
OnMixerControlChange(
262+
PDIALOG_DATA pDialogData,
263+
HWND hwndDlg,
264+
WPARAM wParam,
265+
LPARAM lParam)
266+
{
267+
HMIXER hMixer = (HMIXER)wParam;
268+
DWORD dwControlID = lParam;
259269

270+
if (hMixer != pDialogData->hMixer)
271+
return;
272+
273+
MIXERCONTROLDETAILS mxcd;
274+
mxcd.cbStruct = sizeof(mxcd);
275+
mxcd.dwControlID = dwControlID;
276+
mxcd.cMultipleItems = 0;
277+
278+
if (dwControlID == pDialogData->muteControlID)
279+
{
280+
MIXERCONTROLDETAILS_BOOLEAN mxcdBool;
281+
282+
mxcd.cChannels = 1;
283+
mxcd.cbDetails = sizeof(mxcdBool);
284+
mxcd.paDetails = &mxcdBool;
285+
286+
if (mixerGetControlDetails((HMIXEROBJ)hMixer, &mxcd, MIXER_OBJECTF_HMIXER | MIXER_GETCONTROLDETAILSF_VALUE) == MMSYSERR_NOERROR)
287+
SendDlgItemMessageW(hwndDlg, IDC_LINE_SWITCH, BM_SETCHECK, (WPARAM)(mxcdBool.fValue ? BST_CHECKED : BST_UNCHECKED), 0);
288+
}
289+
else if (dwControlID == pDialogData->volumeControlID)
290+
{
291+
PMIXERCONTROLDETAILS_UNSIGNED mxcdVolume;
292+
293+
mxcdVolume = HeapAlloc(GetProcessHeap(), 0, pDialogData->volumeChannels * sizeof(*mxcdVolume));
294+
if (mxcdVolume == NULL)
295+
return;
296+
297+
mxcd.cChannels = pDialogData->volumeChannels;
298+
mxcd.cbDetails = sizeof(*mxcdVolume);
299+
mxcd.paDetails = mxcdVolume;
300+
301+
if (mixerGetControlDetails((HMIXEROBJ)hMixer, &mxcd, MIXER_OBJECTF_HMIXER | MIXER_GETCONTROLDETAILSF_VALUE) != MMSYSERR_NOERROR)
302+
return;
303+
304+
/* The Volume trackbar always shows the maximum volume value of all channels.
305+
* Changing volume balance in "full" sndvol32 view must not affect it. */
306+
DWORD dwVolume = 0;
307+
for (int i = 0; i < pDialogData->volumeChannels; ++i)
308+
{
309+
if (mxcdVolume[i].dwValue <= dwVolume)
310+
continue;
311+
312+
dwVolume = mxcdVolume[i].dwValue;
313+
}
314+
315+
DWORD dwNewPosition = VOLUME_MAX - dwVolume / pDialogData->volumeStep;
316+
SendDlgItemMessageW(hwndDlg, IDC_LINE_SLIDER_VERT, TBM_SETPOS, TRUE, dwNewPosition);
317+
318+
HeapFree(GetProcessHeap(), 0, mxcdVolume);
319+
}
320+
}
260321

261322
INT_PTR
262323
CALLBACK
@@ -314,6 +375,11 @@ TrayDlgProc(
314375
if (LOWORD(wParam) == WA_INACTIVE)
315376
EndDialog(hwndDlg, IDOK);
316377
break;
378+
379+
case MM_MIXM_CONTROL_CHANGE:
380+
if (pDialogData)
381+
OnMixerControlChange(pDialogData, hwndDlg, wParam, lParam);
382+
break;
317383
}
318384

319385
return 0;

0 commit comments

Comments
 (0)