From 535213785564c1abf6bac74591d371b73ed46059 Mon Sep 17 00:00:00 2001 From: fgerlits Date: Tue, 6 Sep 2005 14:26:40 +0000 Subject: [PATCH] fixed bug #1447, by adding the new Playlist::eliminateGaps() method --- .../core/include/LiveSupport/Core/Playlist.h | 17 +++++- livesupport/modules/core/src/Playlist.cxx | 59 ++++++++++++++++++- livesupport/modules/core/src/PlaylistTest.cxx | 34 ++++++++++- livesupport/modules/core/src/PlaylistTest.h | 13 +++- .../src/SimplePlaylistManagementWindow.cxx | 3 +- 5 files changed, 119 insertions(+), 7 deletions(-) diff --git a/livesupport/modules/core/include/LiveSupport/Core/Playlist.h b/livesupport/modules/core/include/LiveSupport/Core/Playlist.h index c1863d712..931f0f1f4 100644 --- a/livesupport/modules/core/include/LiveSupport/Core/Playlist.h +++ b/livesupport/modules/core/include/LiveSupport/Core/Playlist.h @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.41 $ + Version : $Revision: 1.42 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/include/LiveSupport/Core/Playlist.h,v $ ------------------------------------------------------------------------------*/ @@ -128,7 +128,7 @@ using namespace boost::posix_time; * * * @author $Author: fgerlits $ - * @version $Revision: 1.41 $ + * @version $Revision: 1.42 $ */ class Playlist : public Configurable, public Playable @@ -758,6 +758,19 @@ class Playlist : public Configurable, */ virtual Ptr::Ref getXmlDocumentString(void) const throw (); + + + /** + * Eliminate the gaps in the playlist. + * If there is a 2s gap between elements 2 and 3, then elements 3, + * 4, etc. are moved to 2s earlier. Elements 2 and 3 will not + * overlap, even if the first has a fade-out and the second has a + * fade-in. + * + * @return true if some gaps have been found and eliminated + */ + virtual bool + eliminateGaps(void) throw (); }; diff --git a/livesupport/modules/core/src/Playlist.cxx b/livesupport/modules/core/src/Playlist.cxx index 6e562a723..6bb47b62f 100644 --- a/livesupport/modules/core/src/Playlist.cxx +++ b/livesupport/modules/core/src/Playlist.cxx @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.40 $ + Version : $Revision: 1.41 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/Playlist.cxx,v $ ------------------------------------------------------------------------------*/ @@ -853,3 +853,60 @@ Playlist :: getXmlDocumentString() const throw () return metadataString; } + +/*------------------------------------------------------------------------------ + * Eliminate the gaps in the playlist. + *----------------------------------------------------------------------------*/ +bool +Playlist :: eliminateGaps(void) throw () +{ + bool didSomething = false; + + Playlist::const_iterator it = this->begin(); + while (it != this->end()) { + Ptr::Ref playlistElement = it->second; + if (playlistElement->getType() == PlaylistElement::PlaylistType) { + Ptr::Ref playlist = playlistElement->getPlaylist(); + didSomething |= playlist->eliminateGaps(); + } + ++it; + } + + time_duration position(0,0,0,0); + time_duration gapsFound(0,0,0,0); + + it = this->begin(); + while (it != this->end()) { + Ptr::Ref playlistElement = it->second; + Ptr::Ref startTime + = playlistElement->getRelativeOffset(); + Ptr::Ref newStartTime; + + if (*startTime - gapsFound > position) { + newStartTime.reset(new time_duration(position)); + playlistElement->setRelativeOffset(newStartTime); + gapsFound = *startTime - position; + didSomething = true; + + } else if (gapsFound.total_microseconds() != 0) { + newStartTime.reset(new time_duration(*startTime - gapsFound)); + playlistElement->setRelativeOffset(newStartTime); + + } else { + newStartTime = startTime; + } + + position = *newStartTime + *playlistElement->getPlayable() + ->getPlaylength(); + ++it; + } + + if (didSomething) { + Ptr::Ref newPlaylength(new time_duration(position)); + setPlaylength(newPlaylength); + return true; + } else { + return false; + } +} + diff --git a/livesupport/modules/core/src/PlaylistTest.cxx b/livesupport/modules/core/src/PlaylistTest.cxx index e3dd3c4f4..ff4559784 100644 --- a/livesupport/modules/core/src/PlaylistTest.cxx +++ b/livesupport/modules/core/src/PlaylistTest.cxx @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.24 $ + Version : $Revision: 1.25 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/PlaylistTest.cxx,v $ ------------------------------------------------------------------------------*/ @@ -437,3 +437,35 @@ PlaylistTest :: addPlayableTest(void) + *playlist->getPlaylength()); } + +/*------------------------------------------------------------------------------ + * Testing the eliminateGaps() method + *----------------------------------------------------------------------------*/ +void +PlaylistTest :: eliminateGapsTest(void) + throw (CPPUNIT_NS::Exception) +{ + // a simple negative test + bool result = playlist->eliminateGaps(); + CPPUNIT_ASSERT(result == false); + + // a simple positive test + Ptr::Ref secondElement(new UniqueId("101")); + try { + playlist->removePlaylistElement(secondElement); + } catch (std::invalid_argument &e) { + string eMsg = "removePlaylistElement() returned with error: "; + eMsg += e.what(); + CPPUNIT_FAIL(eMsg); + } + CPPUNIT_ASSERT(!playlist->valid()); // big gap in playlist + CPPUNIT_ASSERT(playlist->getPlaylength()); + CPPUNIT_ASSERT(*playlist->getPlaylength() == seconds(34)); + + result = playlist->eliminateGaps(); + CPPUNIT_ASSERT(result == true); + CPPUNIT_ASSERT(playlist->valid()); // the gap is gone + CPPUNIT_ASSERT(playlist->getPlaylength()); + CPPUNIT_ASSERT(*playlist->getPlaylength() == seconds(23)); +} + diff --git a/livesupport/modules/core/src/PlaylistTest.h b/livesupport/modules/core/src/PlaylistTest.h index c0274fd23..263c4bdfc 100644 --- a/livesupport/modules/core/src/PlaylistTest.h +++ b/livesupport/modules/core/src/PlaylistTest.h @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.12 $ + Version : $Revision: 1.13 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/PlaylistTest.h,v $ ------------------------------------------------------------------------------*/ @@ -58,7 +58,7 @@ namespace Core { * Unit test for the UploadPlaylistMetohd class. * * @author $Author: fgerlits $ - * @version $Revision: 1.12 $ + * @version $Revision: 1.13 $ * @see Playlist */ class PlaylistTest : public CPPUNIT_NS::TestFixture @@ -71,6 +71,7 @@ class PlaylistTest : public CPPUNIT_NS::TestFixture CPPUNIT_TEST(conversionTest); CPPUNIT_TEST(marshallingTest); CPPUNIT_TEST(addPlayableTest); + CPPUNIT_TEST(eliminateGapsTest); CPPUNIT_TEST_SUITE_END(); private: @@ -138,6 +139,14 @@ class PlaylistTest : public CPPUNIT_NS::TestFixture void addPlayableTest(void) throw (CPPUNIT_NS::Exception); + /** + * Testing the eliminateGaps() method. + * + * @exception CPPUNIT_NS::Exception on test failures. + */ + void + eliminateGapsTest(void) throw (CPPUNIT_NS::Exception); + public: diff --git a/livesupport/products/gLiveSupport/src/SimplePlaylistManagementWindow.cxx b/livesupport/products/gLiveSupport/src/SimplePlaylistManagementWindow.cxx index 56b1cefe9..5331a1279 100644 --- a/livesupport/products/gLiveSupport/src/SimplePlaylistManagementWindow.cxx +++ b/livesupport/products/gLiveSupport/src/SimplePlaylistManagementWindow.cxx @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.29 $ + Version : $Revision: 1.30 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/SimplePlaylistManagementWindow.cxx,v $ ------------------------------------------------------------------------------*/ @@ -724,6 +724,7 @@ SimplePlaylistManagementWindow :: onRemoveItem(void) throw() = (*currentItem)[modelColumns.playlistElementColumn]; playlist->removePlaylistElement(playlistElement->getId()); + playlist->eliminateGaps(); isPlaylistModified = true; showContents();