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 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 #include "ControllerView.h"
31 #include "Controller.h"
33 #include "PlaylistObserver.h"
36 ControllerView::ControllerView(BRect frame
, Controller
* controller
,
39 TransportControlGroup(frame
, true, true, false),
40 fController(controller
),
42 fPlaylistObserver(new PlaylistObserver(this))
44 fPlaylist
->AddListener(fPlaylistObserver
);
48 ControllerView::~ControllerView()
50 fPlaylist
->RemoveListener(fPlaylistObserver
);
51 delete fPlaylistObserver
;
56 ControllerView::AttachedToWindow()
58 TransportControlGroup::AttachedToWindow();
63 ControllerView::Draw(BRect updateRect
)
65 TransportControlGroup::Draw(updateRect
);
70 ControllerView::MessageReceived(BMessage
* message
)
72 switch (message
->what
) {
73 case MSG_PLAYLIST_ITEM_ADDED
:
74 case MSG_PLAYLIST_ITEM_REMOVED
:
75 case MSG_PLAYLIST_ITEMS_SORTED
:
76 case MSG_PLAYLIST_CURRENT_ITEM_CHANGED
:
80 case MSG_PLAYLIST_IMPORT_FAILED
:
84 TransportControlGroup::MessageReceived(message
);
93 ControllerView::TogglePlaying()
95 BAutolock
_(fPlaylist
);
96 if (fPlaylist
->CurrentItemIndex() == fPlaylist
->CountItems() - 1
97 && Position() == 1.0) {
98 // Reached end of playlist and end of last item
99 // -> start again from the first item.
100 fPlaylist
->SetCurrentItemIndex(0, true);
102 fController
->TogglePlaying();
107 ControllerView::Stop()
114 ControllerView::Rewind()
116 // TODO: make it so this function is called repeatedly
117 //printf("ControllerView::Rewind()\n");
122 ControllerView::Forward()
124 // TODO: make it so this function is called repeatedly
125 //printf("ControllerView::Forward()\n");
130 ControllerView::SkipBackward()
132 BAutolock
_(fPlaylist
);
133 int32 index
= fPlaylist
->CurrentItemIndex() - 1;
136 fPlaylist
->SetCurrentItemIndex(index
, true);
141 ControllerView::SkipForward()
143 BAutolock
_(fPlaylist
);
144 int32 index
= fPlaylist
->CurrentItemIndex() + 1;
145 if (index
>= fPlaylist
->CountItems())
146 index
= fPlaylist
->CountItems() - 1;
147 fPlaylist
->SetCurrentItemIndex(index
, true);
152 ControllerView::VolumeChanged(float value
)
154 fController
->SetVolume(value
);
159 ControllerView::ToggleMute()
161 fController
->ToggleMute();
166 ControllerView::PositionChanged(float value
)
169 fController
->SetPosition(value
);
177 ControllerView::_CheckSkippable()
179 BAutolock
_(fPlaylist
);
181 bool canSkipNext
, canSkipPrevious
;
182 fPlaylist
->GetSkipInfo(&canSkipPrevious
, &canSkipNext
);
183 SetSkippable(canSkipPrevious
, canSkipNext
);