Skip to content

Commit 5ca444e

Browse files
committed
[SNDVOL32] Update master volume and mute on external events
1 parent 2e9f7c1 commit 5ca444e

File tree

1 file changed

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

1 file changed

+65
-0
lines changed

base/applications/sndvol32/tray.c

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,67 @@ 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) return;
295+
296+
mxcd.cChannels = pDialogData->volumeChannels;
297+
mxcd.cbDetails = sizeof(*mxcdVolume);
298+
mxcd.paDetails = mxcdVolume;
299+
300+
if (mixerGetControlDetails((HMIXEROBJ)hMixer, &mxcd, MIXER_OBJECTF_HMIXER | MIXER_GETCONTROLDETAILSF_VALUE) != MMSYSERR_NOERROR)
301+
return;
302+
303+
/* The Volume trackbar always shows the maximum volume value of all channels.
304+
* Changing volume balance in "full" sndvol32 view must not affect it. */
305+
DWORD dwVolume = 0;
306+
for (int i = 0; i < pDialogData->volumeChannels; ++i)
307+
{
308+
if (mxcdVolume[i].dwValue <= dwVolume)
309+
continue;
310+
311+
dwVolume = mxcdVolume[i].dwValue;
312+
}
313+
314+
DWORD dwNewPosition = VOLUME_MAX - dwVolume / pDialogData->volumeStep;
315+
SendDlgItemMessageW(hwndDlg, IDC_LINE_SLIDER_VERT, TBM_SETPOS, TRUE, dwNewPosition);
316+
317+
HeapFree(GetProcessHeap(), 0, mxcdVolume);
318+
}
319+
}
260320

261321
INT_PTR
262322
CALLBACK
@@ -314,6 +374,11 @@ TrayDlgProc(
314374
if (LOWORD(wParam) == WA_INACTIVE)
315375
EndDialog(hwndDlg, IDOK);
316376
break;
377+
378+
case MM_MIXM_CONTROL_CHANGE:
379+
if (pDialogData)
380+
OnMixerControlChange(pDialogData, hwndDlg, wParam, lParam);
381+
break;
317382
}
318383

319384
return 0;

0 commit comments

Comments
 (0)