added new addPlaylength() method to the Playlist class

This commit is contained in:
fgerlits 2005-07-01 14:39:14 +00:00
parent e80e1e301d
commit 64a9cca523
4 changed files with 111 additions and 29 deletions

View file

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.36 $
Version : $Revision: 1.37 $
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.36 $
* @version $Revision: 1.37 $
*/
class Playlist : public Configurable,
public Playable
@ -573,6 +573,27 @@ class Playlist : public Configurable,
return elementList->size();
}
/**
* Add a new audio clip or sub-playlist to the playlist.
*
* Checks the type of the playlist, and calls either addAudioClip()
* or addPlaylist().
*
* @param audioClip the new playable item to be added
* @param relativeOffset the start of the playable item, relative
* to the start of the playlist
* @param fadeInfo the fade in / fade out info (optional)
* @return the ID of the new PlaylistElement
* @exception std::invalid_argument if playable is neither an AudioClip
* nor a Playlist
*/
Ptr<UniqueId>::Ref
addPlayable(Ptr<Playable>::Ref playable,
Ptr<time_duration>::Ref relativeOffset,
Ptr<FadeInfo>::Ref fadeInfo
= Ptr<FadeInfo>::Ref())
throw (std::invalid_argument);
/**
* Add a new audio clip to the playlist.
*
@ -585,15 +606,13 @@ class Playlist : public Configurable,
* to the start of the playlist
* @param fadeInfo the fade in / fade out info (optional)
* @return the ID of the new PlaylistElement
* @exception std::invalid_argument if the playlist already contains
* a playlist element with the same relative offset
*/
Ptr<UniqueId>::Ref
addAudioClip(Ptr<AudioClip>::Ref audioClip,
Ptr<time_duration>::Ref relativeOffset,
Ptr<FadeInfo>::Ref fadeInfo
= Ptr<FadeInfo>::Ref())
throw (std::invalid_argument);
throw ();
/**
* Add a new sub-playlist to the playlist.
@ -607,15 +626,13 @@ class Playlist : public Configurable,
* to the start of the containing playlist
* @param fadeInfo the fade in / fade out info (optional)
* @return the ID of the new PlaylistElement
* @exception std::invalid_argument if the playlist already contains
* a playlist element with the same relative offset
*/
Ptr<UniqueId>::Ref
addPlaylist(Ptr<Playlist>::Ref playlist,
Ptr<time_duration>::Ref relativeOffset,
Ptr<FadeInfo>::Ref fadeInfo
= Ptr<FadeInfo>::Ref())
throw (std::invalid_argument);
throw ();
/**
* Set the fade in / fade out info for a playlist element.

View file

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.36 $
Version : $Revision: 1.37 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/Playlist.cxx,v $
------------------------------------------------------------------------------*/
@ -438,6 +438,34 @@ Playlist::addPlaylistElement(Ptr<PlaylistElement>::Ref playlistElement)
}
/*------------------------------------------------------------------------------
* Add a new audio clip or sub-playlist to the playlist.
*----------------------------------------------------------------------------*/
Ptr<UniqueId>::Ref
Playlist::addPlayable(Ptr<Playable>::Ref playable,
Ptr<time_duration>::Ref relativeOffset,
Ptr<FadeInfo>::Ref fadeInfo)
throw (std::invalid_argument)
{
Ptr<AudioClip>::Ref audioClip;
Ptr<Playlist>::Ref playlist;
switch (playable->getType()) {
case Playable::AudioClipType :
audioClip = boost::dynamic_pointer_cast<AudioClip>(playable);
return addAudioClip(audioClip, relativeOffset, fadeInfo);
case Playable::PlaylistType :
playlist = boost::dynamic_pointer_cast<Playlist>(playable);
return addPlaylist(playlist, relativeOffset, fadeInfo);
default :
throw std::invalid_argument("Playable object is neither AudioClip"
" nor Playlist?!");
}
}
/*------------------------------------------------------------------------------
* Add a new audio clip to the playlist.
*----------------------------------------------------------------------------*/
@ -445,7 +473,7 @@ Ptr<UniqueId>::Ref
Playlist::addAudioClip(Ptr<AudioClip>::Ref audioClip,
Ptr<time_duration>::Ref relativeOffset,
Ptr<FadeInfo>::Ref fadeInfo)
throw (std::invalid_argument)
throw ()
{
Ptr<PlaylistElement>::Ref playlistElement(new PlaylistElement(
relativeOffset, audioClip, fadeInfo));
@ -469,7 +497,7 @@ Ptr<UniqueId>::Ref
Playlist::addPlaylist(Ptr<Playlist>::Ref playlist,
Ptr<time_duration>::Ref relativeOffset,
Ptr<FadeInfo>::Ref fadeInfo)
throw (std::invalid_argument)
throw ()
{
Ptr<PlaylistElement>::Ref playlistElement(new PlaylistElement(
relativeOffset, playlist, fadeInfo));

View file

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.23 $
Version : $Revision: 1.24 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/PlaylistTest.cxx,v $
------------------------------------------------------------------------------*/
@ -381,21 +381,6 @@ void
PlaylistTest :: marshallingTest(void)
throw (CPPUNIT_NS::Exception)
{
Ptr<Playlist>::Ref playlist(new Playlist());
try {
Ptr<xmlpp::DomParser>::Ref parser(
new xmlpp::DomParser(configFileName, false));
const xmlpp::Document * document = parser->get_document();
const xmlpp::Element * root = document->get_root_node();
playlist->configure(*root);
} catch (std::invalid_argument &e) {
CPPUNIT_FAIL(e.what());
} catch (xmlpp::exception &e) {
CPPUNIT_FAIL(e.what());
}
XmlRpc::XmlRpcValue xmlRpcValue = *playlist;
CPPUNIT_ASSERT(xmlRpcValue.hasMember("playlist"));
@ -409,3 +394,46 @@ PlaylistTest :: marshallingTest(void)
== *otherPlaylist->getPlaylength());
}
/*------------------------------------------------------------------------------
* Testing the addPlayable() method
*----------------------------------------------------------------------------*/
void
PlaylistTest :: addPlayableTest(void)
throw (CPPUNIT_NS::Exception)
{
Ptr<Playlist>::Ref newPlaylist(new Playlist(*playlist));
// make a copy
Ptr<UniqueId>::Ref clipId(new UniqueId("20001"));
Ptr<time_duration>::Ref clipLength(new time_duration(0,0,10,0));
Ptr<AudioClip>::Ref audioClip(new AudioClip(clipId, clipLength));
Ptr<time_duration>::Ref firstOffset(new time_duration(0,0,30,0));
// hour, min, sec, frac_sec
try {
newPlaylist->addPlayable(audioClip, firstOffset);
} catch (std::invalid_argument &e) {
string eMsg = "addPlayable returned with error: ";
eMsg += e.what();
CPPUNIT_FAIL(eMsg);
}
CPPUNIT_ASSERT(newPlaylist->getPlaylength());
CPPUNIT_ASSERT(*newPlaylist->getPlaylength() == *firstOffset
+ *audioClip->getPlaylength());
Ptr<time_duration>::Ref secondOffset(new time_duration(0,0,40,0));
try {
newPlaylist->addPlayable(playlist, secondOffset);
} catch (std::invalid_argument &e) {
string eMsg = "addPlayable returned with error: ";
eMsg += e.what();
CPPUNIT_FAIL(eMsg);
}
CPPUNIT_ASSERT(newPlaylist->getPlaylength());
CPPUNIT_ASSERT(*newPlaylist->getPlaylength() == *secondOffset
+ *playlist->getPlaylength());
}

View file

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.11 $
Version : $Revision: 1.12 $
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.11 $
* @version $Revision: 1.12 $
* @see Playlist
*/
class PlaylistTest : public CPPUNIT_NS::TestFixture
@ -70,6 +70,7 @@ class PlaylistTest : public CPPUNIT_NS::TestFixture
CPPUNIT_TEST(fadeInfoTest);
CPPUNIT_TEST(conversionTest);
CPPUNIT_TEST(marshallingTest);
CPPUNIT_TEST(addPlayableTest);
CPPUNIT_TEST_SUITE_END();
private:
@ -129,6 +130,14 @@ class PlaylistTest : public CPPUNIT_NS::TestFixture
void
marshallingTest(void) throw (CPPUNIT_NS::Exception);
/**
* Testing the addPlayable() method.
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
addPlayableTest(void) throw (CPPUNIT_NS::Exception);
public: