X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3d0a1631ed1eff4c73e175c50ab2e606b720337f..dd9f8b6bb6935360a8271dc3e8749fb026b601a8:/src/msw/mediactrl_am.cpp diff --git a/src/msw/mediactrl_am.cpp b/src/msw/mediactrl_am.cpp index a719a05849..75acd4f99e 100644 --- a/src/msw/mediactrl_am.cpp +++ b/src/msw/mediactrl_am.cpp @@ -56,7 +56,7 @@ #pragma warning (disable:4310) #endif -#if wxUSE_MEDIACTRL +#if wxUSE_MEDIACTRL && wxUSE_ACTIVEX #include "wx/mediactrl.h" @@ -1483,6 +1483,7 @@ public: LPAMGETERRORTEXT m_lpAMGetErrorText; wxString GetErrorString(HRESULT hrdsv); #endif // __WXDEBUG__ + wxEvtHandler* m_evthandler; friend class wxAMMediaEvtHandler; DECLARE_DYNAMIC_CLASS(wxAMMediaBackend) @@ -1573,6 +1574,7 @@ wxAMMediaBackend::wxAMMediaBackend() #endif m_bestSize(wxDefaultSize) { + m_evthandler = NULL; } //--------------------------------------------------------------------------- @@ -1591,7 +1593,11 @@ wxAMMediaBackend::~wxAMMediaBackend() if (GetMP()) GetMP()->Release(); - m_ctrl->PopEventHandler(true); + if (m_evthandler) + { + m_ctrl->RemoveEventHandler(m_evthandler); + delete m_evthandler; + } } } @@ -1683,7 +1689,8 @@ bool wxAMMediaBackend::CreateControl(wxControl* ctrl, wxWindow* parent, #endif ); // Connect for events - m_ctrl->PushEventHandler(new wxAMMediaEvtHandler(this)); + m_evthandler = new wxAMMediaEvtHandler(this); + m_ctrl->PushEventHandler(m_evthandler); // // Here we set up wx-specific stuff for the default @@ -1949,12 +1956,12 @@ wxLongLong wxAMMediaBackend::GetPosition() } //--------------------------------------------------------------------------- -// wxAMMediaBackend::GetVolume +// wxAMMediaBackend::GetVolume and SetVolume() // -// Gets the volume through the IActiveMovie interface - -// value ranges from 0 (MAX volume) to -10000 (minimum volume). -// -100 per decibel (Logorithmic in 0.01db per step). +// Notice that for the IActiveMovie interface value ranges from 0 (MAX volume) +// to -10000 (minimum volume) and the scale is logarithmic in 0.01db per step. //--------------------------------------------------------------------------- + double wxAMMediaBackend::GetVolume() { long lVolume; @@ -1965,37 +1972,20 @@ double wxAMMediaBackend::GetVolume() return 0.0; } - // Volume conversion from Greg Hazel - double dVolume = (double)lVolume / 125; + double dVolume = lVolume / 2000.; // volume is now in [-5..0] range + dVolume = pow(10.0, dVolume); // [10^-5, 1] + dVolume -= 0.00001; // [0, 1-10^-5] + dVolume /= 1 - 0.00001; // [0, 1] - // convert to 0 to 1 - dVolume = pow(10.0, dVolume/20.0); - // handle -INF - dVolume *= 1 + pow(10.0, -5.0); - dVolume -= pow(10.0, -5.0); return dVolume; } -//--------------------------------------------------------------------------- -// wxAMMediaBackend::SetVolume -// -// Sets the volume through the IActiveMovie interface - -// value ranges from 0 (MAX volume) to -10000 (minimum volume). -// -100 per decibel (Logorithmic in 0.01db per step). -//--------------------------------------------------------------------------- bool wxAMMediaBackend::SetVolume(double dVolume) { - // Volume conversion from Greg Hazel - long lVolume; - // handle -INF - dVolume *= 1 - pow(10.0, -5.0); - dVolume += pow(10.0, -5.0); - // convert to -100db to 0db - dVolume = 20 * log10(dVolume); - // scale to -10000 to 0 - lVolume = (long)(125 * dVolume); - - HRESULT hr = GetAM()->put_Volume( lVolume ); + // inverse the transformation above + long lVolume = 2000*log10(dVolume + (1 - dVolume)*0.00001); + + HRESULT hr = GetAM()->put_Volume(lVolume); if(FAILED(hr)) { wxAMLOG(hr); @@ -2270,4 +2260,4 @@ void wxAMMediaEvtHandler::OnActiveX(wxActiveXEvent& event) #include "wx/html/forcelnk.h" FORCE_LINK_ME(wxmediabackend_am) -#endif // wxUSE_MEDIACTRL +#endif // wxUSE_MEDIACTRL && wxUSE_ACTIVEX