[SNDVOL32] Advanced Controls dialog: Implemented the Bass and Treble trackbars.
authorEric Kohl <eric.kohl@reactos.org>
Sun, 24 Feb 2019 11:50:37 +0000 (12:50 +0100)
committerEric Kohl <eric.kohl@reactos.org>
Sun, 24 Feb 2019 11:50:37 +0000 (12:50 +0100)
Please check if they are working correctly. I have no way to check them myself.

base/applications/sndvol32/advanced.c

index a4f055f..a41112a 100644 (file)
@@ -7,11 +7,24 @@
 
 #include "sndvol32.h"
 
+typedef struct _ADVANCED_DATA
+{
+    PADVANCED_CONTEXT Context;
+
+    BOOL bEnabled[4];
+    DWORD dwControlId[4];
+
+    /* Bass and Treble */
+    DWORD dwMaximum[2];
+    DWORD dwMinimum[2];
+
+} ADVANCED_DATA, *PADVANCED_DATA;
+
 static
 VOID
 OnInitDialog(
     HWND hwndDlg,
-    PADVANCED_CONTEXT Context)
+    PADVANCED_DATA pData)
 {
     MIXERCONTROLDETAILS_UNSIGNED UnsignedDetails;
     MIXERCONTROLDETAILS_BOOLEAN BooleanDetails;
@@ -25,7 +38,7 @@ OnInitDialog(
 
     /* Set the dialog title */
     LoadStringW(hAppInstance, IDS_ADVANCED_CONTROLS, szRawBuffer, ARRAYSIZE(szRawBuffer));
-    StringCchPrintfW(szCookedBuffer, ARRAYSIZE(szCookedBuffer), szRawBuffer, Context->LineName);
+    StringCchPrintfW(szCookedBuffer, ARRAYSIZE(szCookedBuffer), szRawBuffer, pData->Context->LineName);
     SetWindowTextW(hwndDlg, szCookedBuffer);
 
     /* Disable the tone controls */
@@ -54,7 +67,7 @@ OnInitDialog(
     for (i = IDC_ADV_OTHER_CONTROLS; i<= IDC_ADV_OTHER_CHECK2; i++)
         ShowWindow(GetDlgItem(hwndDlg, i), SW_HIDE);
 
-    if (SndMixerQueryControls(Context->Mixer, &ControlCount, Context->Line, &Control))
+    if (SndMixerQueryControls(pData->Context->Mixer, &ControlCount, pData->Context->Line, &Control))
     {
         for (Index = 0; Index < ControlCount; Index++)
         {
@@ -62,7 +75,7 @@ OnInitDialog(
             {
                 /* Bass control */
 
-                if (SndMixerGetVolumeControlDetails(Context->Mixer, Control[Index].dwControlID, 1, sizeof(MIXERCONTROLDETAILS_UNSIGNED), (LPVOID)&UnsignedDetails) != -1)
+                if (SndMixerGetVolumeControlDetails(pData->Context->Mixer, Control[Index].dwControlID, 1, sizeof(MIXERCONTROLDETAILS_UNSIGNED), (LPVOID)&UnsignedDetails) != -1)
                 {
                     for (i = IDC_ADV_BASS_LOW; i<= IDC_ADV_BASS_SLIDER; i++)
                         EnableWindow(GetDlgItem(hwndDlg, i), TRUE);
@@ -70,13 +83,18 @@ OnInitDialog(
                     dwStep = (Control[Index].Bounds.dwMaximum - Control[Index].Bounds.dwMinimum) / (VOLUME_MAX - VOLUME_MIN);
                     dwPosition = (UnsignedDetails.dwValue - Control[Index].Bounds.dwMinimum) / dwStep;
                     SendDlgItemMessageW(hwndDlg, IDC_ADV_BASS_SLIDER, TBM_SETPOS, (WPARAM)TRUE, dwPosition);
+
+                    pData->bEnabled[0] = TRUE;
+                    pData->dwControlId[0] = Control[Index].dwControlID;
+                    pData->dwMaximum[0] = Control[Index].Bounds.dwMaximum;
+                    pData->dwMinimum[0] = Control[Index].Bounds.dwMinimum;
                 }
             }
             else if (Control[Index].dwControlType == MIXERCONTROL_CONTROLTYPE_TREBLE)
             {
                 /* Treble control */
 
-                if (SndMixerGetVolumeControlDetails(Context->Mixer, Control[Index].dwControlID, 1, sizeof(MIXERCONTROLDETAILS_UNSIGNED), (LPVOID)&UnsignedDetails) != -1)
+                if (SndMixerGetVolumeControlDetails(pData->Context->Mixer, Control[Index].dwControlID, 1, sizeof(MIXERCONTROLDETAILS_UNSIGNED), (LPVOID)&UnsignedDetails) != -1)
                 {
                     for (i = IDC_ADV_TREBLE_LOW; i<= IDC_ADV_TREBLE_SLIDER; i++)
                         EnableWindow(GetDlgItem(hwndDlg, i), TRUE);
@@ -84,6 +102,11 @@ OnInitDialog(
                     dwStep = (Control[Index].Bounds.dwMaximum - Control[Index].Bounds.dwMinimum) / (VOLUME_MAX - VOLUME_MIN);
                     dwPosition = (UnsignedDetails.dwValue - Control[Index].Bounds.dwMinimum) / dwStep;
                     SendDlgItemMessageW(hwndDlg, IDC_ADV_TREBLE_SLIDER, TBM_SETPOS, (WPARAM)TRUE, dwPosition);
+
+                    pData->bEnabled[1] = TRUE;
+                    pData->dwControlId[1] = Control[Index].dwControlID;
+                    pData->dwMaximum[1] = Control[Index].Bounds.dwMaximum;
+                    pData->dwMinimum[1] = Control[Index].Bounds.dwMinimum;
                 }
             }
             else if (((Control[Index].dwControlType & (MIXERCONTROL_CT_CLASS_MASK | MIXERCONTROL_CT_SUBCLASS_MASK | MIXERCONTROL_CT_UNITS_MASK)) == MIXERCONTROL_CONTROLTYPE_BOOLEAN) &&
@@ -93,7 +116,7 @@ OnInitDialog(
 
                 if (dwOtherControls < 2)
                 {
-                    if (SndMixerGetVolumeControlDetails(Context->Mixer, Control[Index].dwControlID, 1, sizeof(MIXERCONTROLDETAILS_BOOLEAN), (LPVOID)&BooleanDetails) != -1)
+                    if (SndMixerGetVolumeControlDetails(pData->Context->Mixer, Control[Index].dwControlID, 1, sizeof(MIXERCONTROLDETAILS_BOOLEAN), (LPVOID)&BooleanDetails) != -1)
                     {
                         LoadStringW(hAppInstance, IDS_OTHER_CONTROLS1 + dwOtherControls, szRawBuffer, ARRAYSIZE(szRawBuffer));
                         StringCchPrintfW(szCookedBuffer, ARRAYSIZE(szCookedBuffer), szRawBuffer, Control[Index].szName);
@@ -103,6 +126,9 @@ OnInitDialog(
 
                         SendDlgItemMessageW(hwndDlg, IDC_ADV_OTHER_CHECK1 + dwOtherControls, BM_SETCHECK, (WPARAM)BooleanDetails.fValue, 0);
 
+                        pData->bEnabled[dwOtherControls + 2] = TRUE;
+                        pData->dwControlId[dwOtherControls + 2] = Control[Index].dwControlID;
+
                         dwOtherControls++;
                     }
                 }
@@ -122,7 +148,7 @@ OnInitDialog(
         /* Resize the dialog */
         GetWindowRect(hwndDlg, &rect);
 
-        dy = MulDiv((dwOtherControls == 1) ? 73 : (73 + 15), Context->MixerWindow->baseUnit.cy, 8);
+        dy = MulDiv((dwOtherControls == 1) ? 73 : (73 + 15), pData->Context->MixerWindow->baseUnit.cy, 8);
         rect.bottom += dy;
 
         SetWindowPos(hwndDlg, HWND_TOP, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, SWP_NOMOVE | SWP_NOZORDER);
@@ -142,7 +168,7 @@ OnInitDialog(
             GetWindowRect(GetDlgItem(hwndDlg, IDC_ADV_OTHER_CONTROLS), &rect);
             MapWindowPoints(HWND_DESKTOP, hwndDlg, (LPPOINT)&rect, 2);
 
-            dy = MulDiv(15, Context->MixerWindow->baseUnit.cy, 8);
+            dy = MulDiv(15, pData->Context->MixerWindow->baseUnit.cy, 8);
             rect.bottom += dy;
 
             SetWindowPos(GetDlgItem(hwndDlg, IDC_ADV_OTHER_CONTROLS), HWND_TOP, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, SWP_NOMOVE | SWP_NOZORDER);
@@ -151,6 +177,49 @@ OnInitDialog(
 }
 
 
+static
+VOID
+OnHScroll(
+    HWND hwndDlg,
+    PADVANCED_DATA pData,
+    DWORD dwCtrlID)
+{
+    MIXERCONTROLDETAILS_UNSIGNED Details;
+    DWORD dwControlID = 0, dwStep, dwPosition;
+    DWORD dwMaximum, dwMinimum;
+
+    if (dwCtrlID != IDC_ADV_BASS_SLIDER ||
+        dwCtrlID != IDC_ADV_TREBLE_SLIDER)
+        return;
+
+    if (dwCtrlID == IDC_ADV_BASS_SLIDER)
+    {
+        if (pData->bEnabled[0] == FALSE)
+            return;
+
+        dwControlID = pData->dwControlId[0];
+        dwMaximum = pData->dwMaximum[0];
+        dwMinimum = pData->dwMinimum[0];
+    }
+    else if (dwCtrlID == IDC_ADV_TREBLE_SLIDER)
+    {
+        if (pData->bEnabled[1] == FALSE)
+            return;
+
+        dwControlID = pData->dwControlId[1];
+        dwMaximum = pData->dwMaximum[1];
+        dwMinimum = pData->dwMinimum[1];
+    }
+
+    dwPosition = (DWORD)SendDlgItemMessage(hwndDlg, dwCtrlID, TBM_GETPOS, 0, 0);
+    dwStep = (dwMaximum - dwMinimum) / (VOLUME_MAX - VOLUME_MIN);
+
+    Details.dwValue = (dwPosition * dwStep) + dwMinimum;
+
+    SndMixerSetVolumeControlDetails(pData->Context->Mixer, dwControlID, 1, sizeof(MIXERCONTROLDETAILS_UNSIGNED), &Details);
+}
+
+
 INT_PTR
 CALLBACK
 AdvancedDlgProc(
@@ -159,14 +228,20 @@ AdvancedDlgProc(
     WPARAM wParam,
     LPARAM lParam)
 {
-    PADVANCED_CONTEXT Context;
+    PADVANCED_DATA pData;
+
+    pData = (PADVANCED_DATA)GetWindowLongPtr(hwndDlg, DWLP_USER);
 
     switch (uMsg)
     {
         case WM_INITDIALOG:
-            SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)lParam);
-            Context = (PADVANCED_CONTEXT)((LONG_PTR)lParam);
-            OnInitDialog(hwndDlg, Context);
+            pData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(ADVANCED_DATA));
+            if (pData != NULL)
+            {
+                SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pData);
+                pData->Context = (PADVANCED_CONTEXT)((LONG_PTR)lParam);
+                OnInitDialog(hwndDlg, pData);
+            }
             return TRUE;
 
         case WM_COMMAND:
@@ -178,9 +253,25 @@ AdvancedDlgProc(
             }
             break;
 
+        case WM_HSCROLL:
+            if (pData != NULL)
+            {
+                 if (LOWORD(wParam) == TB_THUMBTRACK)
+                    OnHScroll(hwndDlg, pData, GetDlgCtrlID((HWND)lParam));
+            }
+            break;
+
         case WM_CLOSE:
             EndDialog(hwndDlg, IDCANCEL);
             break;
+
+        case WM_DESTROY:
+            if (pData != NULL)
+            {
+                HeapFree(GetProcessHeap(), 0, pData);
+                SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)NULL);
+            }
+            break;
     }
 
     return FALSE;