#include #include #include #include #include #include "resource.h" #include "ISoundTouch.h" #include "stchprop.h" CUnknown * WINAPI CSoundTouchProperties::CreateInstance(LPUNKNOWN lpunk, HRESULT *phr) { //ASSERT(phr); CUnknown *punk = new CSoundTouchProperties(lpunk, phr); if (punk == NULL) { if (phr) *phr = E_OUTOFMEMORY; } return punk; } // CreateInstance CSoundTouchProperties::CSoundTouchProperties(LPUNKNOWN lpunk, HRESULT *phr) : CBasePropertyPage(NAME("SoundTouch Property Page"), lpunk, IDD_GARGPROP, IDS_NAME) { m_pSoundTouch = NULL; } // // ConvertToPosition // int ConvertToPosition(int f) { return -f+12; } // ConvertToPosition // // ConvertToSemiTone // int ConvertToSemiTone(int p) { return -p+12; } // ConvertToSemiTone // // OnReceiveMessage // // Override CBasePropertyPage method. // Handle windows messages for the dialog of the property sheet. // INT_PTR CSoundTouchProperties::OnReceiveMessage(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { UNREFERENCED_PARAMETER(lParam); switch (uMsg) { case WM_INITDIALOG: m_hwnd = hwnd; m_hwndSlider = CreateSlider(hwnd); //ASSERT(m_hwndSlider); return TRUE; // I don't call setfocus... case WM_VSCROLL: //ASSERT(m_hwndSlider); OnSliderNotification(wParam, hwnd); return TRUE; case WM_COMMAND: if (0){ // Should not occur - debug! // TCHAR Buff[100]; (void)StringCchPrintf(Buff, NUMELMS(Buff), TEXT("wParam=%08x\0"), wParam); #ifdef DEBUG //DbgBreakPoint( Buff, TEXT(__FILE__), __LINE__ ); #else //ASSERT(!"Should not occur - debug!"); #endif } return TRUE; case WM_DESTROY: DestroyWindow(m_hwndSlider); return TRUE; default: return FALSE; } // switch } // OnReceiveMessage // // OnConnect // // Override CBasePropertyPage method. // Get the interface to the filter. // Set the member variables m_iGargleRate and m_iGargleShape. // HRESULT CSoundTouchProperties::OnConnect(IUnknown * punk) { // Get ISoundTouch interface // if (punk == NULL) { DbgBreak("You can't call OnConnect with a NULL pointer!!"); return(E_POINTER); } //ASSERT(m_pSoundTouch == NULL); HRESULT hr = punk->QueryInterface(IID_ISoundTouch, (void **) &m_pSoundTouch); if (FAILED(hr)) { DbgBreak("Can't get ISoundTouch interface!"); return E_NOINTERFACE; } CheckPointer(m_pSoundTouch,E_FAIL); m_pSoundTouch->get_TouchKey(&m_iTouchRate); SetDlgItemInt( m_hwnd, IDC_EDIT1, m_iTouchRate, TRUE ); return NOERROR; } // OnConnect // // OnDisconnect // // Override CBasePropertyPage method. // Release the private interface. // HRESULT CSoundTouchProperties::OnDisconnect() { // // Release the interface // if (!m_pSoundTouch) return E_UNEXPECTED; m_pSoundTouch->Release(); m_pSoundTouch = NULL; return(NOERROR); } // OnDisconnect // // OnDeactivate // // Destroy the dialog. // HRESULT CSoundTouchProperties::OnDeactivate(void) { //ASSERT(m_pSoundTouch); // // Remember the SoundTouch Rate and shape for the next Activate() call // m_pSoundTouch->get_TouchKey(&m_iTouchRate); SetDlgItemInt( m_hwnd, IDC_EDIT1, m_iTouchRate, TRUE ); return NOERROR; } // OnDeactivate // // CreateSlider // // Create the slider (common control) to allow the user to // adjust the gargling rate. // HWND CSoundTouchProperties::CreateSlider(HWND hwndParent) { // Find how to convert dialog units to screen units // LONG XUnit = GetDialogBaseUnits(); LONG YUnit = XUnit>>16; XUnit = XUnit & 0x0000ffff; // Create the slider child window at a position which fits the dialog // HWND hwndSlider = CreateWindow( TRACKBAR_CLASS , TEXT("") , WS_CHILD | WS_VISIBLE | TBS_VERT | TBS_BOTH , 2*XUnit // x , 1*YUnit // y , 5*XUnit // width , 5*YUnit // Height , hwndParent , NULL // menu , g_hInst , NULL // CLIENTCREATESTRUCT ); if (hwndSlider == NULL) { DbgLog((LOG_ERROR, 1, TEXT("Could not create window. error code: 0x%x"), GetLastError())); return NULL; } SendMessage(hwndSlider, TBM_SETRANGE, TRUE, MAKELONG(0, 12*2) ); SendMessage(hwndSlider, TBM_SETTIC, 0, 12L); int iPos = ConvertToPosition(m_iTouchRate); SendMessage(hwndSlider, TBM_SETPOS, TRUE, iPos); SetDlgItemInt( m_hwnd, IDC_EDIT1, m_iTouchRate, TRUE ); return hwndSlider; } // CreateSlider // // OnSliderNotification // // Handle the notification meesages from the slider control // void CSoundTouchProperties::OnSliderNotification(WPARAM wParam, HWND hwnd) { int iPos; switch (wParam) { case TB_BOTTOM: iPos = ConvertToPosition(MinSoundTouchRate); SendMessage(m_hwndSlider, TBM_SETPOS, TRUE, (LPARAM) iPos); break; case TB_TOP: iPos = ConvertToPosition(MaxSoundTouchRate); SendMessage(m_hwndSlider, TBM_SETPOS, TRUE, (LPARAM) iPos); break; case TB_PAGEDOWN: case TB_PAGEUP: break; case TB_THUMBPOSITION: case TB_ENDTRACK: { int iRate = (int) SendMessage(m_hwndSlider, TBM_GETPOS, 0, 0L); iRate = ConvertToSemiTone(iRate); m_pSoundTouch->put_TouchKey( iRate ); SetDlgItemInt( hwnd, IDC_EDIT1, iRate, TRUE ); break; } case TB_THUMBTRACK: // default handling of these messages is ok. case TB_LINEDOWN: case TB_LINEUP: break; } } // OnSliderNotification