hrev43642 adds 1 changeset to branch 'master' old head: 174676503b2c345653f73de4915e8b247961a81a new head: a5a013ca40aa991d809cffb85a7367e67132ea0c ---------------------------------------------------------------------------- a5a013c: MediaPlayer: Fix movement of items in playlist In Playlist, whenever a move of items occured causing the currently playing song to change its position, so : 1. Importing files (D&D for example) before its position 2. Removings files before it 3. Moving files before it was causing the currently playing song to restart because it was thinking a new entry was asked (it had a different index number suddently). Also adjusted the behaviour when you delete the currently playing track. Should fix ticket #6689. [ Philippe Saint-Pierre <stpere@xxxxxxxxx> ] ---------------------------------------------------------------------------- Revision: hrev43642 Commit: a5a013ca40aa991d809cffb85a7367e67132ea0c URL: http://cgit.haiku-os.org/haiku/commit/?id=a5a013c Author: Philippe Saint-Pierre <stpere@xxxxxxxxx> Date: Sat Jan 7 22:24:37 2012 UTC Ticket: https://dev.haiku-os.org/ticket/6689 ---------------------------------------------------------------------------- 11 files changed, 30 insertions(+), 24 deletions(-) src/apps/mediaplayer/ControllerView.cpp | 6 ++-- src/apps/mediaplayer/MainWin.cpp | 4 +++ .../mediaplayer/playlist/CopyPLItemsCommand.cpp | 2 +- .../mediaplayer/playlist/ImportPLItemsCommand.cpp | 2 +- .../mediaplayer/playlist/MovePLItemsCommand.cpp | 4 +- src/apps/mediaplayer/playlist/Playlist.cpp | 20 ++++++++-------- src/apps/mediaplayer/playlist/Playlist.h | 7 +++-- src/apps/mediaplayer/playlist/PlaylistObserver.cpp | 3 +- src/apps/mediaplayer/playlist/PlaylistObserver.h | 2 +- .../playlist/RandomizePLItemsCommand.cpp | 2 +- .../mediaplayer/playlist/RemovePLItemsCommand.cpp | 2 +- ---------------------------------------------------------------------------- diff --git a/src/apps/mediaplayer/ControllerView.cpp b/src/apps/mediaplayer/ControllerView.cpp index f8e2987..f3b9176 100644 --- a/src/apps/mediaplayer/ControllerView.cpp +++ b/src/apps/mediaplayer/ControllerView.cpp @@ -105,7 +105,7 @@ ControllerView::TogglePlaying() && Position() == 1.0) { // Reached end of playlist and end of last item // -> start again from the first item. - fPlaylist->SetCurrentItemIndex(0); + fPlaylist->SetCurrentItemIndex(0, true); } else fController->TogglePlaying(); } @@ -141,7 +141,7 @@ ControllerView::SkipBackward() int32 index = fPlaylist->CurrentItemIndex() - 1; if (index < 0) index = 0; - fPlaylist->SetCurrentItemIndex(index); + fPlaylist->SetCurrentItemIndex(index, true); } @@ -152,7 +152,7 @@ ControllerView::SkipForward() int32 index = fPlaylist->CurrentItemIndex() + 1; if (index >= fPlaylist->CountItems()) index = fPlaylist->CountItems() - 1; - fPlaylist->SetCurrentItemIndex(index); + fPlaylist->SetCurrentItemIndex(index, true); } diff --git a/src/apps/mediaplayer/MainWin.cpp b/src/apps/mediaplayer/MainWin.cpp index 30c5968..c11e61c 100644 --- a/src/apps/mediaplayer/MainWin.cpp +++ b/src/apps/mediaplayer/MainWin.cpp @@ -605,6 +605,10 @@ MainWin::MessageReceived(BMessage* msg) BAutolock _(fPlaylist); int32 index; + // if false, the message was meant to only update the GUI + bool play; + if (msg->FindBool("play", &play) < B_OK || !play) + break; if (msg->FindInt32("index", &index) < B_OK || index != fPlaylist->CurrentItemIndex()) break; diff --git a/src/apps/mediaplayer/playlist/CopyPLItemsCommand.cpp b/src/apps/mediaplayer/playlist/CopyPLItemsCommand.cpp index 058150d..f9774a9 100644 --- a/src/apps/mediaplayer/playlist/CopyPLItemsCommand.cpp +++ b/src/apps/mediaplayer/playlist/CopyPLItemsCommand.cpp @@ -107,7 +107,7 @@ CopyPLItemsCommand::Undo() // take care about currently played item if (current != NULL) - fPlaylist->SetCurrentItemIndex(fPlaylist->IndexOf(current)); + fPlaylist->SetCurrentItemIndex(fPlaylist->IndexOf(current), false); return B_OK; } diff --git a/src/apps/mediaplayer/playlist/ImportPLItemsCommand.cpp b/src/apps/mediaplayer/playlist/ImportPLItemsCommand.cpp index 36d2ebe..d7944a7 100644 --- a/src/apps/mediaplayer/playlist/ImportPLItemsCommand.cpp +++ b/src/apps/mediaplayer/playlist/ImportPLItemsCommand.cpp @@ -162,7 +162,7 @@ ImportPLItemsCommand::Undo() } // Restore previously playing item if (fPlaylingIndex >= 0) - fPlaylist->SetCurrentItemIndex(fPlaylingIndex); + fPlaylist->SetCurrentItemIndex(fPlaylingIndex, false); } else { // remove new items from playlist for (int32 i = 0; i < fNewCount; i++) { diff --git a/src/apps/mediaplayer/playlist/MovePLItemsCommand.cpp b/src/apps/mediaplayer/playlist/MovePLItemsCommand.cpp index 3d9428d..109b305 100644 --- a/src/apps/mediaplayer/playlist/MovePLItemsCommand.cpp +++ b/src/apps/mediaplayer/playlist/MovePLItemsCommand.cpp @@ -134,7 +134,7 @@ MovePLItemsCommand::Perform() // take care about currently played item if (current != NULL) - fPlaylist->SetCurrentItemIndex(fPlaylist->IndexOf(current)); + fPlaylist->SetCurrentItemIndex(fPlaylist->IndexOf(current), false); return B_OK; } @@ -168,7 +168,7 @@ MovePLItemsCommand::Undo() // take care about currently played item if (current != NULL) - fPlaylist->SetCurrentItemIndex(fPlaylist->IndexOf(current)); + fPlaylist->SetCurrentItemIndex(fPlaylist->IndexOf(current), false); return B_OK; } diff --git a/src/apps/mediaplayer/playlist/Playlist.cpp b/src/apps/mediaplayer/playlist/Playlist.cpp index 5a0da70..11f74c9 100644 --- a/src/apps/mediaplayer/playlist/Playlist.cpp +++ b/src/apps/mediaplayer/playlist/Playlist.cpp @@ -55,7 +55,7 @@ Playlist::Listener::~Listener() {} void Playlist::Listener::ItemAdded(PlaylistItem* item, int32 index) {} void Playlist::Listener::ItemRemoved(int32 index) {} void Playlist::Listener::ItemsSorted() {} -void Playlist::Listener::CurrentItemChanged(int32 newIndex) {} +void Playlist::Listener::CurrentItemChanged(int32 newIndex, bool play) {} void Playlist::Listener::ImportFailed() {} @@ -277,7 +277,7 @@ Playlist::AddItem(PlaylistItem* item, int32 index) return false; if (index <= fCurrentIndex) - SetCurrentItemIndex(fCurrentIndex + 1); + SetCurrentItemIndex(fCurrentIndex + 1, false); _NotifyItemAdded(item, index); @@ -325,10 +325,10 @@ Playlist::RemoveItem(int32 index, bool careAboutCurrentIndex) _NotifyItemRemoved(index); if (careAboutCurrentIndex) { - if (index == fCurrentIndex && index >= CountItems()) + if (index >= CountItems()) SetCurrentItemIndex(CountItems() - 1); - else if (index < fCurrentIndex) - SetCurrentItemIndex(fCurrentIndex - 1); + else if (index <= fCurrentIndex) + SetCurrentItemIndex(index - 1); } return item; @@ -360,7 +360,7 @@ Playlist::ItemAtFast(int32 index) const bool -Playlist::SetCurrentItemIndex(int32 index, bool forceNotify) +Playlist::SetCurrentItemIndex(int32 index, bool notify) { bool result = true; if (index >= CountItems()) { @@ -371,11 +371,11 @@ Playlist::SetCurrentItemIndex(int32 index, bool forceNotify) index = -1; result = false; } - if (index == fCurrentIndex && !forceNotify) + if (index == fCurrentIndex && !notify) return result; fCurrentIndex = index; - _NotifyCurrentItemChanged(fCurrentIndex); + _NotifyCurrentItemChanged(fCurrentIndex, notify); return result; } @@ -804,13 +804,13 @@ Playlist::_NotifyItemsSorted() const void -Playlist::_NotifyCurrentItemChanged(int32 newIndex) const +Playlist::_NotifyCurrentItemChanged(int32 newIndex, bool play) const { BList listeners(fListeners); int32 count = listeners.CountItems(); for (int32 i = 0; i < count; i++) { Listener* listener = (Listener*)listeners.ItemAtFast(i); - listener->CurrentItemChanged(newIndex); + listener->CurrentItemChanged(newIndex, play); } } diff --git a/src/apps/mediaplayer/playlist/Playlist.h b/src/apps/mediaplayer/playlist/Playlist.h index 03ec16d..0a2ca39 100644 --- a/src/apps/mediaplayer/playlist/Playlist.h +++ b/src/apps/mediaplayer/playlist/Playlist.h @@ -55,7 +55,7 @@ public: virtual void ItemsSorted(); - virtual void CurrentItemChanged(int32 newIndex); + virtual void CurrentItemChanged(int32 newIndex, bool play); virtual void ImportFailed(); }; @@ -92,7 +92,7 @@ public: // navigating current ref bool SetCurrentItemIndex(int32 index, - bool forceNotify = false); + bool notify = true); int32 CurrentItemIndex() const; void GetSkipInfo(bool* canSkipPrevious, @@ -137,7 +137,8 @@ private: int32 index) const; void _NotifyItemRemoved(int32 index) const; void _NotifyItemsSorted() const; - void _NotifyCurrentItemChanged(int32 newIndex) const; + void _NotifyCurrentItemChanged(int32 newIndex, + bool play) const; void _NotifyImportFailed() const; private: diff --git a/src/apps/mediaplayer/playlist/PlaylistObserver.cpp b/src/apps/mediaplayer/playlist/PlaylistObserver.cpp index 0b2d763..e18c3e7 100644 --- a/src/apps/mediaplayer/playlist/PlaylistObserver.cpp +++ b/src/apps/mediaplayer/playlist/PlaylistObserver.cpp @@ -53,10 +53,11 @@ PlaylistObserver::ItemsSorted() void -PlaylistObserver::CurrentItemChanged(int32 newIndex) +PlaylistObserver::CurrentItemChanged(int32 newIndex, bool play) { BMessage message(MSG_PLAYLIST_CURRENT_ITEM_CHANGED); message.AddInt32("index", newIndex); + message.AddBool("play", play); DeliverMessage(message); } diff --git a/src/apps/mediaplayer/playlist/PlaylistObserver.h b/src/apps/mediaplayer/playlist/PlaylistObserver.h index 4eb4b9b..7a2d3bf 100644 --- a/src/apps/mediaplayer/playlist/PlaylistObserver.h +++ b/src/apps/mediaplayer/playlist/PlaylistObserver.h @@ -26,7 +26,7 @@ public: virtual void ItemsSorted(); - virtual void CurrentItemChanged(int32 newIndex); + virtual void CurrentItemChanged(int32 newIndex, bool play); virtual void ImportFailed(); }; diff --git a/src/apps/mediaplayer/playlist/RandomizePLItemsCommand.cpp b/src/apps/mediaplayer/playlist/RandomizePLItemsCommand.cpp index 9eaa253..bdadb89 100644 --- a/src/apps/mediaplayer/playlist/RandomizePLItemsCommand.cpp +++ b/src/apps/mediaplayer/playlist/RandomizePLItemsCommand.cpp @@ -135,7 +135,7 @@ RandomizePLItemsCommand::_Sort(bool random) // take care about currently played item if (current != NULL) - fPlaylist->SetCurrentItemIndex(fPlaylist->IndexOf(current)); + fPlaylist->SetCurrentItemIndex(fPlaylist->IndexOf(current), false); return B_OK; } diff --git a/src/apps/mediaplayer/playlist/RemovePLItemsCommand.cpp b/src/apps/mediaplayer/playlist/RemovePLItemsCommand.cpp index e21b332..c762ef8 100644 --- a/src/apps/mediaplayer/playlist/RemovePLItemsCommand.cpp +++ b/src/apps/mediaplayer/playlist/RemovePLItemsCommand.cpp @@ -157,7 +157,7 @@ RemovePLItemsCommand::Undo() // take care about currently played ref if (current != NULL) - fPlaylist->SetCurrentItemIndex(fPlaylist->IndexOf(current)); + fPlaylist->SetCurrentItemIndex(fPlaylist->IndexOf(current), false); return B_OK; }