added new removeAudioClipFromPlaylist and validatePlaylist
modified the contract for removeAudioClipFromPlaylist to take a relative offset as argument instead of an audio clip id (makes more sense this way, also implements more neatly :-)
This commit is contained in:
parent
cad97c0806
commit
a5b4dd625e
20 changed files with 7217 additions and 4264 deletions
|
@ -22,7 +22,7 @@
|
|||
|
||||
|
||||
Author : $Author: fgerlits $
|
||||
Version : $Revision: 1.5 $
|
||||
Version : $Revision: 1.6 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/include/LiveSupport/Core/Playlist.h,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -71,7 +71,7 @@ using namespace boost::posix_time;
|
|||
* the playlist.
|
||||
*
|
||||
* @author $Author: fgerlits $
|
||||
* @version $Revision: 1.5 $
|
||||
* @version $Revision: 1.6 $
|
||||
*/
|
||||
class Playlist : public Configurable
|
||||
{
|
||||
|
@ -166,7 +166,7 @@ class Playlist : public Configurable
|
|||
* @return the name of the expected XML configuration element.
|
||||
*/
|
||||
static const std::string
|
||||
getConfigElementName(void) throw ()
|
||||
getConfigElementName(void) throw ()
|
||||
{
|
||||
return configElementNameStr;
|
||||
}
|
||||
|
@ -182,7 +182,7 @@ class Playlist : public Configurable
|
|||
*/
|
||||
virtual void
|
||||
configure(const xmlpp::Element & element)
|
||||
throw (std::invalid_argument);
|
||||
throw (std::invalid_argument);
|
||||
|
||||
/**
|
||||
* Return the id of the playlist.
|
||||
|
@ -190,7 +190,7 @@ class Playlist : public Configurable
|
|||
* @return the unique id of the playlist.
|
||||
*/
|
||||
Ptr<const UniqueId>::Ref
|
||||
getId(void) const throw ()
|
||||
getId(void) const throw ()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
@ -201,7 +201,7 @@ class Playlist : public Configurable
|
|||
* @return the playling length of this playlist, in milliseconds.
|
||||
*/
|
||||
Ptr<const time_duration>::Ref
|
||||
getPlaylength(void) const throw ()
|
||||
getPlaylength(void) const throw ()
|
||||
{
|
||||
return playlength;
|
||||
}
|
||||
|
@ -209,12 +209,14 @@ class Playlist : public Configurable
|
|||
/**
|
||||
* Test whether the playlist is locked for editing.
|
||||
*
|
||||
* @return true if playlist is locked, false if not
|
||||
* @return true if playlist is currently being edited;
|
||||
* false if not, or if the editing has been suspended
|
||||
* because the playlist is being played
|
||||
*/
|
||||
bool
|
||||
getIsLockedForEditing() throw ()
|
||||
getIsLockedForEditing() const throw ()
|
||||
{
|
||||
return isLockedForEditing;
|
||||
return isLockedForEditing && !isLockedForPlaying;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -223,7 +225,7 @@ class Playlist : public Configurable
|
|||
* @return true if playlist is locked, false if not
|
||||
*/
|
||||
bool
|
||||
getIsLockedForPlaying() throw ()
|
||||
getIsLockedForPlaying() const throw ()
|
||||
{
|
||||
return isLockedForPlaying;
|
||||
}
|
||||
|
@ -235,7 +237,7 @@ class Playlist : public Configurable
|
|||
* false otherwise.
|
||||
*/
|
||||
bool
|
||||
setLockedForEditing(bool lockStatus)
|
||||
setLockedForEditing(const bool lockStatus)
|
||||
throw ();
|
||||
|
||||
/**
|
||||
|
@ -245,7 +247,7 @@ class Playlist : public Configurable
|
|||
* false otherwise.
|
||||
*/
|
||||
bool
|
||||
setLockedForPlaying(bool lockStatus)
|
||||
setLockedForPlaying(const bool lockStatus)
|
||||
throw ();
|
||||
|
||||
/**
|
||||
|
@ -256,7 +258,6 @@ class Playlist : public Configurable
|
|||
|
||||
/**
|
||||
* Get an iterator pointing to the first playlist element.
|
||||
*
|
||||
*/
|
||||
const_iterator
|
||||
begin() const throw ()
|
||||
|
@ -266,7 +267,6 @@ class Playlist : public Configurable
|
|||
|
||||
/**
|
||||
* Get an iterator pointing to one after the last playlist element.
|
||||
*
|
||||
*/
|
||||
const_iterator
|
||||
end() const throw ()
|
||||
|
@ -287,6 +287,27 @@ class Playlist : public Configurable
|
|||
addAudioClip(Ptr<AudioClip>::Ref audioClip,
|
||||
Ptr<time_duration>::Ref relativeOffset)
|
||||
throw (std::invalid_argument);
|
||||
|
||||
/**
|
||||
* Remove an audio clip from the playlist.
|
||||
*
|
||||
* @param relativeOffset the start of the audio clip, relative
|
||||
* to the start of the playlist
|
||||
* @exception std::invalid_argument if the playlist does not contain
|
||||
* an audio clip with the specified relative offset
|
||||
*/
|
||||
void
|
||||
removeAudioClip(Ptr<const time_duration>::Ref relativeOffset)
|
||||
throw (std::invalid_argument);
|
||||
|
||||
/**
|
||||
* Validate the playlist: check that there are no overlaps or gaps.
|
||||
* If the playlength is the only thing amiss, playlist is considered
|
||||
* valid, and the playlength is fixed. (Hence no 'const'.)
|
||||
*/
|
||||
bool
|
||||
valid(void) throw ();
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
|
||||
Author : $Author: fgerlits $
|
||||
Version : $Revision: 1.5 $
|
||||
Version : $Revision: 1.6 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/Playlist.cxx,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -153,7 +153,7 @@ Playlist::addAudioClip(Ptr<AudioClip>::Ref audioClip,
|
|||
throw (std::invalid_argument)
|
||||
{
|
||||
if (elementList->find(*relativeOffset) != elementList->end()) {
|
||||
std::string eMsg = "two playlist elements at the same relative offset";
|
||||
std::string eMsg = "two audio clips at the same relative offset";
|
||||
throw std::invalid_argument(eMsg);
|
||||
}
|
||||
|
||||
|
@ -164,11 +164,26 @@ Playlist::addAudioClip(Ptr<AudioClip>::Ref audioClip,
|
|||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Remove an audio clip from the playlist.
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
Playlist::removeAudioClip(Ptr<const time_duration>::Ref relativeOffset)
|
||||
throw (std::invalid_argument)
|
||||
{
|
||||
// this returns the number of elements found and erased
|
||||
if (!elementList->erase(*relativeOffset)) {
|
||||
std::string eMsg = "no audio clip at the specified relative offset";
|
||||
throw std::invalid_argument(eMsg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Lock or unlock the playlist for editing.
|
||||
*----------------------------------------------------------------------------*/
|
||||
bool
|
||||
Playlist::setLockedForEditing(bool lockStatus)
|
||||
Playlist::setLockedForEditing(const bool lockStatus)
|
||||
throw ()
|
||||
{
|
||||
if (lockStatus == true) {
|
||||
|
@ -196,7 +211,7 @@ Playlist::setLockedForEditing(bool lockStatus)
|
|||
* Lock or unlock the playlist for playing.
|
||||
*----------------------------------------------------------------------------*/
|
||||
bool
|
||||
Playlist::setLockedForPlaying(bool lockStatus)
|
||||
Playlist::setLockedForPlaying(const bool lockStatus)
|
||||
throw ()
|
||||
{
|
||||
if (lockStatus == true) {
|
||||
|
@ -214,3 +229,27 @@ Playlist::setLockedForPlaying(bool lockStatus)
|
|||
} // was already unlocked!
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Validate the playlist.
|
||||
*----------------------------------------------------------------------------*/
|
||||
bool
|
||||
Playlist::valid(void) throw ()
|
||||
{
|
||||
Ptr<time_duration>::Ref runningTime(new time_duration(0,0,0,0));
|
||||
Ptr<const PlaylistElement>::Ref playlistElement;
|
||||
Ptr<const AudioClip>::Ref audioClip;
|
||||
|
||||
PlaylistElementListType::const_iterator it = elementList->begin();
|
||||
while (it != elementList->end()) {
|
||||
playlistElement = it->second;
|
||||
if (*runningTime != *(playlistElement->getRelativeOffset())) {
|
||||
return false;
|
||||
}
|
||||
audioClip = playlistElement->getAudioClip();
|
||||
*runningTime += *(audioClip->getPlaylength());
|
||||
++it;
|
||||
}
|
||||
playlength = runningTime; // fix playlength, if everything else is OK
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
|
||||
Author : $Author: fgerlits $
|
||||
Version : $Revision: 1.5 $
|
||||
Version : $Revision: 1.6 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/PlaylistTest.cxx,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -90,6 +90,9 @@ PlaylistTest :: setUp(void) throw ()
|
|||
CPPUNIT_ASSERT(duration->hours() == 1);
|
||||
CPPUNIT_ASSERT(duration->minutes() == 30);
|
||||
CPPUNIT_ASSERT(duration->seconds() == 0);
|
||||
|
||||
CPPUNIT_ASSERT(playlist->valid());
|
||||
|
||||
} catch (std::invalid_argument &e) {
|
||||
CPPUNIT_FAIL("semantic error in configuration file");
|
||||
} catch (xmlpp::exception &e) {
|
||||
|
@ -162,10 +165,10 @@ PlaylistTest :: lockTest(void)
|
|||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Test to see if we can add a new audio clip
|
||||
* Test to see if we can add or remove an audio clip
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
PlaylistTest :: addAudioClipTest(void)
|
||||
PlaylistTest :: audioClipTest(void)
|
||||
throw (CPPUNIT_NS::Exception)
|
||||
{
|
||||
Ptr<UniqueId>::Ref clipId(new UniqueId(20001));
|
||||
|
@ -183,6 +186,8 @@ PlaylistTest :: addAudioClipTest(void)
|
|||
CPPUNIT_FAIL(eMsg);
|
||||
}
|
||||
|
||||
CPPUNIT_ASSERT(!playlist->valid()); // overlapping audio clips
|
||||
|
||||
Playlist::const_iterator it = playlist->begin();
|
||||
CPPUNIT_ASSERT(it != playlist->end());
|
||||
|
||||
|
@ -200,4 +205,31 @@ PlaylistTest :: addAudioClipTest(void)
|
|||
|
||||
++it;
|
||||
CPPUNIT_ASSERT(it == playlist->end());
|
||||
|
||||
try {
|
||||
playlist->removeAudioClip(relativeOffset);
|
||||
}
|
||||
catch (std::invalid_argument &e) {
|
||||
string eMsg = "removeAudioClip returned with error: ";
|
||||
eMsg += e.what();
|
||||
CPPUNIT_FAIL(eMsg);
|
||||
}
|
||||
|
||||
it = playlist->begin();
|
||||
CPPUNIT_ASSERT(it != playlist->end());
|
||||
++it;
|
||||
CPPUNIT_ASSERT(it != playlist->end());
|
||||
++it;
|
||||
CPPUNIT_ASSERT(it == playlist->end());
|
||||
|
||||
Ptr<const time_duration>::Ref phonyRelativeOffset(
|
||||
new time_duration(0,0,1,0));
|
||||
try {
|
||||
playlist->removeAudioClip(phonyRelativeOffset);
|
||||
}
|
||||
catch (std::invalid_argument &e) {
|
||||
return;
|
||||
}
|
||||
CPPUNIT_FAIL("removeAudioClip allowed to remove "
|
||||
"non-existent audio clip");
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
|
||||
Author : $Author: fgerlits $
|
||||
Version : $Revision: 1.3 $
|
||||
Version : $Revision: 1.4 $
|
||||
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.3 $
|
||||
* @version $Revision: 1.4 $
|
||||
* @see Playlist
|
||||
*/
|
||||
class PlaylistTest : public CPPUNIT_NS::TestFixture
|
||||
|
@ -66,7 +66,7 @@ class PlaylistTest : public CPPUNIT_NS::TestFixture
|
|||
CPPUNIT_TEST_SUITE(PlaylistTest);
|
||||
CPPUNIT_TEST(firstTest);
|
||||
CPPUNIT_TEST(lockTest);
|
||||
CPPUNIT_TEST(addAudioClipTest);
|
||||
CPPUNIT_TEST(audioClipTest);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
private:
|
||||
|
@ -100,7 +100,7 @@ class PlaylistTest : public CPPUNIT_NS::TestFixture
|
|||
* @exception CPPUNIT_NS::Exception on test failures.
|
||||
*/
|
||||
void
|
||||
addAudioClipTest(void) throw (CPPUNIT_NS::Exception);
|
||||
audioClipTest(void) throw (CPPUNIT_NS::Exception);
|
||||
|
||||
|
||||
public:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue