https://git.reactos.org/?p=reactos.git;a=commitdiff;h=ad3bda1c8dd0c79541d59d2ea483d2de04c043b0

commit ad3bda1c8dd0c79541d59d2ea483d2de04c043b0
Author:     Eric Kohl <[email protected]>
AuthorDate: Thu Mar 15 22:03:33 2018 +0100
Commit:     Eric Kohl <[email protected]>
CommitDate: Thu Mar 15 22:03:33 2018 +0100

    [SNDVOL32] Set the ranges, pagesize and ticks for the balance and volume 
trackbars and fix the conversion between trackbar position and volume value
---
 base/applications/sndvol32/dialog.c   | 164 ++++++++++++++++++++--------------
 base/applications/sndvol32/sndvol32.c |  11 ++-
 base/applications/sndvol32/sndvol32.h |   7 ++
 3 files changed, 111 insertions(+), 71 deletions(-)

diff --git a/base/applications/sndvol32/dialog.c 
b/base/applications/sndvol32/dialog.c
index e736f4bb0a..621e905a81 100644
--- a/base/applications/sndvol32/dialog.c
+++ b/base/applications/sndvol32/dialog.c
@@ -79,6 +79,7 @@ AddDialogControl(
     LPWSTR ClassName, WindowName = NULL;
     HWND hwnd;
     DWORD wID;
+    INT nSteps, i;
 
     /* initialize client rectangle */
     rect.left = DialogItem->x;
@@ -145,6 +146,11 @@ AddDialogControl(
         wID = DialogItem->id * (DialogIdMultiplier + 1);
 
     }
+
+    /* Hack: Disable TBS_AUTOTICKS because it looks ugly */
+    if (!wcsicmp(ClassName, L"msctls_trackbar32"))
+        DialogItem->style &= ~TBS_AUTOTICKS;
+
     /* now create the window */
     hwnd = CreateWindowExW(DialogItem->dwExtendedStyle,
                            ClassName,
@@ -168,18 +174,46 @@ AddDialogControl(
     /* check if this the track bar */
     if (!wcsicmp(ClassName, L"msctls_trackbar32"))
     {
-        /* set up range */
-        SendMessage(hwnd, TBM_SETRANGE, (WPARAM) TRUE, (LPARAM) MAKELONG(0, 
5));
+        if (DialogItem->style & TBS_VERT)
+        {
+            /* Vertical trackbar: Volume */
 
-        /* set up page size */
-        SendMessage(hwnd, TBM_SETPAGESIZE, 0, (LPARAM) 1);
+            /* set up range */
+            SendMessage(hwnd, TBM_SETRANGE, (WPARAM)TRUE, (LPARAM)MAKELONG(0, 
VOLUME_STEPS));
 
-        /* set available range */
-        //SendMessage(hwnd, TBM_SETSEL, (WPARAM) FALSE, (LPARAM) MAKELONG(0, 
5));
+            /* set up page size */
+            SendMessage(hwnd, TBM_SETPAGESIZE, 0, (LPARAM)VOLUME_PAGE_SIZE);
 
-        /* set position */
-        SendMessage(hwnd, TBM_SETPOS, (WPARAM) TRUE, (LPARAM) 0);
+            /* set position */
+            SendMessage(hwnd, TBM_SETPOS, (WPARAM)TRUE, (LPARAM)0);
 
+            /* Calculate and set ticks */
+            nSteps = (VOLUME_STEPS / (VOLUME_TICKS + 1));
+            if (VOLUME_STEPS % (VOLUME_TICKS + 1) != 0)
+                nSteps++;
+            for (i = nSteps; i < VOLUME_STEPS; i += nSteps)
+                SendMessage(hwnd, TBM_SETTIC, 0, (LPARAM)i);
+        }
+        else
+        {
+            /* Horizontal trackbar: Balance */
+
+            /* set up range */
+            SendMessage(hwnd, TBM_SETRANGE, (WPARAM)TRUE, (LPARAM)MAKELONG(0, 
BALANCE_STEPS));
+
+            /* set up page size */
+            SendMessage(hwnd, TBM_SETPAGESIZE, 0, (LPARAM)BALANCE_PAGE_SIZE);
+
+            /* set position */
+            SendMessage(hwnd, TBM_SETPOS, (WPARAM)TRUE, (LPARAM)BALANCE_STEPS 
/ 2);
+
+            /* Calculate and set ticks */
+            nSteps = (BALANCE_STEPS / (BALANCE_TICKS + 1));
+            if (BALANCE_STEPS % (BALANCE_TICKS + 1) != 0)
+                nSteps++;
+            for (i = nSteps; i < BALANCE_STEPS; i += nSteps)
+                SendMessage(hwnd, TBM_SETTIC, 0, (LPARAM)i);
+        }
     }
     else if (!wcsicmp(ClassName, L"static") || !wcsicmp(ClassName, L"button"))
     {
@@ -419,64 +453,64 @@ EnumConnectionsCallback(
               if (SndMixerQueryControls(Mixer, &ControlCount, Line, &Control) 
!= FALSE)
               {
                   /* now go through all controls and update their states */
-                  for(Index = 0; Index < ControlCount; Index++)
+                  for(Index = 0; Index < Line->cControls; Index++)
                   {
-                     if ((Control[Index].dwControlType & 
MIXERCONTROL_CT_CLASS_MASK) == MIXERCONTROL_CT_CLASS_SWITCH)
-                     {
-                         MIXERCONTROLDETAILS_BOOLEAN Details;
-
-                         /* get volume control details */
-                         if (SndMixerGetVolumeControlDetails(Mixer, 
Control[Index].dwControlID, sizeof(MIXERCONTROLDETAILS_BOOLEAN), 
(LPVOID)&Details) != -1)
-                         {
-                             /* update dialog control */
-                             wID = (PrefContext->Count + 1) * IDC_LINE_SWITCH;
-
-                            /* get dialog control */
-                            hDlgCtrl = 
GetDlgItem(PrefContext->MixerWindow->hWnd, wID);
-
-                            if (hDlgCtrl != NULL)
-                            {
-                                /* check state */
-                                if (SendMessageW(hDlgCtrl, BM_GETCHECK, 0, 0) 
!= Details.fValue)
-                                {
-                                    /* update control state */
-                                    SendMessageW(hDlgCtrl, BM_SETCHECK, 
(WPARAM)Details.fValue, 0);
-                                }
-                            }
-                         }
-                     }
-                     else if ((Control[Index].dwControlType & 
MIXERCONTROL_CT_CLASS_MASK) == MIXERCONTROL_CT_CLASS_FADER)
-                     {
-                         MIXERCONTROLDETAILS_UNSIGNED Details;
-
-                         /* get volume control details */
-                         if (SndMixerGetVolumeControlDetails(Mixer, 
Control[Index].dwControlID, sizeof(MIXERCONTROLDETAILS_UNSIGNED), 
(LPVOID)&Details) != -1)
-                         {
-                             /* update dialog control */
-                             DWORD Position;
-                             DWORD Step = 0x10000 / 5;
-
-                             /* FIXME: give me granularity */
-                             Position = 5 - (Details.dwValue / Step);
-
-                             /* FIXME support left - right slider */
-                             wID = (PrefContext->Count + 1) * 
IDC_LINE_SLIDER_VERT;
-
-                             /* get dialog control */
-                             hDlgCtrl = 
GetDlgItem(PrefContext->MixerWindow->hWnd, wID);
-
-                             if (hDlgCtrl != NULL)
-                             {
-                                 /* check state */
-                                 LRESULT OldPosition = SendMessageW(hDlgCtrl, 
TBM_GETPOS, 0, 0);
-                                 if (OldPosition != Position)
-                                 {
-                                     /* update control state */
-                                     SendMessageW(hDlgCtrl, TBM_SETPOS, 
(WPARAM)TRUE, Position + Index);
-                                 }
-                             }
-                        }
-                     }
+                      if ((Control[Index].dwControlType & 
MIXERCONTROL_CT_CLASS_MASK) == MIXERCONTROL_CT_CLASS_SWITCH)
+                      {
+                          MIXERCONTROLDETAILS_BOOLEAN Details;
+
+                          /* get volume control details */
+                          if (SndMixerGetVolumeControlDetails(Mixer, 
Control[Index].dwControlID, sizeof(MIXERCONTROLDETAILS_BOOLEAN), 
(LPVOID)&Details) != -1)
+                          {
+                              /* update dialog control */
+                              wID = (PrefContext->Count + 1) * IDC_LINE_SWITCH;
+
+                              /* get dialog control */
+                              hDlgCtrl = 
GetDlgItem(PrefContext->MixerWindow->hWnd, wID);
+
+                              if (hDlgCtrl != NULL)
+                              {
+                                  /* check state */
+                                  if (SendMessageW(hDlgCtrl, BM_GETCHECK, 0, 
0) != Details.fValue)
+                                  {
+                                      /* update control state */
+                                      SendMessageW(hDlgCtrl, BM_SETCHECK, 
(WPARAM)Details.fValue, 0);
+                                  }
+                              }
+                          }
+                      }
+                      else if ((Control[Index].dwControlType & 
MIXERCONTROL_CT_CLASS_MASK) == MIXERCONTROL_CT_CLASS_FADER)
+                      {
+                          MIXERCONTROLDETAILS_UNSIGNED Details;
+
+                          /* get volume control details */
+                          if (SndMixerGetVolumeControlDetails(Mixer, 
Control[Index].dwControlID, sizeof(MIXERCONTROLDETAILS_UNSIGNED), 
(LPVOID)&Details) != -1)
+                          {
+                              /* update dialog control */
+                              DWORD Position;
+                              DWORD Step = 0x10000 / VOLUME_STEPS;
+
+                              /* FIXME: give me granularity */
+                              Position = VOLUME_STEPS - (Details.dwValue / 
Step);
+
+                              /* FIXME support left - right slider */
+                              wID = (PrefContext->Count + 1) * 
IDC_LINE_SLIDER_VERT;
+
+                              /* get dialog control */
+                              hDlgCtrl = 
GetDlgItem(PrefContext->MixerWindow->hWnd, wID);
+
+                              if (hDlgCtrl != NULL)
+                              {
+                                  /* check state */
+                                  LRESULT OldPosition = SendMessageW(hDlgCtrl, 
TBM_GETPOS, 0, 0);
+                                  if (OldPosition != Position)
+                                  {
+                                      /* update control state */
+                                      SendMessageW(hDlgCtrl, TBM_SETPOS, 
(WPARAM)TRUE, Position + Index);
+                                  }
+                              }
+                          }
+                      }
                   }
 
                   /* free controls */
diff --git a/base/applications/sndvol32/sndvol32.c 
b/base/applications/sndvol32/sndvol32.c
index 26b5ba99e7..44c4b44956 100644
--- a/base/applications/sndvol32/sndvol32.c
+++ b/base/applications/sndvol32/sndvol32.c
@@ -651,14 +651,14 @@ SetVolumeCallback(PSND_MIXER Mixer, DWORD LineID, 
LPMIXERLINE Line, PVOID Ctx)
     }
 
     /* now go through all controls and compare control ids */
-    for(Index = 0; Index < ControlCount; Index++)
+    for (Index = 0; Index < ControlCount; Index++)
     {
         if (Context->bVertical)
         {
             if ((Control[Index].dwControlType & MIXERCONTROL_CT_CLASS_MASK) == 
MIXERCONTROL_CT_CLASS_FADER)
             {
                 /* FIXME: give me granularity */
-                DWORD Step = 0x10000 / 5;
+                DWORD Step = 0x10000 / VOLUME_STEPS;
 
                 /* set up details */
                 uDetails.dwValue = 0x10000 - Step * Context->SliderPos;
@@ -722,7 +722,7 @@ MixerControlChangeCallback(PSND_MIXER Mixer, DWORD LineID, 
LPMIXERLINE Line, PVO
     }
 
     /* now go through all controls and compare control ids */
-    for(Index = 0; Index < ControlCount; Index++)
+    for (Index = 0; Index < ControlCount; Index++)
     {
         if (Control[Index].dwControlID == PtrToUlong(Context))
         {
@@ -746,10 +746,10 @@ MixerControlChangeCallback(PSND_MIXER Mixer, DWORD 
LineID, LPMIXERLINE Line, PVO
                 {
                     /* update dialog control */
                     DWORD Position;
-                    DWORD Step = 0x10000 / 5;
+                    DWORD Step = 0x10000 / VOLUME_STEPS;
 
                     /* FIXME: give me granularity */
-                    Position = 5 - (Details.dwValue / Step);
+                    Position = VOLUME_STEPS - (Details.dwValue / Step);
 
                     /* update volume control slider */
                     UpdateDialogLineSliderControl(&Preferences, Line, 
Control[Index].dwControlID, IDC_LINE_SLIDER_VERT, Position);
@@ -762,7 +762,6 @@ MixerControlChangeCallback(PSND_MIXER Mixer, DWORD LineID, 
LPMIXERLINE Line, PVO
     /* free controls */
     HeapFree(GetProcessHeap(), 0, Control);
 
-
     /* done */
     return TRUE;
 }
diff --git a/base/applications/sndvol32/sndvol32.h 
b/base/applications/sndvol32/sndvol32.h
index 640ac20c8f..ad7311fa86 100644
--- a/base/applications/sndvol32/sndvol32.h
+++ b/base/applications/sndvol32/sndvol32.h
@@ -14,6 +14,13 @@
 
 #include "resources.h"
 
+#define VOLUME_STEPS       500
+#define VOLUME_TICKS         5
+#define VOLUME_PAGE_SIZE   100
+#define BALANCE_STEPS       64
+#define BALANCE_TICKS        1
+#define BALANCE_PAGE_SIZE   12
+
 typedef enum _WINDOW_MODE
 {
     NORMAL_MODE,

Reply via email to