2 * ReactOS Sound Volume Control
3 * Copyright (C) 2004-2005 Thomas Weidenmueller
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 * COPYRIGHT: See COPYING in the top level directory
21 * PROJECT: ReactOS Sound Volume Control
22 * FILE: base/applications/sndvol32/sndvol32.c
23 * PROGRAMMERS: Thomas Weidenmueller <w3seek@reactos.com>
30 HINSTANCE hAppInstance
;
35 PREFERENCES_CONTEXT Preferences
;
37 #define GetDialogData(hwndDlg, type) \
38 ( P##type )GetWindowLongPtr((hwndDlg), DWLP_USER)
39 #define GetWindowData(hwnd, type) \
40 ( P##type )GetWindowLongPtr((hwnd), GWL_USERDATA)
42 /******************************************************************************/
46 typedef struct _PREFERENCES_FILL_DEVICES
48 PPREFERENCES_CONTEXT PrefContext
;
51 } PREFERENCES_FILL_DEVICES
, *PPREFERENCES_FILL_DEVICES
;
54 FillDeviceComboBox(PSND_MIXER Mixer
,
60 PPREFERENCES_FILL_DEVICES FillContext
= (PPREFERENCES_FILL_DEVICES
)Context
;
62 UNREFERENCED_PARAMETER(Mixer
);
64 lres
= SendMessage(FillContext
->hComboBox
,
70 /* save the index so we don't screw stuff when the combobox is sorted... */
71 SendMessage(FillContext
->hComboBox
,
76 if (Id
== FillContext
->Selected
)
78 SendMessage(FillContext
->hComboBox
,
89 PrefDlgAddLine(PSND_MIXER Mixer
,
94 PPREFERENCES_CONTEXT PrefContext
= (PPREFERENCES_CONTEXT
)Context
;
96 UNREFERENCED_PARAMETER(Mixer
);
97 UNREFERENCED_PARAMETER(DisplayControls
);
99 switch (Line
->dwComponentType
)
101 case MIXERLINE_COMPONENTTYPE_DST_SPEAKERS
:
102 if (PrefContext
->PlaybackID
== (DWORD
)-1)
104 PrefContext
->PlaybackID
= Line
->dwLineID
;
106 if (PrefContext
->SelectedLine
== (DWORD
)-1)
108 PrefContext
->SelectedLine
= Line
->dwLineID
;
112 goto AddToOthersLines
;
116 case MIXERLINE_COMPONENTTYPE_DST_WAVEIN
:
117 if (PrefContext
->RecordingID
== (DWORD
)-1)
119 PrefContext
->RecordingID
= Line
->dwLineID
;
121 if (PrefContext
->SelectedLine
== (DWORD
)-1)
123 PrefContext
->SelectedLine
= Line
->dwLineID
;
127 goto AddToOthersLines
;
136 if (PrefContext
->SelectedLine
== (DWORD
)-1)
138 PrefContext
->SelectedLine
= Line
->dwLineID
;
142 hwndCbOthers
= GetDlgItem(PrefContext
->hwndDlg
,
145 lres
= SendMessage(hwndCbOthers
,
148 (LPARAM
)Line
->szName
);
151 SendMessage(hwndCbOthers
,
156 PrefContext
->OtherLines
++;
166 PrefDlgAddConnection(PSND_MIXER Mixer
,
171 PPREFERENCES_CONTEXT PrefContext
= (PPREFERENCES_CONTEXT
)Context
;
176 UNREFERENCED_PARAMETER(Mixer
);
177 UNREFERENCED_PARAMETER(LineID
);
179 if (Line
->cControls
!= 0)
181 hwndControls
= GetDlgItem(PrefContext
->hwndDlg
,
184 lvi
.mask
= LVIF_TEXT
| LVIF_PARAM
;
185 lvi
.iItem
= PrefContext
->tmp
++;
187 lvi
.pszText
= Line
->szName
;
188 lvi
.lParam
= (LPARAM
)Line
->dwSource
;
190 i
= SendMessage(hwndControls
,
196 TCHAR LineName
[MIXER_LONG_NAME_CHARS
];
198 BOOL SelLine
= FALSE
;
200 if (SndMixerGetLineName(PrefContext
->Mixer
,
201 PrefContext
->SelectedLine
,
203 MIXER_LONG_NAME_CHARS
,
206 LineName
[0] = TEXT('\0');
209 if (ReadLineConfig(PrefContext
->DeviceName
,
220 ListView_SetCheckState(hwndControls
,
230 UpdatePrefDlgControls(PPREFERENCES_CONTEXT Context
,
233 INT OldID
, MixerID
= 0;
236 /* select the mixer */
237 DeviceCbIndex
= SendDlgItemMessage(Context
->hwndDlg
,
242 if (DeviceCbIndex
!= CB_ERR
)
244 MixerID
= SendDlgItemMessage(Context
->hwndDlg
,
249 if (MixerID
== CB_ERR
)
255 OldID
= Context
->Selected
;
256 if (MixerID
!= OldID
&&
257 SndMixerSelect(Context
->Mixer
,
260 Context
->Selected
= SndMixerGetSelection(Context
->Mixer
);
262 /* update the controls */
263 Context
->PlaybackID
= (DWORD
)-1;
264 Context
->RecordingID
= (DWORD
)-1;
265 Context
->OtherLines
= 0;
266 Context
->SelectedLine
= (DWORD
)-1;
268 SndMixerGetProductName(Context
->Mixer
,
270 sizeof(Context
->DeviceName
) / sizeof(Context
->DeviceName
[0]));
272 if (SndMixerEnumLines(Context
->Mixer
,
278 /* enable/disable controls and make default selection */
279 EnableWindow(GetDlgItem(Context
->hwndDlg
,
281 Context
->PlaybackID
!= (DWORD
)-1);
282 CheckDlgButton(Context
->hwndDlg
,
284 (Context
->PlaybackID
!= (DWORD
)-1 && SelBox
++ == 0) ?
285 BST_CHECKED
: BST_UNCHECKED
);
287 EnableWindow(GetDlgItem(Context
->hwndDlg
,
289 Context
->RecordingID
!= (DWORD
)-1);
290 CheckDlgButton(Context
->hwndDlg
,
292 (Context
->RecordingID
!= (DWORD
)-1 && SelBox
++ == 0) ?
293 BST_CHECKED
: BST_UNCHECKED
);
295 if (Context
->OtherLines
!= 0)
297 /* select the first item in the other lines combo box by default */
298 SendDlgItemMessage(Context
->hwndDlg
,
304 EnableWindow(GetDlgItem(Context
->hwndDlg
,
307 EnableWindow(GetDlgItem(Context
->hwndDlg
,
309 Context
->OtherLines
!= 0);
310 CheckDlgButton(Context
->hwndDlg
,
312 (Context
->OtherLines
!= 0 && SelBox
++ == 0) ?
313 BST_CHECKED
: BST_UNCHECKED
);
315 /* disable the OK button if the device doesn't have any lines */
316 EnableWindow(GetDlgItem(Context
->hwndDlg
,
318 Context
->PlaybackID
!= (DWORD
)-1 ||
319 Context
->RecordingID
!= (DWORD
)-1 ||
320 Context
->OtherLines
!= 0);
322 LineID
= Context
->SelectedLine
;
326 /* update the line sources list */
327 if ((MixerID
!= OldID
&& Context
->SelectedLine
!= (DWORD
)-1) ||
328 (Context
->SelectedLine
!= LineID
&& LineID
!= (DWORD
)-1))
330 Context
->SelectedLine
= LineID
;
332 (void)ListView_DeleteAllItems(GetDlgItem(Context
->hwndDlg
,
336 SndMixerEnumConnections(Context
->Mixer
,
338 PrefDlgAddConnection
,
345 WriteLineSettings(PPREFERENCES_CONTEXT Context
, HWND hwndDlg
)
349 WCHAR LineName
[MIXER_LONG_NAME_CHARS
];
350 WCHAR DestinationName
[MIXER_LONG_NAME_CHARS
];
352 PSNDVOL_REG_LINESTATE LineStates
;
355 hwndControls
= GetDlgItem(hwndDlg
, IDC_CONTROLS
);
357 /* get list item count */
358 Count
= ListView_GetItemCount(hwndControls
);
363 if (SndMixerGetLineName(Context
->Mixer
, Context
->SelectedLine
, DestinationName
, MIXER_LONG_NAME_CHARS
, TRUE
) == -1)
365 /* failed to get destination line name */
369 /* allocate line states array */
370 LineStates
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(SNDVOL_REG_LINESTATE
) * Count
);
371 if (LineStates
== NULL
)
373 /* failed to allocate line states array */
378 for(Index
= 0; Index
< Count
; Index
++)
384 ListView_GetItemText(hwndControls
, Index
, 0, LineName
, MIXER_LONG_NAME_CHARS
);
386 /* make sure it is null terminated */
387 LineName
[MIXER_LONG_NAME_CHARS
-1] = L
'\0';
389 /* get check state */
390 Flags
= (ListView_GetCheckState(hwndControls
, Index
) == 0 ? 0x4 : 0);
393 wcscpy(LineStates
[Index
].LineName
, LineName
);
396 LineStates
[Index
].Flags
= Flags
;
399 /* now write the line config */
400 WriteLineConfig(Context
->DeviceName
, DestinationName
, LineStates
, sizeof(SNDVOL_REG_LINESTATE
) * Count
);
402 /* free line states */
403 HeapFree(GetProcessHeap(), 0, LineStates
);
406 static INT_PTR CALLBACK
407 DlgPreferencesProc(HWND hwndDlg
,
412 PPREFERENCES_CONTEXT Context
;
418 Context
= GetDialogData(hwndDlg
,
419 PREFERENCES_CONTEXT
);
420 switch (LOWORD(wParam
))
422 case IDC_MIXERDEVICE
:
424 if (HIWORD(wParam
) == CBN_SELCHANGE
)
426 UpdatePrefDlgControls(Context
,
434 if (HIWORD(wParam
) == CBN_SELCHANGE
)
439 Index
= SendDlgItemMessage(hwndDlg
,
446 LineID
= SendDlgItemMessage(hwndDlg
,
451 if (LineID
!= CB_ERR
)
453 UpdatePrefDlgControls(Context
,
463 UpdatePrefDlgControls(Context
,
464 Context
->PlaybackID
);
465 EnableWindow(GetDlgItem(hwndDlg
,
473 UpdatePrefDlgControls(Context
,
474 Context
->RecordingID
);
475 EnableWindow(GetDlgItem(hwndDlg
,
486 EnableWindow(GetDlgItem(hwndDlg
,
490 LineCbIndex
= SendDlgItemMessage(hwndDlg
,
495 if (LineCbIndex
!= CB_ERR
)
497 LineID
= SendDlgItemMessage(hwndDlg
,
502 if (LineID
!= CB_ERR
)
504 UpdatePrefDlgControls(Context
,
513 /* write line settings */
514 WriteLineSettings(Context
, hwndDlg
);
530 PREFERENCES_FILL_DEVICES FillDevContext
;
535 SetWindowLongPtr(hwndDlg
,
538 Context
= (PPREFERENCES_CONTEXT
)((LONG_PTR
)lParam
);
539 Context
->hwndDlg
= hwndDlg
;
540 Context
->Mixer
= SndMixerCreate(hwndDlg
, Context
->MixerWindow
->MixerId
);
541 Context
->Selected
= (UINT
)-1;
543 FillDevContext
.PrefContext
= Context
;
544 FillDevContext
.hComboBox
= GetDlgItem(hwndDlg
,
546 FillDevContext
.Selected
= SndMixerGetSelection(Context
->Mixer
);
547 SndMixerEnumProducts(Context
->Mixer
,
551 /* initialize the list view control */
552 hwndControls
= GetDlgItem(hwndDlg
,
554 (void)ListView_SetExtendedListViewStyle(hwndControls
,
557 GetClientRect(hwndControls
,
559 lvc
.mask
= LVCF_TEXT
| LVCF_WIDTH
;
560 lvc
.pszText
= TEXT("");
561 lvc
.cx
= rcClient
.right
;
562 SendMessage(hwndControls
,
567 /* update all controls */
568 UpdatePrefDlgControls(Context
,
569 (DWORD
)Context
->SelectedLine
);
580 case WM_SYSCOLORCHANGE
:
584 /* Forward WM_SYSCOLORCHANGE */
585 hwndControls
= GetDlgItem(hwndDlg
, IDC_CONTROLS
);
586 SendMessage(hwndControls
, WM_SYSCOLORCHANGE
, 0, 0);
607 /* FIXME: Update the dialog title */
609 /* Disable the tone controls */
610 EnableWindow(GetDlgItem(hwndDlg
, IDC_ADV_BASS_LOW
), FALSE
);
611 EnableWindow(GetDlgItem(hwndDlg
, IDC_ADV_BASS_HIGH
), FALSE
);
612 EnableWindow(GetDlgItem(hwndDlg
, IDC_ADV_BASS_SLIDER
), FALSE
);
613 EnableWindow(GetDlgItem(hwndDlg
, IDC_ADV_TREBLE_LOW
), FALSE
);
614 EnableWindow(GetDlgItem(hwndDlg
, IDC_ADV_TREBLE_HIGH
), FALSE
);
615 EnableWindow(GetDlgItem(hwndDlg
, IDC_ADV_TREBLE_SLIDER
), FALSE
);
617 /* Hide the other controls */
618 ShowWindow(GetDlgItem(hwndDlg
, IDC_ADV_OTHER_CONTROLS
), SW_HIDE
);
619 ShowWindow(GetDlgItem(hwndDlg
, IDC_ADV_OTHER_TEXT
), SW_HIDE
);
620 ShowWindow(GetDlgItem(hwndDlg
, IDC_ADV_OTHER_CHECK1
), SW_HIDE
);
621 ShowWindow(GetDlgItem(hwndDlg
, IDC_ADV_OTHER_CHECK2
), SW_HIDE
);
627 switch (LOWORD(wParam
))
630 EndDialog(hwndDlg
, IDOK
);
636 EndDialog(hwndDlg
, IDCANCEL
);
644 /******************************************************************************/
647 DeleteMixerWindowControls(PMIXER_WINDOW MixerWindow
)
651 for(Index
= 0; Index
< MixerWindow
->WindowCount
; Index
++)
653 /* destroys the window */
654 DestroyWindow(MixerWindow
->Window
[Index
]);
658 HeapFree(GetProcessHeap(), 0, MixerWindow
->Window
);
661 MixerWindow
->Window
= NULL
;
662 MixerWindow
->WindowCount
= 0;
666 RebuildMixerWindowControls(PPREFERENCES_CONTEXT PrefContext
)
668 /* delete existing mixer controls */
669 DeleteMixerWindowControls(PrefContext
->MixerWindow
);
671 /* load new mixer controls */
672 LoadDialogCtrls(PrefContext
);
680 SetVolumeCallback(PSND_MIXER Mixer
, DWORD LineID
, LPMIXERLINE Line
, PVOID Ctx
)
682 UINT ControlCount
= 0, Index
;
683 LPMIXERCONTROL Control
= NULL
;
684 PMIXERCONTROLDETAILS_UNSIGNED puDetails
= NULL
;
685 MIXERCONTROLDETAILS_BOOLEAN bDetails
;
686 PSET_VOLUME_CONTEXT Context
= (PSET_VOLUME_CONTEXT
)Ctx
;
688 /* check if the line name is equal */
689 if (wcsicmp(Line
->szName
, Context
->LineName
))
696 if (SndMixerQueryControls(Mixer
, &ControlCount
, Line
, &Control
) == FALSE
)
698 /* failed to query for controls */
702 puDetails
= HeapAlloc(GetProcessHeap(), 0, Line
->cChannels
* sizeof(MIXERCONTROLDETAILS_UNSIGNED
));
703 if (puDetails
== NULL
)
706 /* now go through all controls and compare control ids */
707 for (Index
= 0; Index
< ControlCount
; Index
++)
709 if (Context
->bVertical
)
711 if ((Control
[Index
].dwControlType
& MIXERCONTROL_CT_CLASS_MASK
) == MIXERCONTROL_CT_CLASS_FADER
)
713 DWORD LineOffset
, volumePosition
, balancePosition
;
714 DWORD volumeStep
, balanceStep
;
716 LineOffset
= Context
->SliderPos
;
718 volumePosition
= (DWORD
)SendDlgItemMessage(Preferences
.MixerWindow
->hWnd
, LineOffset
* IDC_LINE_SLIDER_VERT
, TBM_GETPOS
, 0, 0);
719 volumeStep
= (Control
[Index
].Bounds
.dwMaximum
- Control
[Index
].Bounds
.dwMinimum
) / (VOLUME_MAX
- VOLUME_MIN
);
721 if (Line
->cChannels
== 1)
724 puDetails
[0].dwValue
= ((VOLUME_MAX
- volumePosition
) * volumeStep
) + Control
[Index
].Bounds
.dwMinimum
;
726 else if (Line
->cChannels
== 2)
728 balancePosition
= (DWORD
)SendDlgItemMessage(Preferences
.MixerWindow
->hWnd
, LineOffset
* IDC_LINE_SLIDER_HORZ
, TBM_GETPOS
, 0, 0);
729 if (balancePosition
== BALANCE_CENTER
)
731 puDetails
[0].dwValue
= ((VOLUME_MAX
- volumePosition
) * volumeStep
) + Control
[Index
].Bounds
.dwMinimum
;
732 puDetails
[1].dwValue
= ((VOLUME_MAX
- volumePosition
) * volumeStep
) + Control
[Index
].Bounds
.dwMinimum
;
734 else if (balancePosition
== BALANCE_LEFT
)
736 puDetails
[0].dwValue
= ((VOLUME_MAX
- volumePosition
) * volumeStep
) + Control
[Index
].Bounds
.dwMinimum
;
737 puDetails
[1].dwValue
= Control
[Index
].Bounds
.dwMinimum
;
739 else if (balancePosition
== BALANCE_RIGHT
)
741 puDetails
[0].dwValue
= Control
[Index
].Bounds
.dwMinimum
;
742 puDetails
[1].dwValue
= ((VOLUME_MAX
- volumePosition
) * volumeStep
) + Control
[Index
].Bounds
.dwMinimum
;
744 else if (balancePosition
< BALANCE_CENTER
) // Left
746 puDetails
[0].dwValue
= ((VOLUME_MAX
- volumePosition
) * volumeStep
) + Control
[Index
].Bounds
.dwMinimum
;
748 balanceStep
= (puDetails
[0].dwValue
- Control
[Index
].Bounds
.dwMinimum
) / (BALANCE_STEPS
/ 2);
750 puDetails
[1].dwValue
= (balancePosition
* balanceStep
) + Control
[Index
].Bounds
.dwMinimum
;
752 else if (balancePosition
> BALANCE_CENTER
) // Right
754 puDetails
[1].dwValue
= ((VOLUME_MAX
- volumePosition
) * volumeStep
) + Control
[Index
].Bounds
.dwMinimum
;
756 balanceStep
= (puDetails
[1].dwValue
- Control
[Index
].Bounds
.dwMinimum
) / (BALANCE_STEPS
/ 2);
758 puDetails
[0].dwValue
= ((BALANCE_RIGHT
- balancePosition
) * balanceStep
) + Control
[Index
].Bounds
.dwMinimum
;
763 SndMixerGetVolumeControlDetails(Preferences
.MixerWindow
->Mixer
, Control
[Index
].dwControlID
, Line
->cChannels
, sizeof(MIXERCONTROLDETAILS_UNSIGNED
), (LPVOID
)puDetails
);
769 SndMixerSetVolumeControlDetails(Preferences
.MixerWindow
->Mixer
, Control
[Index
].dwControlID
, Line
->cChannels
, sizeof(MIXERCONTROLDETAILS_UNSIGNED
), (LPVOID
)puDetails
);
775 else if (Context
->bSwitch
)
777 if ((Control
[Index
].dwControlType
& MIXERCONTROL_CT_CLASS_MASK
) == MIXERCONTROL_CT_CLASS_SWITCH
)
780 bDetails
.fValue
= Context
->SliderPos
;
783 SndMixerSetVolumeControlDetails(Preferences
.MixerWindow
->Mixer
, Control
[Index
].dwControlID
, 1, sizeof(MIXERCONTROLDETAILS_BOOLEAN
), (LPVOID
)&bDetails
);
791 if (puDetails
!= NULL
)
792 HeapFree(GetProcessHeap(), 0, puDetails
);
795 HeapFree(GetProcessHeap(), 0, Control
);
805 MixerControlChangeCallback(PSND_MIXER Mixer
, DWORD LineID
, LPMIXERLINE Line
, PVOID Context
)
807 PMIXERCONTROLDETAILS_UNSIGNED pVolumeDetails
= NULL
;
808 UINT ControlCount
= 0, Index
;
809 LPMIXERCONTROL Control
= NULL
;
811 /* check if the line has controls */
812 if (Line
->cControls
== 0)
819 if (SndMixerQueryControls(Mixer
, &ControlCount
, Line
, &Control
) == FALSE
)
821 /* failed to query for controls */
825 pVolumeDetails
= HeapAlloc(GetProcessHeap(),
827 Line
->cChannels
* sizeof(MIXERCONTROLDETAILS_UNSIGNED
));
828 if (pVolumeDetails
== NULL
)
831 /* now go through all controls and compare control ids */
832 for (Index
= 0; Index
< ControlCount
; Index
++)
834 if (Control
[Index
].dwControlID
== PtrToUlong(Context
))
836 if ((Control
[Index
].dwControlType
& MIXERCONTROL_CT_CLASS_MASK
) == MIXERCONTROL_CT_CLASS_SWITCH
)
838 MIXERCONTROLDETAILS_BOOLEAN Details
;
840 /* get volume control details */
841 if (SndMixerGetVolumeControlDetails(Preferences
.MixerWindow
->Mixer
, Control
[Index
].dwControlID
, 1, sizeof(MIXERCONTROLDETAILS_BOOLEAN
), (LPVOID
)&Details
) != -1)
843 /* update dialog control */
844 UpdateDialogLineSwitchControl(&Preferences
, Line
, Details
.fValue
);
847 else if ((Control
[Index
].dwControlType
& MIXERCONTROL_CT_CLASS_MASK
) == MIXERCONTROL_CT_CLASS_FADER
)
849 /* get volume control details */
850 if (SndMixerGetVolumeControlDetails(Preferences
.MixerWindow
->Mixer
, Control
[Index
].dwControlID
, Line
->cChannels
, sizeof(MIXERCONTROLDETAILS_UNSIGNED
), (LPVOID
)pVolumeDetails
) != -1)
852 /* update dialog control */
853 DWORD volumePosition
, volumeStep
, maxVolume
, i
;
854 DWORD balancePosition
, balanceStep
;
856 volumeStep
= (Control
[Index
].Bounds
.dwMaximum
- Control
[Index
].Bounds
.dwMinimum
) / (VOLUME_MAX
- VOLUME_MIN
);
859 for (i
= 0; i
< Line
->cChannels
; i
++)
861 if (pVolumeDetails
[i
].dwValue
> maxVolume
)
862 maxVolume
= pVolumeDetails
[i
].dwValue
;
865 volumePosition
= (maxVolume
- Control
[Index
].Bounds
.dwMinimum
) / volumeStep
;
867 if (Line
->cChannels
== 1)
869 balancePosition
= BALANCE_CENTER
;
871 else if (Line
->cChannels
== 2)
873 if (pVolumeDetails
[0].dwValue
== pVolumeDetails
[1].dwValue
)
875 balancePosition
= BALANCE_CENTER
;
877 else if (pVolumeDetails
[0].dwValue
== Control
[Index
].Bounds
.dwMinimum
)
879 balancePosition
= BALANCE_RIGHT
;
881 else if (pVolumeDetails
[1].dwValue
== Control
[Index
].Bounds
.dwMinimum
)
883 balancePosition
= BALANCE_LEFT
;
887 balanceStep
= (maxVolume
- Control
[Index
].Bounds
.dwMinimum
) / (BALANCE_STEPS
/ 2);
889 if (pVolumeDetails
[0].dwValue
< pVolumeDetails
[1].dwValue
)
891 balancePosition
= (pVolumeDetails
[0].dwValue
- Control
[Index
].Bounds
.dwMinimum
) / balanceStep
;
892 balancePosition
= BALANCE_RIGHT
- balancePosition
;
894 else if (pVolumeDetails
[1].dwValue
< pVolumeDetails
[0].dwValue
)
896 balancePosition
= (pVolumeDetails
[1].dwValue
- Control
[Index
].Bounds
.dwMinimum
) / balanceStep
;
897 balancePosition
= BALANCE_LEFT
+ balancePosition
;
902 /* Update the volume control slider */
903 UpdateDialogLineSliderControl(&Preferences
, Line
, IDC_LINE_SLIDER_VERT
, VOLUME_MAX
- volumePosition
);
905 /* Update the balance control slider */
906 UpdateDialogLineSliderControl(&Preferences
, Line
, IDC_LINE_SLIDER_HORZ
, balancePosition
);
914 /* Free the volume details */
916 HeapFree(GetProcessHeap(), 0, pVolumeDetails
);
919 HeapFree(GetProcessHeap(), 0, Control
);
925 static LRESULT CALLBACK
926 MainWindowProc(HWND hwnd
,
931 PMIXER_WINDOW MixerWindow
;
932 DWORD CtrlID
, LineOffset
;
934 SET_VOLUME_CONTEXT Context
;
940 MixerWindow
= GetWindowData(hwnd
,
943 switch (LOWORD(wParam
))
947 PREFERENCES_CONTEXT Pref
;
949 Pref
.MixerWindow
= MixerWindow
;
951 Pref
.SelectedLine
= Preferences
.SelectedLine
;
953 if (DialogBoxParam(hAppInstance
,
954 MAKEINTRESOURCE(IDD_PREFERENCES
),
957 (LPARAM
)&Pref
) == IDOK
)
960 TCHAR szProduct
[MAXPNAMELEN
];
962 /* get mixer product name */
963 if (SndMixerGetProductName(Pref
.Mixer
,
965 sizeof(szProduct
) / sizeof(szProduct
[0])) == -1)
967 /* failed to get name */
968 szProduct
[0] = L
'\0';
973 wcscpy(Preferences
.DeviceName
, szProduct
);
976 /* destroy old status bar */
977 if (MixerWindow
->Mode
== NORMAL_MODE
)
978 DestroyWindow(MixerWindow
->hStatusBar
);
981 Preferences
.SelectedLine
= Pref
.SelectedLine
;
983 /* destroy old mixer */
984 SndMixerDestroy(Preferences
.MixerWindow
->Mixer
);
986 /* use new selected mixer */
987 Preferences
.MixerWindow
->Mixer
= Pref
.Mixer
;
989 /* create status window */
990 if (MixerWindow
->Mode
== NORMAL_MODE
)
992 MixerWindow
->hStatusBar
= CreateStatusWindow(WS_VISIBLE
| WS_CHILD
| WS_CLIPSIBLINGS
,
996 if (MixerWindow
->hStatusBar
)
999 SendMessage(MixerWindow
->hStatusBar
,
1006 /* rebuild dialog controls */
1007 RebuildMixerWindowControls(&Preferences
);
1012 case IDM_ADVANCED_CONTROLS
:
1013 MixerWindow
->bShowExtendedControls
= !MixerWindow
->bShowExtendedControls
;
1014 CheckMenuItem(GetMenu(hwnd
),
1015 IDM_ADVANCED_CONTROLS
,
1016 MF_BYCOMMAND
| (MixerWindow
->bShowExtendedControls
? MF_CHECKED
: MF_UNCHECKED
));
1017 RebuildMixerWindowControls(&Preferences
);
1028 HICON hAppIcon
= (HICON
)GetClassLongPtrW(hwnd
,
1040 CtrlID
= LOWORD(wParam
);
1042 /* check if the message is from the line switch */
1043 if (HIWORD(wParam
) == BN_CLICKED
)
1045 if (CtrlID
% IDC_LINE_SWITCH
== 0)
1047 /* compute line offset */
1048 LineOffset
= CtrlID
/ IDC_LINE_SWITCH
;
1050 /* compute window id of line name static control */
1051 CtrlID
= LineOffset
* IDC_LINE_NAME
;
1054 if (GetDlgItemTextW(hwnd
, CtrlID
, Context
.LineName
, MIXER_LONG_NAME_CHARS
) != 0)
1057 Context
.SliderPos
= SendMessage((HWND
)lParam
, BM_GETCHECK
, 0, 0);
1058 Context
.bVertical
= FALSE
;
1059 Context
.bSwitch
= TRUE
;
1062 SndMixerEnumConnections(Preferences
.MixerWindow
->Mixer
, Preferences
.SelectedLine
, SetVolumeCallback
, (LPVOID
)&Context
);
1065 else if (CtrlID
% IDC_LINE_ADVANCED
== 0)
1067 if (DialogBoxParam(hAppInstance
,
1068 MAKEINTRESOURCE(IDD_ADVANCED
),
1071 (LPARAM
)NULL
) == IDOK
)
1082 case MM_MIXM_LINE_CHANGE
:
1084 DPRINT("MM_MIXM_LINE_CHANGE\n");
1088 case MM_MIXM_CONTROL_CHANGE
:
1090 DPRINT("MM_MIXM_CONTROL_CHANGE\n");
1092 /* get mixer window */
1093 MixerWindow
= GetWindowData(hwnd
,
1097 assert(MixerWindow
);
1098 assert(MixerWindow
->Mixer
->hmx
== (HMIXER
)wParam
);
1100 SndMixerEnumConnections(MixerWindow
->Mixer
, Preferences
.SelectedLine
, MixerControlChangeCallback
, (PVOID
)lParam
);
1105 switch (LOWORD(wParam
))
1108 /* get dialog item ctrl */
1109 CtrlID
= GetDlgCtrlID((HWND
)lParam
);
1111 /* get line index */
1112 LineOffset
= CtrlID
/ IDC_LINE_SLIDER_VERT
;
1114 /* compute window id of line name static control */
1115 CtrlID
= LineOffset
* IDC_LINE_NAME
;
1118 if (GetDlgItemTextW(hwnd
, CtrlID
, Context
.LineName
, MIXER_LONG_NAME_CHARS
) != 0)
1121 Context
.SliderPos
= LineOffset
;
1122 Context
.bVertical
= TRUE
;
1123 Context
.bSwitch
= FALSE
;
1126 SndMixerEnumConnections(Preferences
.MixerWindow
->Mixer
, Preferences
.SelectedLine
, SetVolumeCallback
, (LPVOID
)&Context
);
1131 MixerWindow
= GetWindowData(hwnd
,
1134 /* get dialog item ctrl */
1135 CtrlID
= GetDlgCtrlID((HWND
)lParam
);
1137 /* get line index */
1138 LineOffset
= CtrlID
/ IDC_LINE_SLIDER_VERT
;
1140 if (LineOffset
== 1 && MixerWindow
->Mixer
->MixerId
== 0)
1141 PlaySound((LPCTSTR
)SND_ALIAS_SYSTEMDEFAULT
, NULL
, SND_ASYNC
| SND_ALIAS_ID
);
1150 switch (LOWORD(wParam
))
1153 /* get dialog item ctrl */
1154 CtrlID
= GetDlgCtrlID((HWND
)lParam
);
1156 /* get line index */
1157 LineOffset
= CtrlID
/ IDC_LINE_SLIDER_HORZ
;
1159 /* compute window id of line name static control */
1160 CtrlID
= LineOffset
* IDC_LINE_NAME
;
1163 if (GetDlgItemTextW(hwnd
, CtrlID
, Context
.LineName
, MIXER_LONG_NAME_CHARS
) != 0)
1166 Context
.SliderPos
= LineOffset
;
1167 Context
.bVertical
= TRUE
;
1168 Context
.bSwitch
= FALSE
;
1171 SndMixerEnumConnections(Preferences
.MixerWindow
->Mixer
, Preferences
.SelectedLine
, SetVolumeCallback
, (LPVOID
)&Context
);
1176 MixerWindow
= GetWindowData(hwnd
,
1179 /* get dialog item ctrl */
1180 CtrlID
= GetDlgCtrlID((HWND
)lParam
);
1182 /* get line index */
1183 LineOffset
= CtrlID
/ IDC_LINE_SLIDER_HORZ
;
1185 if (LineOffset
== 1 && MixerWindow
->Mixer
->MixerId
== 0)
1186 PlaySound((LPCTSTR
)SND_ALIAS_SYSTEMDEFAULT
, NULL
, SND_ASYNC
| SND_ALIAS_ID
);
1197 MixerWindow
= ((LPCREATESTRUCT
)lParam
)->lpCreateParams
;
1198 SetWindowLongPtr(hwnd
,
1200 (LONG_PTR
)MixerWindow
);
1201 MixerWindow
->hWnd
= hwnd
;
1202 MixerWindow
->Mixer
= SndMixerCreate(MixerWindow
->hWnd
, MixerWindow
->MixerId
);
1203 if (MixerWindow
->Mixer
!= NULL
)
1205 TCHAR szProduct
[MAXPNAMELEN
];
1207 /* get mixer product name */
1208 if (SndMixerGetProductName(MixerWindow
->Mixer
,
1210 sizeof(szProduct
) / sizeof(szProduct
[0])) == -1)
1212 /* failed to get name */
1213 szProduct
[0] = L
'\0';
1217 /* initialize preferences */
1218 ZeroMemory(&Preferences
, sizeof(Preferences
));
1221 Preferences
.Mixer
= MixerWindow
->Mixer
;
1223 /* store mixer window */
1224 Preferences
.MixerWindow
= MixerWindow
;
1226 /* first destination line id */
1227 Preferences
.SelectedLine
= 0xFFFF0000;
1230 wcscpy(Preferences
.DeviceName
, szProduct
);
1232 /* Disable the 'Advanced Controls' menu item */
1233 EnableMenuItem(GetMenu(hwnd
), IDM_ADVANCED_CONTROLS
, MF_BYCOMMAND
| MF_GRAYED
);
1235 /* create status window */
1236 if (MixerWindow
->Mode
== NORMAL_MODE
)
1238 MixerWindow
->hStatusBar
= CreateStatusWindow(WS_VISIBLE
| WS_CHILD
| WS_CLIPSIBLINGS
,
1242 if (MixerWindow
->hStatusBar
)
1244 SendMessage(MixerWindow
->hStatusBar
,
1251 if (!RebuildMixerWindowControls(&Preferences
))
1253 DPRINT("Rebuilding mixer window controls failed!\n");
1254 SndMixerDestroy(MixerWindow
->Mixer
);
1255 MixerWindow
->Mixer
= NULL
;
1264 MixerWindow
= GetWindowData(hwnd
,
1266 if (MixerWindow
!= NULL
)
1268 if (MixerWindow
->Mixer
!= NULL
)
1270 SndMixerDestroy(MixerWindow
->Mixer
);
1272 if (MixerWindow
->hFont
)
1273 DeleteObject(MixerWindow
->hFont
);
1274 HeapFree(hAppHeap
, 0, MixerWindow
);
1287 Result
= DefWindowProc(hwnd
,
1299 RegisterApplicationClasses(VOID
)
1303 wc
.cbSize
= sizeof(WNDCLASSEX
);
1304 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
1305 wc
.lpfnWndProc
= MainWindowProc
;
1307 wc
.cbWndExtra
= sizeof(PMIXER_WINDOW
);
1308 wc
.hInstance
= hAppInstance
;
1309 wc
.hIcon
= LoadIcon(hAppInstance
,
1310 MAKEINTRESOURCE(IDI_MAINAPP
));
1311 wc
.hCursor
= LoadCursor(NULL
,
1313 wc
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
1314 wc
.lpszMenuName
= NULL
;
1315 wc
.lpszClassName
= SZ_APP_CLASS
;
1317 MainWindowClass
= RegisterClassEx(&wc
);
1319 return MainWindowClass
!= 0;
1323 UnregisterApplicationClasses(VOID
)
1325 UnregisterClass(SZ_APP_CLASS
,
1330 CreateApplicationWindow(
1331 WINDOW_MODE WindowMode
,
1336 PMIXER_WINDOW MixerWindow
= HeapAlloc(hAppHeap
,
1338 sizeof(MIXER_WINDOW
));
1339 if (MixerWindow
== NULL
)
1344 MixerWindow
->Mode
= WindowMode
;
1345 MixerWindow
->MixerId
= MixerId
;
1347 if (mixerGetNumDevs() > 0)
1349 hWnd
= CreateWindowEx(WS_EX_WINDOWEDGE
| WS_EX_CONTROLPARENT
,
1352 WS_DLGFRAME
| WS_CAPTION
| WS_MINIMIZEBOX
| WS_SYSMENU
| WS_CLIPCHILDREN
| WS_CLIPSIBLINGS
| WS_VISIBLE
,
1355 LoadMenu(hAppInstance
,
1356 MAKEINTRESOURCE(IDM_MAINMENU
)),
1362 LPTSTR lpErrMessage
;
1365 * no mixer devices are available!
1369 if (AllocAndLoadString(&lpErrMessage
,
1371 IDS_NOMIXERDEVICES
))
1376 MB_ICONINFORMATION
);
1377 LocalFree(lpErrMessage
);
1393 HandleCommandLine(LPTSTR cmdline
,
1400 *pMixerId
= PLAY_MIXER
;
1401 *pMode
= (dwStyle
& 0x20) ? SMALL_MODE
: NORMAL_MODE
;
1403 while (*cmdline
== _T(' ') || *cmdline
== _T('-') || *cmdline
== _T('/'))
1405 if (*cmdline
++ == _T(' '))
1411 while (*cmdline
== _T(' '))
1416 case 'd': /* Device */
1420 case 'n': /* Small size */
1422 *pMode
= NORMAL_MODE
;
1425 case 's': /* Small size */
1427 *pMode
= SMALL_MODE
;
1430 case 't': /* Tray size */
1435 case 'p': /* Play mode */
1437 *pMixerId
= PLAY_MIXER
;
1440 case 'r': /* Record mode */
1442 *pMixerId
= RECORD_MIXER
;
1454 _tWinMain(HINSTANCE hInstance
,
1455 HINSTANCE hPrevInstance
,
1461 INITCOMMONCONTROLSEX Controls
;
1462 WINDOW_MODE WindowMode
= SMALL_MODE
;
1466 UNREFERENCED_PARAMETER(hPrevInstance
);
1467 UNREFERENCED_PARAMETER(nCmdShow
);
1469 hAppInstance
= hInstance
;
1470 hAppHeap
= GetProcessHeap();
1472 if (InitAppConfig())
1474 dwStyle
= GetStyleValue();
1475 HandleCommandLine(lpszCmdLine
, dwStyle
, &WindowMode
, &MixerId
);
1477 /* load the application title */
1478 if (!AllocAndLoadString(&lpAppTitle
,
1485 Controls
.dwSize
= sizeof(INITCOMMONCONTROLSEX
);
1486 Controls
.dwICC
= ICC_BAR_CLASSES
| ICC_STANDARD_CLASSES
;
1488 InitCommonControlsEx(&Controls
);
1490 if (WindowMode
== TRAY_MODE
)
1492 DialogBoxParam(hAppInstance
,
1493 MAKEINTRESOURCE(IDD_TRAY_MASTER
),
1500 if (RegisterApplicationClasses())
1502 hMainWnd
= CreateApplicationWindow(WindowMode
, MixerId
);
1503 if (hMainWnd
!= NULL
)
1506 while ((bRet
=GetMessage(&Msg
,
1513 TranslateMessage(&Msg
);
1514 DispatchMessage(&Msg
);
1518 DestroyWindow(hMainWnd
);
1523 DPRINT("Failed to create application window (LastError: %d)!\n", GetLastError());
1526 UnregisterApplicationClasses();
1530 DPRINT("Failed to register application classes (LastError: %d)!\n", GetLastError());
1534 if (lpAppTitle
!= NULL
)
1536 LocalFree(lpAppTitle
);
1543 DPRINT("Unable to open the Volume Control registry key!\n");