forked from jfchapman/VUPlayer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DlgAdvancedWasapi.cpp
104 lines (95 loc) · 3.36 KB
/
DlgAdvancedWasapi.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include "DlgAdvancedWasapi.h"
#include "resource.h"
#include "Utility.h"
INT_PTR CALLBACK DlgAdvancedWasapi::DialogProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
{
switch ( message ) {
case WM_INITDIALOG : {
DlgAdvancedWasapi* dialog = reinterpret_cast<DlgAdvancedWasapi*>( lParam );
if ( nullptr != dialog ) {
SetWindowLongPtr( hwnd, DWLP_USER, lParam );
dialog->OnInitDialog( hwnd );
return TRUE;
}
break;
}
case WM_DESTROY : {
SetWindowLongPtr( hwnd, DWLP_USER, 0 );
break;
}
case WM_COMMAND : {
switch ( LOWORD( wParam ) ) {
case IDOK : {
DlgAdvancedWasapi* dialog = reinterpret_cast<DlgAdvancedWasapi*>( GetWindowLongPtr( hwnd, DWLP_USER ) );
if ( nullptr != dialog ) {
dialog->SaveSettings( hwnd );
}
}
case IDCANCEL : {
EndDialog( hwnd, 0 );
return TRUE;
}
case IDC_WASAPI_RESET : {
DlgAdvancedWasapi* dialog = reinterpret_cast<DlgAdvancedWasapi*>( GetWindowLongPtr( hwnd, DWLP_USER ) );
if ( nullptr != dialog ) {
dialog->ResetToDefaults( hwnd );
}
break;
}
}
break;
}
}
return FALSE;
}
DlgAdvancedWasapi::DlgAdvancedWasapi( const HINSTANCE instance, const HWND parent, Settings& settings ) :
m_Settings( settings )
{
DialogBoxParam( instance, MAKEINTRESOURCE( IDD_ADVANCED_WASAPI ), parent, DialogProc, reinterpret_cast<LPARAM>( this ) );
}
DlgAdvancedWasapi::~DlgAdvancedWasapi()
{
}
void DlgAdvancedWasapi::OnInitDialog( const HWND hwnd )
{
CentreDialog( hwnd );
bool useDeviceDefaultFormat = false;
int bufferLength = 0;
int leadIn = 0;
m_Settings.GetAdvancedWasapiExclusiveSettings( useDeviceDefaultFormat, bufferLength, leadIn );
SetDlgItemInt( hwnd, IDC_WASAPI_BUFFERLENGTH, static_cast<UINT>( bufferLength ), FALSE );
SetDlgItemInt( hwnd, IDC_WASAPI_LEADIN, static_cast<UINT>( leadIn ), FALSE );
CheckRadioButton( hwnd, IDC_WASAPI_OUTPUT_DEFAULT, IDC_WASAPI_OUTPUT_SOURCE,
useDeviceDefaultFormat ? IDC_WASAPI_OUTPUT_DEFAULT : IDC_WASAPI_OUTPUT_SOURCE );
}
void DlgAdvancedWasapi::SaveSettings( const HWND hwnd )
{
bool useDeviceDefaultFormat = false;
int bufferLength = 0;
int leadIn = 0;
m_Settings.GetAdvancedWasapiExclusiveSettings( useDeviceDefaultFormat, bufferLength, leadIn );
useDeviceDefaultFormat = ( BST_CHECKED == IsDlgButtonChecked( hwnd, IDC_WASAPI_OUTPUT_DEFAULT ) );
BOOL success = FALSE;
UINT value = GetDlgItemInt( hwnd, IDC_WASAPI_BUFFERLENGTH, &success, FALSE );
if ( success ) {
bufferLength = static_cast<int>( value );
}
value = GetDlgItemInt( hwnd, IDC_WASAPI_LEADIN, &success, FALSE );
if ( success ) {
leadIn = static_cast<int>( value );
}
m_Settings.SetAdvancedWasapiExclusiveSettings( useDeviceDefaultFormat, bufferLength, leadIn );
}
void DlgAdvancedWasapi::ResetToDefaults( const HWND hwnd )
{
bool useDeviceDefaultFormat = false;
int bufferLength = 0;
int leadIn = 0;
int maxBufferLength = 0;
int maxLeadIn = 0;
m_Settings.GetDefaultAdvancedWasapiExclusiveSettings( useDeviceDefaultFormat, bufferLength, leadIn, maxBufferLength, maxLeadIn );
SetDlgItemInt( hwnd, IDC_WASAPI_BUFFERLENGTH, static_cast<UINT>( bufferLength ), TRUE /*signed*/ );
SetDlgItemInt( hwnd, IDC_WASAPI_LEADIN, static_cast<UINT>( leadIn ), TRUE /*signed*/ );
CheckRadioButton( hwnd, IDC_WASAPI_OUTPUT_DEFAULT, IDC_WASAPI_OUTPUT_SOURCE,
useDeviceDefaultFormat ? IDC_WASAPI_OUTPUT_DEFAULT : IDC_WASAPI_OUTPUT_SOURCE );
}