2 * Controller.cpp - Media Player for the Haiku Operating System
4 * Copyright (C) 2006 Marcus Overhagen <marcus@overhagen.de>
5 * Copyright (C) 2007 Stephan Aßmus <superstippi@gmx.de>
6 * Copyright (C) 2008-2009 Fredrik Modéen <[FirstName]@[LastName].se> (MIT ok)
8 * Released under the terms of the MIT license.
12 #include "ControllerView.h"
19 #include "Controller.h"
21 #include "PlaylistObserver.h"
24 ControllerView::ControllerView(BRect frame
, Controller
* controller
,
27 TransportControlGroup(frame
, true, true, false),
28 fController(controller
),
30 fPlaylistObserver(new PlaylistObserver(this))
32 fPlaylist
->AddListener(fPlaylistObserver
);
36 ControllerView::~ControllerView()
38 fPlaylist
->RemoveListener(fPlaylistObserver
);
39 delete fPlaylistObserver
;
44 ControllerView::AttachedToWindow()
46 TransportControlGroup::AttachedToWindow();
51 ControllerView::Draw(BRect updateRect
)
53 TransportControlGroup::Draw(updateRect
);
58 ControllerView::MessageReceived(BMessage
* message
)
60 switch (message
->what
) {
61 case MSG_PLAYLIST_ITEM_ADDED
:
62 case MSG_PLAYLIST_ITEM_REMOVED
:
63 case MSG_PLAYLIST_ITEMS_SORTED
:
64 case MSG_PLAYLIST_CURRENT_ITEM_CHANGED
:
68 case MSG_PLAYLIST_IMPORT_FAILED
:
72 TransportControlGroup::MessageReceived(message
);
81 ControllerView::TogglePlaying()
83 BAutolock
_(fPlaylist
);
84 if (fPlaylist
->CurrentItemIndex() == fPlaylist
->CountItems() - 1
85 && Position() == 1.0) {
86 // Reached end of playlist and end of last item
87 // -> start again from the first item.
88 fPlaylist
->SetCurrentItemIndex(0, true);
90 fController
->TogglePlaying();
95 ControllerView::Stop()
102 ControllerView::Rewind()
104 // TODO: make it so this function is called repeatedly
105 //printf("ControllerView::Rewind()\n");
110 ControllerView::Forward()
112 // TODO: make it so this function is called repeatedly
113 //printf("ControllerView::Forward()\n");
118 ControllerView::SkipBackward()
120 BAutolock
_(fPlaylist
);
121 int32 index
= fPlaylist
->CurrentItemIndex() - 1;
124 fPlaylist
->SetCurrentItemIndex(index
, true);
129 ControllerView::SkipForward()
131 BAutolock
_(fPlaylist
);
132 int32 index
= fPlaylist
->CurrentItemIndex() + 1;
133 if (index
>= fPlaylist
->CountItems())
134 index
= fPlaylist
->CountItems() - 1;
135 fPlaylist
->SetCurrentItemIndex(index
, true);
140 ControllerView::VolumeChanged(float value
)
142 fController
->SetVolume(value
);
147 ControllerView::ToggleMute()
149 fController
->ToggleMute();
154 ControllerView::PositionChanged(float value
)
157 fController
->SetPosition(value
);
165 ControllerView::_CheckSkippable()
167 BAutolock
_(fPlaylist
);
169 bool canSkipNext
, canSkipPrevious
;
170 fPlaylist
->GetSkipInfo(&canSkipPrevious
, &canSkipNext
);
171 SetSkippable(canSkipPrevious
, canSkipNext
);