From 64a9cca523251b1534182e2422c6980ba1e97c8d Mon Sep 17 00:00:00 2001 From: fgerlits Date: Fri, 1 Jul 2005 14:39:14 +0000 Subject: [PATCH] added new addPlaylength() method to the Playlist class --- .../core/include/LiveSupport/Core/Playlist.h | 33 +++++++--- livesupport/modules/core/src/Playlist.cxx | 34 ++++++++++- livesupport/modules/core/src/PlaylistTest.cxx | 60 ++++++++++++++----- livesupport/modules/core/src/PlaylistTest.h | 13 +++- 4 files changed, 111 insertions(+), 29 deletions(-) diff --git a/livesupport/modules/core/include/LiveSupport/Core/Playlist.h b/livesupport/modules/core/include/LiveSupport/Core/Playlist.h index 1e037cae1..801add77e 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.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; * * * @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::Ref + addPlayable(Ptr::Ref playable, + Ptr::Ref relativeOffset, + Ptr::Ref fadeInfo + = Ptr::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::Ref addAudioClip(Ptr::Ref audioClip, Ptr::Ref relativeOffset, Ptr::Ref fadeInfo = Ptr::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::Ref addPlaylist(Ptr::Ref playlist, Ptr::Ref relativeOffset, Ptr::Ref fadeInfo = Ptr::Ref()) - throw (std::invalid_argument); + throw (); /** * Set the fade in / fade out info for a playlist element. diff --git a/livesupport/modules/core/src/Playlist.cxx b/livesupport/modules/core/src/Playlist.cxx index c06a5edf2..b106fd5d5 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.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::Ref playlistElement) } +/*------------------------------------------------------------------------------ + * Add a new audio clip or sub-playlist to the playlist. + *----------------------------------------------------------------------------*/ +Ptr::Ref +Playlist::addPlayable(Ptr::Ref playable, + Ptr::Ref relativeOffset, + Ptr::Ref fadeInfo) + throw (std::invalid_argument) +{ + Ptr::Ref audioClip; + Ptr::Ref playlist; + + switch (playable->getType()) { + case Playable::AudioClipType : + audioClip = boost::dynamic_pointer_cast(playable); + return addAudioClip(audioClip, relativeOffset, fadeInfo); + + case Playable::PlaylistType : + playlist = boost::dynamic_pointer_cast(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::Ref Playlist::addAudioClip(Ptr::Ref audioClip, Ptr::Ref relativeOffset, Ptr::Ref fadeInfo) - throw (std::invalid_argument) + throw () { Ptr::Ref playlistElement(new PlaylistElement( relativeOffset, audioClip, fadeInfo)); @@ -469,7 +497,7 @@ Ptr::Ref Playlist::addPlaylist(Ptr::Ref playlist, Ptr::Ref relativeOffset, Ptr::Ref fadeInfo) - throw (std::invalid_argument) + throw () { Ptr::Ref playlistElement(new PlaylistElement( relativeOffset, playlist, fadeInfo)); diff --git a/livesupport/modules/core/src/PlaylistTest.cxx b/livesupport/modules/core/src/PlaylistTest.cxx index bd195bec3..e3dd3c4f4 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.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::Ref playlist(new Playlist()); - try { - Ptr::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::Ref newPlaylist(new Playlist(*playlist)); + // make a copy + + Ptr::Ref clipId(new UniqueId("20001")); + Ptr::Ref clipLength(new time_duration(0,0,10,0)); + Ptr::Ref audioClip(new AudioClip(clipId, clipLength)); + + Ptr::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::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()); +} + diff --git a/livesupport/modules/core/src/PlaylistTest.h b/livesupport/modules/core/src/PlaylistTest.h index b34b62781..c0274fd23 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.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: