From 39f36757110ccd684824f72fb9930eb9bcc7e070 Mon Sep 17 00:00:00 2001 From: Lucas Murray Date: Sun, 10 Mar 2013 17:54:54 +0800 Subject: [PATCH] Added the beginning of a configuration dialog to the noise gate plugin --- NoiseGate/NoiseGate.cpp | 85 +++++++++++++++++++++++++++++ NoiseGate/NoiseGate.h | 43 +++++++++++++++ NoiseGate/NoiseGate.rc | 43 +++++++++++++++ NoiseGate/NoiseGate.vcxproj | 4 ++ NoiseGate/NoiseGate.vcxproj.filters | 8 +++ NoiseGate/resource.h | 14 +++++ rundir/locale/en.txt | 9 +++ 7 files changed, 206 insertions(+) create mode 100644 NoiseGate/NoiseGate.rc create mode 100644 NoiseGate/resource.h diff --git a/NoiseGate/NoiseGate.cpp b/NoiseGate/NoiseGate.cpp index 78696a25..f701b337 100644 --- a/NoiseGate/NoiseGate.cpp +++ b/NoiseGate/NoiseGate.cpp @@ -17,6 +17,7 @@ ********************************************************************************/ #include "NoiseGate.h" +#include "resource.h" //============================================================================ // NoiseGateFilter class @@ -97,6 +98,77 @@ void NoiseGateFilter::ApplyNoiseGate(float *buffer, int totalFloats) } } +//============================================================================ +// NoiseGateConfigWindow class + +NoiseGateConfigWindow::NoiseGateConfigWindow(NoiseGate *parent, HWND parentHwnd) + : parent(parent) + , parentHwnd(parentHwnd) + , hwnd(NULL) +{ +} + +NoiseGateConfigWindow::~NoiseGateConfigWindow() +{ +} + +INT_PTR CALLBACK NoiseGateConfigWindow::DialogProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + // Get the pointer to our class instance + NoiseGateConfigWindow *window = (NoiseGateConfigWindow *)GetWindowLongPtr(hwnd, DWLP_USER); + + switch(message) + { + default: + // Unhandled + break; + case WM_INITDIALOG: + SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR)lParam); + window = (NoiseGateConfigWindow *)lParam; + window->hwnd = hwnd; + window->MsgInitDialog(); + return TRUE; + case WM_COMMAND: + if(window != NULL) + return window->MsgCommand(wParam, lParam); + break; + } + + return FALSE; +} + +/** + * Display the dialog and begin its message loop. Returns \t{true} if the + * user clicked the "OK" button. + */ +bool NoiseGateConfigWindow::Process() +{ + INT_PTR res = DialogBoxParam(parent->hinstDLL, MAKEINTRESOURCE(IDD_CONFIGURENOISEGATE), parentHwnd, (DLGPROC)DialogProc, (LPARAM)this); + if(res == IDOK) + return true; + return false; +} + +void NoiseGateConfigWindow::MsgInitDialog() +{ + LocalizeWindow(hwnd); +} + +INT_PTR NoiseGateConfigWindow::MsgCommand(WPARAM wParam, LPARAM lParam) +{ + switch(LOWORD(wParam)) + { + case IDOK: + EndDialog(hwnd, LOWORD(wParam)); // Return IDOK (1) + return TRUE; + case IDCANCEL: + EndDialog(hwnd, LOWORD(wParam)); // Return IDCANCEL (2) + return TRUE; + } + + return FALSE; +} + //============================================================================ // NoiseGate class @@ -140,6 +212,12 @@ void NoiseGate::StreamStopped() micSource = NULL; } +void NoiseGate::ShowConfigDialog(HWND parentHwnd) +{ + NoiseGateConfigWindow dialog(this, parentHwnd); + dialog.Process(); +} + //============================================================================ // Plugin entry points @@ -159,6 +237,13 @@ void UnloadPlugin() NoiseGate::instance = NULL; } +void ConfigPlugin(HWND parentHwnd) +{ + if(NoiseGate::instance == NULL) + return; + NoiseGate::instance->ShowConfigDialog(parentHwnd); +} + void OnStartStream() { if(NoiseGate::instance == NULL) diff --git a/NoiseGate/NoiseGate.h b/NoiseGate/NoiseGate.h index 37264aba..b73d14f8 100644 --- a/NoiseGate/NoiseGate.h +++ b/NoiseGate/NoiseGate.h @@ -56,12 +56,53 @@ private: void ApplyNoiseGate(float *buffer, int totalFloats); }; +//============================================================================ +// NoiseGateConfigWindow class + +class NoiseGateConfigWindow +{ + //----------------------------------------------------------------------- + // Private members + +private: + NoiseGate * parent; + HWND parentHwnd; + HWND hwnd; + + //----------------------------------------------------------------------- + // Static methods + +public: + static INT_PTR CALLBACK DialogProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); + + //----------------------------------------------------------------------- + // Constructor/destructor + +public: + NoiseGateConfigWindow(NoiseGate *parent, HWND parentHwnd); + ~NoiseGateConfigWindow(); + + //----------------------------------------------------------------------- + // Methods + +public: + bool Process(); + + //----------------------------------------------------------------------- + // Message processing + +private: + void MsgInitDialog(); + INT_PTR MsgCommand(WPARAM wParam, LPARAM lParam); +}; + //============================================================================ // NoiseGate class class NoiseGate { friend class NoiseGateFilter; + friend class NoiseGateConfigWindow; //----------------------------------------------------------------------- // Static members @@ -97,6 +138,7 @@ public: public: void StreamStarted(); void StreamStopped(); + void ShowConfigDialog(HWND parentHwnd); }; //============================================================================ @@ -104,6 +146,7 @@ public: extern "C" __declspec(dllexport) bool LoadPlugin(); extern "C" __declspec(dllexport) void UnloadPlugin(); +extern "C" __declspec(dllexport) void ConfigPlugin(HWND parentHwnd); extern "C" __declspec(dllexport) void OnStartStream(); extern "C" __declspec(dllexport) void OnStopStream(); extern "C" __declspec(dllexport) CTSTR GetPluginName(); diff --git a/NoiseGate/NoiseGate.rc b/NoiseGate/NoiseGate.rc new file mode 100644 index 00000000..c874c29f --- /dev/null +++ b/NoiseGate/NoiseGate.rc @@ -0,0 +1,43 @@ +// Generated by ResEdit 1.5.11 +// Copyright (C) 2006-2012 +// http://www.resedit.net + +#include "winres.h" +#include "commctrl.h" +#include "resource.h" + + + + +// +// Dialog resources +// +LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL +IDD_CONFIGURENOISEGATE DIALOG 0, 0, 357, 282 +STYLE DS_3DLOOK | DS_CENTER | DS_MODALFRAME | DS_SHELLFONT | WS_CAPTION | WS_VISIBLE | WS_POPUP | WS_SYSMENU +CAPTION "Plugins.NoiseGate.ConfigureTitle" +FONT 8, "Ms Shell Dlg" +{ + DEFPUSHBUTTON "OK", IDOK, 232, 257, 50, 14 + PUSHBUTTON "Cancel", IDCANCEL, 292, 257, 50, 14 + CONTROL "", IDC_OPENTHRES_SLIDER, TRACKBAR_CLASS, WS_TABSTOP | TBS_VERT | TBS_BOTH | TBS_NOTICKS, 287, 37, 20, 145 + CONTROL "", IDC_CLOSETHRES_SLIDER, TRACKBAR_CLASS, WS_TABSTOP | TBS_VERT | TBS_BOTH | TBS_NOTICKS, 267, 37, 20, 145 + CONTROL "", IDC_CURVOL, PROGRESS_CLASS, PBS_VERTICAL, 307, 42, 15, 135 + PUSHBUTTON "Plugins.NoiseGate.EnablePreview", IDC_PREVIEWON, 22, 26, 80, 14 + GROUPBOX "Plugins.NoiseGate.Settings", IDC_STATIC, 25, 90, 145, 115 + RTEXT "Plugins.NoiseGate.OpenThreshold", IDC_STATIC, 30, 107, 70, 8, SS_RIGHT + RTEXT "Plugins.NoiseGate.CloseThreshold", IDC_STATIC, 30, 127, 70, 8, SS_RIGHT + RTEXT "Plugins.NoiseGate.AttackTime", IDC_STATIC, 30, 147, 70, 8, SS_RIGHT + RTEXT "Plugins.NoiseGate.HoldTime", IDC_STATIC, 30, 167, 70, 8, SS_RIGHT + RTEXT "Plugins.NoiseGate.ReleaseTime", IDC_STATIC, 30, 187, 70, 8, SS_RIGHT + EDITTEXT IDC_CLOSETHRES_EDIT, 102, 122, 40, 14, ES_AUTOHSCROLL + EDITTEXT IDC_ATTACKTIME_EDIT, 102, 142, 40, 14, ES_AUTOHSCROLL + EDITTEXT IDC_HOLDTIME_EDIT, 102, 162, 40, 14, ES_AUTOHSCROLL + EDITTEXT IDC_RELEASETIME_EDIT, 102, 182, 40, 14, ES_AUTOHSCROLL + LTEXT "ms", IDC_STATIC, 147, 187, 10, 8, SS_LEFT + LTEXT "ms", IDC_STATIC, 147, 167, 10, 8, SS_LEFT + LTEXT "ms", IDC_STATIC, 147, 147, 10, 8, SS_LEFT + LTEXT "dB", IDC_STATIC, 147, 107, 10, 8, SS_LEFT + LTEXT "dB", IDC_STATIC, 147, 127, 10, 8, SS_LEFT + EDITTEXT IDC_OPENTHRES_EDIT, 102, 102, 40, 14, ES_AUTOHSCROLL +} diff --git a/NoiseGate/NoiseGate.vcxproj b/NoiseGate/NoiseGate.vcxproj index 5bd1e21e..ad1e031f 100644 --- a/NoiseGate/NoiseGate.vcxproj +++ b/NoiseGate/NoiseGate.vcxproj @@ -215,6 +215,7 @@ + @@ -222,6 +223,9 @@ false + + + diff --git a/NoiseGate/NoiseGate.vcxproj.filters b/NoiseGate/NoiseGate.vcxproj.filters index 0d9f26b2..0bad6177 100644 --- a/NoiseGate/NoiseGate.vcxproj.filters +++ b/NoiseGate/NoiseGate.vcxproj.filters @@ -23,5 +23,13 @@ Header Files + + Header Files + + + + + Resource Files + \ No newline at end of file diff --git a/NoiseGate/resource.h b/NoiseGate/resource.h new file mode 100644 index 00000000..d4f84720 --- /dev/null +++ b/NoiseGate/resource.h @@ -0,0 +1,14 @@ +#ifndef IDC_STATIC +#define IDC_STATIC (-1) +#endif + +#define IDD_CONFIGURENOISEGATE 101 +#define IDC_CURVOL 1007 +#define IDC_PREVIEWON 1010 +#define IDC_OPENTHRES_EDIT 1016 +#define IDC_CLOSETHRES_SLIDER 1018 +#define IDC_OPENTHRES_SLIDER 1019 +#define IDC_CLOSETHRES_EDIT 1020 +#define IDC_RELEASETIME_EDIT 1024 +#define IDC_HOLDTIME_EDIT 1025 +#define IDC_ATTACKTIME_EDIT 1026 diff --git a/rundir/locale/en.txt b/rundir/locale/en.txt index 6bb21079..1b059cac 100644 --- a/rundir/locale/en.txt +++ b/rundir/locale/en.txt @@ -288,3 +288,12 @@ Settings.Advanced.AutomaticLatency "Automatic low latency mode:" Plugins.NoiseGate.PluginName "Microphone Noise Gate" Plugins.NoiseGate.PluginDescription "Reduces microphone noise by automatically muting the microphone if you are not talking." +Plugins.NoiseGate.ConfigureTitle "Configure microphone noise gate" +Plugins.NoiseGate.EnablePreview "Enable preview" +Plugins.NoiseGate.DisablePreview "Disable preview" +Plugins.NoiseGate.Settings "Settings" +Plugins.NoiseGate.OpenThreshold "Open threshold:" +Plugins.NoiseGate.CloseThreshold "Close threshold:" +Plugins.NoiseGate.AttackTime "Attack time:" +Plugins.NoiseGate.HoldTime "Hold time:" +Plugins.NoiseGate.ReleaseTime "Release time:"