fixed bug #1447, by adding the new Playlist::eliminateGaps() method
This commit is contained in:
parent
b3b80d424f
commit
5352137855
5 changed files with 119 additions and 7 deletions
|
@ -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;
|
|||
* </code></pre>
|
||||
*
|
||||
* @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<Glib::ustring>::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 ();
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -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<PlaylistElement>::Ref playlistElement = it->second;
|
||||
if (playlistElement->getType() == PlaylistElement::PlaylistType) {
|
||||
Ptr<Playlist>::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<PlaylistElement>::Ref playlistElement = it->second;
|
||||
Ptr<time_duration>::Ref startTime
|
||||
= playlistElement->getRelativeOffset();
|
||||
Ptr<time_duration>::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<time_duration>::Ref newPlaylength(new time_duration(position));
|
||||
setPlaylength(newPlaylength);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<UniqueId>::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));
|
||||
}
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue