[SNDVOL32] Set the ranges, pagesize and ticks for the balance and volume trackbars and fix the conversion between trackbar position and volume value

This commit is contained in:
Eric Kohl 2018-03-15 22:03:33 +01:00
parent 25cacdedb7
commit ad3bda1c8d
3 changed files with 103 additions and 63 deletions

View file

@ -79,6 +79,7 @@ AddDialogControl(
LPWSTR ClassName, WindowName = NULL; LPWSTR ClassName, WindowName = NULL;
HWND hwnd; HWND hwnd;
DWORD wID; DWORD wID;
INT nSteps, i;
/* initialize client rectangle */ /* initialize client rectangle */
rect.left = DialogItem->x; rect.left = DialogItem->x;
@ -145,6 +146,11 @@ AddDialogControl(
wID = DialogItem->id * (DialogIdMultiplier + 1); 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 */ /* now create the window */
hwnd = CreateWindowExW(DialogItem->dwExtendedStyle, hwnd = CreateWindowExW(DialogItem->dwExtendedStyle,
ClassName, ClassName,
@ -168,18 +174,46 @@ AddDialogControl(
/* check if this the track bar */ /* check if this the track bar */
if (!wcsicmp(ClassName, L"msctls_trackbar32")) if (!wcsicmp(ClassName, L"msctls_trackbar32"))
{ {
if (DialogItem->style & TBS_VERT)
{
/* Vertical trackbar: Volume */
/* set up range */ /* set up range */
SendMessage(hwnd, TBM_SETRANGE, (WPARAM) TRUE, (LPARAM) MAKELONG(0, 5)); SendMessage(hwnd, TBM_SETRANGE, (WPARAM)TRUE, (LPARAM)MAKELONG(0, VOLUME_STEPS));
/* set up page size */ /* set up page size */
SendMessage(hwnd, TBM_SETPAGESIZE, 0, (LPARAM) 1); SendMessage(hwnd, TBM_SETPAGESIZE, 0, (LPARAM)VOLUME_PAGE_SIZE);
/* set available range */
//SendMessage(hwnd, TBM_SETSEL, (WPARAM) FALSE, (LPARAM) MAKELONG(0, 5));
/* set position */ /* set position */
SendMessage(hwnd, TBM_SETPOS, (WPARAM) TRUE, (LPARAM) 0); 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")) else if (!wcsicmp(ClassName, L"static") || !wcsicmp(ClassName, L"button"))
{ {
@ -419,7 +453,7 @@ EnumConnectionsCallback(
if (SndMixerQueryControls(Mixer, &ControlCount, Line, &Control) != FALSE) if (SndMixerQueryControls(Mixer, &ControlCount, Line, &Control) != FALSE)
{ {
/* now go through all controls and update their states */ /* 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) if ((Control[Index].dwControlType & MIXERCONTROL_CT_CLASS_MASK) == MIXERCONTROL_CT_CLASS_SWITCH)
{ {
@ -454,10 +488,10 @@ EnumConnectionsCallback(
{ {
/* update dialog control */ /* update dialog control */
DWORD Position; DWORD Position;
DWORD Step = 0x10000 / 5; DWORD Step = 0x10000 / VOLUME_STEPS;
/* FIXME: give me granularity */ /* FIXME: give me granularity */
Position = 5 - (Details.dwValue / Step); Position = VOLUME_STEPS - (Details.dwValue / Step);
/* FIXME support left - right slider */ /* FIXME support left - right slider */
wID = (PrefContext->Count + 1) * IDC_LINE_SLIDER_VERT; wID = (PrefContext->Count + 1) * IDC_LINE_SLIDER_VERT;

View file

@ -651,14 +651,14 @@ SetVolumeCallback(PSND_MIXER Mixer, DWORD LineID, LPMIXERLINE Line, PVOID Ctx)
} }
/* now go through all controls and compare control ids */ /* 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 (Context->bVertical)
{ {
if ((Control[Index].dwControlType & MIXERCONTROL_CT_CLASS_MASK) == MIXERCONTROL_CT_CLASS_FADER) if ((Control[Index].dwControlType & MIXERCONTROL_CT_CLASS_MASK) == MIXERCONTROL_CT_CLASS_FADER)
{ {
/* FIXME: give me granularity */ /* FIXME: give me granularity */
DWORD Step = 0x10000 / 5; DWORD Step = 0x10000 / VOLUME_STEPS;
/* set up details */ /* set up details */
uDetails.dwValue = 0x10000 - Step * Context->SliderPos; 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 */ /* 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)) if (Control[Index].dwControlID == PtrToUlong(Context))
{ {
@ -746,10 +746,10 @@ MixerControlChangeCallback(PSND_MIXER Mixer, DWORD LineID, LPMIXERLINE Line, PVO
{ {
/* update dialog control */ /* update dialog control */
DWORD Position; DWORD Position;
DWORD Step = 0x10000 / 5; DWORD Step = 0x10000 / VOLUME_STEPS;
/* FIXME: give me granularity */ /* FIXME: give me granularity */
Position = 5 - (Details.dwValue / Step); Position = VOLUME_STEPS - (Details.dwValue / Step);
/* update volume control slider */ /* update volume control slider */
UpdateDialogLineSliderControl(&Preferences, Line, Control[Index].dwControlID, IDC_LINE_SLIDER_VERT, Position); 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 */ /* free controls */
HeapFree(GetProcessHeap(), 0, Control); HeapFree(GetProcessHeap(), 0, Control);
/* done */ /* done */
return TRUE; return TRUE;
} }

View file

@ -14,6 +14,13 @@
#include "resources.h" #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 typedef enum _WINDOW_MODE
{ {
NORMAL_MODE, NORMAL_MODE,