[haiku-development] Re: One More fix , MediaPlayer

  • From: Fredrik Modéen <fredrik@xxxxxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Wed, 17 Oct 2007 09:26:34 +0200 (CEST)

One more try..

> On Tuesday 16 October 2007 08.56.08 Fredrik Modéen wrote:
>> Hi I have one more fix.
>>
>> I have only tested with mp3's
>>
>> Mediaplayer
>> - Mute with speaker button works
>> - arrow keys works , left/right - skip forward/ skip back, up/down -
>> higher/ lower sound
>> - Settings options in menu mark's the selected menu item.
>>
>
> Hi
> Nice features!
> There are IMO some issues with the patch:
> * There is debug output left
> * If statements violates the coding guidelines
> * Some lines are too long
> * Strange semantics/naming with the toggle mute feature, see below
>
> Index: ControllerView.cpp
> ================================================================== void
>  ControllerView::ToggleMute()
>  {
> -     printf("ControllerView::ToggleMute()\n");
> +     fController->Mute();
>  }
>
> Index: Controller.cpp
> ==================================================================+void
> +Controller::Mute()
> +{
> +     if(fMuted)
> +             fVolume = fVolumeOld;
> +     else
> +     {
> +             fVolumeOld = fVolume;
> +             fVolume = 0.0;
> +     }
> +     printf("Controller::Mute %.4f\n", fVolume);
> +     fMuted = !fMuted;
> +     SetVolume(fVolume);
> +}
> +
> +
>
> The function Controller::Mute() does infact toggle the "mute mode" even
> though
> it says Mute. A couple of options are:
> Name the function ToggleMute()
> Have an argument, Mute(bool)
> Use two functions, Mute() and Unmute()
>
> /Fredrik Ekdahl
>
>


-- 
MVH
Fredrik Modéen
Index: ControllerView.cpp
===================================================================
--- ControllerView.cpp  (revision 22593)
+++ ControllerView.cpp  (working copy)
@@ -144,7 +145,7 @@
 void
 ControllerView::ToggleMute()
 {
-       printf("ControllerView::ToggleMute()\n");
+       fController->ToggleMute();
 }
 
 
Index: Controller.cpp
===================================================================
--- Controller.cpp      (revision 22593)
+++ Controller.cpp      (working copy)
@@ -127,6 +128,7 @@
  ,     fCurrentBitmap(NULL)
  ,     fBitmapLock("bitmap lock")
  ,     fListeners(4)
+ ,     fMuted(false)
 {
        for (int i = 0; i < MAX_AUDIO_BUFFERS; i++) {
                fAudioBuffer[i].bitmap = NULL;
@@ -501,7 +503,38 @@
        }
 }
 
+void
+Controller::VolumeUp()
+{
+       float f = Volume()+ 0.05;
+       if(f < 1.8){
+               SetVolume(f);
+       }
+}
 
+void
+Controller::VolumeDown()
+{
+       float f = Volume()-0.05;
+       if(f > -0.05){
+               SetVolume(f);
+       }
+}
+
+void
+Controller::ToggleMute()
+{      
+       if(fMuted){
+               fVolume = fVolumeOld;
+       }else{
+               fVolumeOld = fVolume;
+               fVolume = 0.0;
+       }
+       fMuted = !fMuted;
+       SetVolume(fVolume);
+}
+
+
 float
 Controller::Volume() const
 {
Index: MainWin.cpp
===================================================================
--- MainWin.cpp (revision 22593)
+++ MainWin.cpp (working copy)
@@ -167,8 +168,7 @@
 
        // setup the playlist window now, we need to have it 
        // running for the undo/redo playlist editing
-       fPlaylistWindow = new PlaylistWindow(BRect(150, 150, 400, 500),
-               fPlaylist, fController);
+       fPlaylistWindow = new PlaylistWindow(BRect(150, 150, 400, 500), 
fPlaylist, fController);
        fPlaylistWindow->Hide();
        fPlaylistWindow->Show();
                // this makes sure the window thread is running without
@@ -314,6 +314,7 @@
 void
 MainWin::MessageReceived(BMessage *msg)
 {
+//     msg->PrintToStream();
        switch (msg->what) {
                case B_REFS_RECEIVED:
                        printf("MainWin::MessageReceived: B_REFS_RECEIVED\n");
@@ -436,33 +437,34 @@
 
                case M_TOGGLE_FULLSCREEN:
                        _ToggleFullscreen();
-//                     fSettingsMenu->ItemAt(1)->SetMarked(fIsFullscreen);
+                       
(fSettingsMenu->FindItem(M_TOGGLE_FULLSCREEN))->SetMarked(fIsFullscreen);
                        break;
 
                case M_TOGGLE_NO_MENU:
                        _ToggleNoMenu();
-//                     fSettingsMenu->ItemAt(3)->SetMarked(fNoMenu);
+                       
(fSettingsMenu->FindItem(M_TOGGLE_NO_MENU))->SetMarked(fNoMenu);
                        break;
                        
                case M_TOGGLE_NO_CONTROLS:
                        _ToggleNoControls();
-//                     fSettingsMenu->ItemAt(3)->SetMarked(fNoControls);
+                       
(fSettingsMenu->FindItem(M_TOGGLE_NO_CONTROLS))->SetMarked(fNoControls);
                        break;
                
                case M_TOGGLE_NO_BORDER:
                        _ToggleNoBorder();
-//                     fSettingsMenu->ItemAt(4)->SetMarked(fNoBorder);
+                       
(fSettingsMenu->FindItem(M_TOGGLE_NO_BORDER))->SetMarked(fNoBorder);
                        break;
                        
                case M_TOGGLE_ALWAYS_ON_TOP:
                        _ToggleAlwaysOnTop();
-//                     fSettingsMenu->ItemAt(5)->SetMarked(fAlwaysOnTop);
+                       
(fSettingsMenu->FindItem(M_TOGGLE_ALWAYS_ON_TOP))->SetMarked(fAlwaysOnTop);
                        break;
        
-               case M_TOGGLE_KEEP_ASPECT_RATIO:
+               case M_TOGGLE_KEEP_ASPECT_RATIO:{
                        _ToggleKeepAspectRatio();
-//                     fSettingsMenu->ItemAt(6)->SetMarked(fKeepAspectRatio);
-                       break;
+                       BMenuItem* bitem = 
fSettingsMenu->FindItem(M_TOGGLE_KEEP_ASPECT_RATIO);
+                       bitem->SetMarked(fKeepAspectRatio);
+               }break;
 
                case M_TOGGLE_NO_BORDER_NO_MENU_NO_CONTROLS:
                        _ToggleNoBorderNoMenu();
@@ -532,41 +534,22 @@
                        if (dy < -0.1)  PostMessage(inv ? M_CHANNEL_NEXT : 
M_VOLUME_UP);
                        break;
                }
-
+*/
                case M_CHANNEL_NEXT:
-               {
-                       printf("M_CHANNEL_NEXT\n");
-                       int chan = fController->CurrentChannel();
-                       if (chan != -1) {
-                               chan++;
-                               if (chan < fController->ChannelCount())
-                                       SelectChannel(chan);
-                       }
+                       fControls->SkipForward();
                        break;
-               }
 
                case M_CHANNEL_PREV:
-               {
-                       printf("M_CHANNEL_PREV\n");
-                       int chan = fController->CurrentChannel();
-                       if (chan != -1) {
-                               chan--;
-                               if (chan >= 0)
-                                       SelectChannel(chan);
-                       }
+                       fControls->SkipBackward();
                        break;
-               }
 
                case M_VOLUME_UP:
-                       printf("M_VOLUME_UP\n");
                        fController->VolumeUp();
                        break;
 
                case M_VOLUME_DOWN:
-                       printf("M_VOLUME_DOWN\n");
                        fController->VolumeDown();
                        break;
-*/
 
                case M_ASPECT_100000_1:
                        VideoFormatChange(fSourceWidth, fSourceHeight, 1.0, 
1.0);
Index: ControllerView.h
===================================================================
--- ControllerView.h    (revision 22593)
+++ ControllerView.h    (working copy)
@@ -35,11 +36,6 @@
                                                        Playlist* playlist);
                                                ~ControllerView();
                                        
-private:
-       void                            AttachedToWindow();
-       void                            MessageReceived(BMessage *msg);
-       void                            Draw(BRect updateRect);
-
        // TransportControlGroup interface
        virtual uint32          EnabledButtons();
        virtual void            TogglePlaying();
@@ -52,6 +48,11 @@
        virtual void            ToggleMute();
        virtual void            PositionChanged(float value);
 
+private:
+       void                            AttachedToWindow();
+       void                            MessageReceived(BMessage *msg);
+       void                            Draw(BRect updateRect);
+
        // ControllerView
                        void            CheckSkippable();
 
Index: Controller.h
===================================================================
--- Controller.h        (revision 22593)
+++ Controller.h        (working copy)
@@ -88,6 +89,9 @@
 
        void                                    SetVolume(float value);
        float                                   Volume() const;
+       void                                    VolumeUp();
+       void                                    VolumeDown();
+       void                                    ToggleMute();
        void                                    SetPosition(float value);
 
        bool                                    HasFile();
@@ -168,6 +172,8 @@
        volatile bool                   fPaused;
        volatile bool                   fStopped;
        float                                   fVolume;
+       float                                   fVolumeOld;
+       bool                                    fMuted;
 
        entry_ref                               fRef;
        BMediaFile *                    fMediaFile;

Other related posts: