fixed #936, mostly

This commit is contained in:
fgerlits 2006-11-13 19:52:18 +00:00
parent 54308f13e4
commit fc76b78a84
6 changed files with 157 additions and 19 deletions

View file

@ -883,6 +883,23 @@ class Playlist : public Configurable,
*/
virtual bool
eliminateGaps(void) throw ();
/**
* Find the playlist element at the specified offset.
*
* This is used by the Master Panel to display the contents
* of the currently playing Playlist.
* When there are more than one playlist elements at the given
* offset, the one with the greatest relativeOffset is chosen.
* Can return a 0 pointer if there is no playlist element at
* the given offset.
*
* @param offset the elapsed time relative to the Playlist.
* @return the playlist element at the given offset.
*/
Ptr<PlaylistElement>::Ref
findAtOffset(Ptr<const time_duration>::Ref offset) const
throw ();
};

View file

@ -901,3 +901,33 @@ Playlist :: eliminateGaps(void) throw ()
}
}
/*------------------------------------------------------------------------------
* Find the playlist element at the specified offset.
*----------------------------------------------------------------------------*/
Ptr<PlaylistElement>::Ref
Playlist :: findAtOffset(Ptr<const time_duration>::Ref offset) const
throw ()
{
Ptr<PlaylistElement>::Ref playlistElement;
PlaylistElementListType::const_reverse_iterator it;
PlaylistElementListType::const_reverse_iterator rend
= elementList->rend();
for (it = elementList->rbegin(); it != rend; ++it) {
time_duration currentStart = it->first;
if (currentStart <= *offset) {
Ptr<PlaylistElement>::Ref
currentElement = it->second;
time_duration currentEnd = currentStart
+ *currentElement->getPlayable()
->getPlaylength();
if (currentEnd > *offset) {
playlistElement = currentElement;
}
}
}
return playlistElement;
}

View file

@ -481,3 +481,46 @@ PlaylistTest :: eliminateGapsLastItemTest(void)
}
/*------------------------------------------------------------------------------
* Test the findAtOffset() method.
*----------------------------------------------------------------------------*/
void
PlaylistTest :: findAtOffsetTest(void) throw (CPPUNIT_NS::Exception)
{
Ptr<time_duration>::Ref offset(new time_duration());
Ptr<const PlaylistElement>::Ref playlistElement;
*offset = seconds(-1);
playlistElement = playlist->findAtOffset(offset);
CPPUNIT_ASSERT(!playlistElement);
*offset = seconds(0);
playlistElement = playlist->findAtOffset(offset);
CPPUNIT_ASSERT(playlistElement);
CPPUNIT_ASSERT(playlistElement->getPlayable()->getId()->getId() == 0x10001);
*offset = seconds(11);
playlistElement = playlist->findAtOffset(offset);
CPPUNIT_ASSERT(playlistElement);
CPPUNIT_ASSERT(playlistElement->getPlayable()->getId()->getId() == 0x10002);
*offset = seconds(20);
playlistElement = playlist->findAtOffset(offset);
CPPUNIT_ASSERT(playlistElement);
CPPUNIT_ASSERT(playlistElement->getPlayable()->getId()->getId() == 0x10002);
*offset = microseconds(30123456);
playlistElement = playlist->findAtOffset(offset);
CPPUNIT_ASSERT(playlistElement);
CPPUNIT_ASSERT(playlistElement->getPlayable()->getId()->getId() == 0x2);
*offset = seconds(34);
playlistElement = playlist->findAtOffset(offset);
CPPUNIT_ASSERT(!playlistElement);
*offset = hours(1);
playlistElement = playlist->findAtOffset(offset);
CPPUNIT_ASSERT(!playlistElement);
}

View file

@ -73,6 +73,7 @@ class PlaylistTest : public CPPUNIT_NS::TestFixture
CPPUNIT_TEST(addPlayableTest);
CPPUNIT_TEST(eliminateGapsTest);
CPPUNIT_TEST(eliminateGapsLastItemTest);
CPPUNIT_TEST(findAtOffsetTest);
CPPUNIT_TEST_SUITE_END();
private:
@ -156,6 +157,14 @@ class PlaylistTest : public CPPUNIT_NS::TestFixture
void
eliminateGapsLastItemTest(void) throw (CPPUNIT_NS::Exception);
/**
* Test the findAtOffset() method.
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
findAtOffsetTest(void) throw (CPPUNIT_NS::Exception);
public: