[vlc-devel] [PATCH 2/6] win32: re-organize audio button/slider updating methods

Hugo Beauzée-Luyssen hugo at beauzee.fr
Wed Dec 16 10:06:52 CET 2015


On 12/15/2015 10:15 PM, Daniel Amm wrote:
> This is needed for the next commit
> ---
>   common/win32_fullscreen.cpp | 67 ++++++++++++++++++++-------------------------
>   common/win32_fullscreen.h   |  4 +--
>   2 files changed, 32 insertions(+), 39 deletions(-)
>
> diff --git a/common/win32_fullscreen.cpp b/common/win32_fullscreen.cpp
> index c801760..18768b3 100644
> --- a/common/win32_fullscreen.cpp
> +++ b/common/win32_fullscreen.cpp
> @@ -216,7 +216,13 @@ LRESULT VLCControlsWnd::WindowProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
>
>               CreateToolTip();
>               RegisterToVLCEvents();
> -            SyncVolumeSliderWithVLCVolume();
> +
> +            if( VP() ){
> +                vlc_player& vp = *VP();

Why not fetching the pointer once and compare it against nullptr instead 
of fetching twice and using a reference afterward?
I doubt if makes any difference once compiled, though if feels more 
natural as far as I'm concerned

> +                UpdateVolumeSlider( vp.get_mp().volume() );
> +                UpdateMuteButton( vp.get_mp().mute() );
> +            }
> +
>               break;
>           }
>           case WM_LBUTTONUP:{
> @@ -269,8 +275,9 @@ LRESULT VLCControlsWnd::WindowProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
>                           }
>                           case ID_FS_MUTE:{
>                               if( VP() ){
> -                                VP()->get_mp().setMute( IsDlgButtonChecked(hWnd(), ID_FS_MUTE) != FALSE );
> -                                SyncVolumeSliderWithVLCVolume();
> +                                bool newMutedState = IsDlgButtonChecked(hWnd(), ID_FS_MUTE) != FALSE;
> +                                VP()->get_mp().setMute( newMutedState );
> +                                UpdateMuteButton( newMutedState );
>                               }
>                               break;
>                           }
> @@ -369,10 +376,11 @@ LRESULT VLCControlsWnd::WindowProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
>           }
>           case WM_HSCROLL:
>           case WM_VSCROLL: {
> -            if( VP() ){
> -                if(hVolumeSlider==(HWND)lParam){
> +            if( hVolumeSlider == (HWND)lParam ){
> +                if( VP() ){
> +                    vlc_player& vp = *VP();
>                       LRESULT SliderPos = SendMessage(hVolumeSlider, (UINT) TBM_GETPOS, 0, 0);
> -                    SetVLCVolumeBySliderPos(SliderPos);
> +                    vp.get_mp().setVolume( SliderPos );
>                   }
>               }
>               break;
> @@ -433,44 +441,29 @@ void VLCControlsWnd::SetVideoPos(float Pos) //0-start, 1-end
>       }
>   }
>
> -void VLCControlsWnd::SyncVolumeSliderWithVLCVolume()
> +void VLCControlsWnd::UpdateVolumeSlider(unsigned int vol)
>   {
> -    if( VP() ){
> -        vlc_player& vp = *VP();
> -        unsigned int vol = vp.get_mp().volume();
> -        const LRESULT SliderPos = SendMessage(hVolumeSlider, (UINT) TBM_GETPOS, 0, 0);
> -        if((UINT)SliderPos!=vol)
> -            PostMessage(hVolumeSlider, (UINT) TBM_SETPOS, (WPARAM) TRUE, (LPARAM) vol);
> -
> -        bool muted = vp.get_mp().mute();
> -        int MuteButtonState = SendMessage(hMuteButton, (UINT) BM_GETCHECK, 0, 0);
> -        if((muted&&(BST_UNCHECKED==MuteButtonState))||(!muted&&(BST_CHECKED==MuteButtonState))){
> -            PostMessage(hMuteButton, BM_SETCHECK, (WPARAM)(muted?BST_CHECKED:BST_UNCHECKED), 0);
> -        }
> -        LRESULT lResult = SendMessage(hMuteButton, BM_GETIMAGE, (WPARAM)IMAGE_BITMAP, 0);
> -        if( (muted && ((HANDLE)lResult == RC().hVolumeBitmap)) ||
> -            (!muted&&((HANDLE)lResult == RC().hVolumeMutedBitmap)) )
> -        {
> -            HANDLE hBmp = muted ? RC().hVolumeMutedBitmap : RC().hVolumeBitmap ;
> -            PostMessage(hMuteButton, BM_SETIMAGE,
> -                        (WPARAM)IMAGE_BITMAP, (LPARAM)hBmp);
> -        }
> -    }
> +    const LRESULT SliderPos = SendMessage(hVolumeSlider, (UINT) TBM_GETPOS, 0, 0);
> +    if( (UINT)SliderPos != vol )
> +        PostMessage(hVolumeSlider, (UINT) TBM_SETPOS, (WPARAM) TRUE, (LPARAM) vol);
>   }
>
> -void VLCControlsWnd::SetVLCVolumeBySliderPos(int CurPos)
> +void VLCControlsWnd::UpdateMuteButton(bool muted)
>   {
> -    if( VP() ){
> -        vlc_player& vp = *VP();
> -        vp.get_mp().setVolume( CurPos );
> -        if(0==CurPos){
> -            vp.get_mp().setMute( IsDlgButtonChecked( hWnd(), ID_FS_MUTE) != FALSE );
> -        }
> -        SyncVolumeSliderWithVLCVolume();
> +    int MuteButtonState = SendMessage(hMuteButton, (UINT) BM_GETCHECK, 0, 0);
> +    if((muted&&(BST_UNCHECKED==MuteButtonState))||(!muted&&(BST_CHECKED==MuteButtonState))){
> +        PostMessage(hMuteButton, BM_SETCHECK, (WPARAM)(muted?BST_CHECKED:BST_UNCHECKED), 0);
> +    }
> +    LRESULT lResult = SendMessage(hMuteButton, BM_GETIMAGE, (WPARAM)IMAGE_BITMAP, 0);
> +    if( (muted && ((HANDLE)lResult == RC().hVolumeBitmap)) ||
> +        (!muted&&((HANDLE)lResult == RC().hVolumeMutedBitmap)) )
> +    {
> +        HANDLE hBmp = muted ? RC().hVolumeMutedBitmap : RC().hVolumeBitmap ;
> +        PostMessage(hMuteButton, BM_SETIMAGE,
> +             (WPARAM)IMAGE_BITMAP, (LPARAM)hBmp);
>       }
>   }
>
> -
>   void VLCControlsWnd::UpdateFullscreenButton(bool fullscreen)
>   {
>       if (fullscreen)
> diff --git a/common/win32_fullscreen.h b/common/win32_fullscreen.h
> index c1ff55e..1bd65be 100644
> --- a/common/win32_fullscreen.h
> +++ b/common/win32_fullscreen.h
> @@ -107,8 +107,8 @@ protected:
>   private:
>       void SetVideoPos(float Pos); //0-start, 1-end
>
> -    void SyncVolumeSliderWithVLCVolume();
> -    void SetVLCVolumeBySliderPos(int CurScrollPos);
> +    void UpdateVolumeSlider(unsigned int vol);
> +    void UpdateMuteButton(bool muted);
>       void RegisterToVLCEvents();
>
>       void NeedHideControls();
>



More information about the vlc-devel mailing list