modified PlaylistElement to contain (a pointer to) an actual AudioClip

instance, not just its ID
This commit is contained in:
fgerlits 2004-10-15 09:33:28 +00:00
parent 55a0dcc50f
commit cad97c0806
21 changed files with 193 additions and 150 deletions

View file

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE playlistElement [
<!ELEMENT playlistElement (audioClip) >
<!ATTLIST playlistElement id NMTOKEN #REQUIRED >
<!ATTLIST playlistElement relativeOffset NMTOKEN #REQUIRED >
<!ELEMENT audioClip EMPTY >
<!ATTLIST audioClip id NMTOKEN #REQUIRED >
<!ATTLIST audioClip playlength NMTOKEN #REQUIRED >
]>
<playlistElement id="707" relativeOffset="00:12:34.000" >
<audioClip id="10001" playlength="01:00:00.000"/>
</playlistElement>

View file

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.1 $
Version : $Revision: 1.2 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/include/LiveSupport/Core/AudioClip.h,v $
------------------------------------------------------------------------------*/
@ -72,7 +72,7 @@ using namespace boost::posix_time;
* in a Playlist.
*
* @author $Author: fgerlits $
* @version $Revision: 1.1 $
* @version $Revision: 1.2 $
*/
class AudioClip : public Configurable
{
@ -150,13 +150,10 @@ class AudioClip : public Configurable
* @param element the XML element to configure the object from.
* @exception std::invalid_argument if the supplied XML element
* contains bad configuraiton information
* @exception std::logic_error if the object has already
* been configured, and can not be reconfigured.
*/
virtual void
configure(const xmlpp::Element & element)
throw (std::invalid_argument,
std::logic_error);
throw (std::invalid_argument);
/**
* Return the id of the audio clip.

View file

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.4 $
Version : $Revision: 1.5 $
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.4 $
* @version $Revision: 1.5 $
*/
class Playlist : public Configurable
{
@ -284,7 +284,7 @@ class Playlist : public Configurable
* an audio clip with the same relative offset
*/
void
addAudioClip(Ptr<UniqueId>::Ref audioClipId,
addAudioClip(Ptr<AudioClip>::Ref audioClip,
Ptr<time_duration>::Ref relativeOffset)
throw (std::invalid_argument);
};

View file

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.2 $
Version : $Revision: 1.3 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/include/LiveSupport/Core/PlaylistElement.h,v $
------------------------------------------------------------------------------*/
@ -49,6 +49,7 @@
#include "LiveSupport/Core/Ptr.h"
#include "LiveSupport/Core/UniqueId.h"
#include "LiveSupport/Core/Configurable.h"
#include "LiveSupport/Core/AudioClip.h"
namespace LiveSupport {
@ -72,7 +73,7 @@ using namespace LiveSupport::Core;
* An item in a playlist.
*
* @author $Author: fgerlits $
* @version $Revision: 1.2 $
* @version $Revision: 1.3 $
*/
class PlaylistElement : public Configurable
{
@ -93,9 +94,9 @@ class PlaylistElement : public Configurable
Ptr<time_duration>::Ref relativeOffset;
/**
* The id of the audio clip associated with the entry.
* The audio clip associated with the entry.
*/
Ptr<UniqueId>::Ref audioClipId;
Ptr<AudioClip>::Ref audioClip;
public:
@ -119,12 +120,12 @@ class PlaylistElement : public Configurable
*/
PlaylistElement(Ptr<UniqueId>::Ref id,
Ptr<time_duration>::Ref relativeOffset,
Ptr<UniqueId>::Ref audioClipId)
Ptr<AudioClip>::Ref audioClip)
throw ()
{
this->id = id;
this->relativeOffset = relativeOffset;
this->audioClipId = audioClipId;
this->audioClip = audioClip;
}
/**
@ -137,12 +138,12 @@ class PlaylistElement : public Configurable
* the start of the playlist.
*/
PlaylistElement(Ptr<time_duration>::Ref relativeOffset,
Ptr<UniqueId>::Ref audioClipId)
Ptr<AudioClip>::Ref audioClip)
throw ()
{
this->id = UniqueId::generateId();
this->relativeOffset = relativeOffset;
this->audioClipId = audioClipId;
this->audioClip = audioClip;
}
/**
@ -172,9 +173,7 @@ class PlaylistElement : public Configurable
*
* @param element the XML element to configure the object from.
* @exception std::invalid_argument if the supplied XML element
* contains bad configuraiton information
* @exception std::logic_error if the object has already
* been configured, and can not be reconfigured.
* contains bad configuration information
*/
virtual void
configure(const xmlpp::Element & element)
@ -192,7 +191,7 @@ class PlaylistElement : public Configurable
}
/**
* Return the relative offset of the element.
* Return the relative offset of the playlist element.
*
* @return the relative offset of the element.
*/
@ -203,14 +202,14 @@ class PlaylistElement : public Configurable
}
/**
* Return the id of the audio clip associated with the element.
* Return the audio clip associated with the playlist element.
*
* @return the id of the audio clip associated with the element.
* @return the audio clip associated with the element.
*/
Ptr<const UniqueId>::Ref
getAudioClipId(void) const throw ()
Ptr<const AudioClip>::Ref
getAudioClip(void) const throw ()
{
return audioClipId;
return audioClip;
}
};

View file

@ -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/Attic/StorageClientInterface.h,v $
------------------------------------------------------------------------------*/
@ -61,7 +61,7 @@ namespace Core {
* An interface for storage clients.
*
* @author $Author: fgerlits $
* @version $Revision: 1.5 $
* @version $Revision: 1.6 $
*/
class StorageClientInterface
{
@ -130,6 +130,18 @@ class StorageClientInterface
virtual const bool
existsAudioClip(Ptr<const UniqueId>::Ref id) const throw ()
= 0;
/**
* Return an audio clip with the specified id.
*
* @param id the id of the playlist to return.
* @return the requested audio clip.
* @exception std::invalid_argument if no audio clip with the
* specified id exists.
*/
virtual Ptr<AudioClip>::Ref
getAudioClip(Ptr<const UniqueId>::Ref id) const
throw (std::invalid_argument)
= 0;
};

View file

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.1 $
Version : $Revision: 1.2 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/AudioClip.cxx,v $
------------------------------------------------------------------------------*/
@ -80,7 +80,7 @@ AudioClip :: configure(const xmlpp::Element & element)
std::invalid_argument)
{
if (element.get_name() != configElementNameStr) {
std::string eMsg = "Bad configuration element ";
std::string eMsg = "bad configuration element ";
eMsg += element.get_name();
throw std::invalid_argument(eMsg);
}
@ -90,7 +90,7 @@ AudioClip :: configure(const xmlpp::Element & element)
unsigned long int idValue;
if (!(attribute = element.get_attribute(idAttrName))) {
std::string eMsg = "Missing attribute ";
std::string eMsg = "missing attribute ";
eMsg += idAttrName;
throw std::invalid_argument(eMsg);
}
@ -107,11 +107,10 @@ AudioClip :: configure(const xmlpp::Element & element)
title.reset(new std::string(titleValue));
*/
if (!(attribute = element.get_attribute(playlengthAttrName))) {
std::string eMsg = "Missing attribute ";
std::string eMsg = "missing attribute ";
eMsg += idAttrName;
throw std::invalid_argument(eMsg);
}
playlength.reset(new time_duration(
duration_from_string(attribute->get_value())));
}

View file

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.4 $
Version : $Revision: 1.5 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/Playlist.cxx,v $
------------------------------------------------------------------------------*/
@ -80,7 +80,7 @@ Playlist :: configure(const xmlpp::Element & element)
throw (std::invalid_argument)
{
if (element.get_name() != configElementNameStr) {
std::string eMsg = "Bad configuration element ";
std::string eMsg = "bad configuration element ";
eMsg += element.get_name();
throw std::invalid_argument(eMsg);
}
@ -90,7 +90,7 @@ Playlist :: configure(const xmlpp::Element & element)
unsigned long int idValue;
if (!(attribute = element.get_attribute(idAttrName))) {
std::string eMsg = "Missing attribute ";
std::string eMsg = "missing attribute ";
eMsg += idAttrName;
throw std::invalid_argument(eMsg);
}
@ -99,14 +99,13 @@ Playlist :: configure(const xmlpp::Element & element)
id.reset(new UniqueId(idValue));
if (!(attribute = element.get_attribute(playlengthAttrName))) {
std::string eMsg = "Missing attribute ";
std::string eMsg = "missing attribute ";
eMsg += idAttrName;
throw std::invalid_argument(eMsg);
}
playlength.reset(new time_duration(
duration_from_string(attribute->get_value())));
// no exception thrown here: it's OK to have an empty playlist element list
elementList.reset(new PlaylistElementListType);
xmlpp::Node::NodeList childNodes
= element.get_children(elementListAttrName);
@ -116,7 +115,7 @@ Playlist :: configure(const xmlpp::Element & element)
Ptr<PlaylistElement>::Ref newPlaylistElement(new PlaylistElement);
const xmlpp::Element * childElement
= dynamic_cast<const xmlpp::Element*> (*it);
newPlaylistElement->configure(*childElement);
newPlaylistElement->configure(*childElement); // may throw exception
addPlaylistElement(newPlaylistElement);
++it;
}
@ -137,7 +136,7 @@ Playlist::addPlaylistElement(Ptr<PlaylistElement>::Ref playlistElement)
= playlistElement->getRelativeOffset();
if (elementList->find(*relativeOffset) != elementList->end()) {
std::string eMsg = "Two playlist elements at the same relative offset";
std::string eMsg = "two playlist elements at the same relative offset";
throw std::invalid_argument(eMsg);
}
@ -149,17 +148,17 @@ Playlist::addPlaylistElement(Ptr<PlaylistElement>::Ref playlistElement)
* Add a new audio clip to the playlist.
*----------------------------------------------------------------------------*/
void
Playlist::addAudioClip(Ptr<UniqueId>::Ref audioClipId,
Playlist::addAudioClip(Ptr<AudioClip>::Ref audioClip,
Ptr<time_duration>::Ref relativeOffset)
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 playlist elements at the same relative offset";
throw std::invalid_argument(eMsg);
}
Ptr<PlaylistElement>::Ref playlistElement(new PlaylistElement(
relativeOffset, audioClipId));
relativeOffset, audioClip));
(*elementList)[*relativeOffset] = playlistElement;
}

View file

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.2 $
Version : $Revision: 1.3 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/PlaylistElement.cxx,v $
------------------------------------------------------------------------------*/
@ -67,11 +67,6 @@ static const std::string relativeOffsetAttrName = "relativeOffset";
*/
static const std::string audioClipElementName = "audioClip";
/**
* The name of the attribute of the id of the audio clip element.
*/
static const std::string audioClipIdAttrName = "id";
/* =============================================== local function prototypes */
@ -86,7 +81,7 @@ PlaylistElement :: configure(const xmlpp::Element & element)
throw (std::invalid_argument)
{
if (element.get_name() != configElementNameStr) {
std::string eMsg = "Bad configuration element ";
std::string eMsg = "bad configuration element ";
eMsg += element.get_name();
throw std::invalid_argument(eMsg);
}
@ -96,7 +91,7 @@ PlaylistElement :: configure(const xmlpp::Element & element)
UniqueId::IdType idValue;
if (!(attribute = element.get_attribute(idAttrName))) {
std::string eMsg = "Missing attribute ";
std::string eMsg = "missing attribute ";
eMsg += idAttrName;
throw std::invalid_argument(eMsg);
}
@ -105,7 +100,7 @@ PlaylistElement :: configure(const xmlpp::Element & element)
id.reset(new UniqueId(idValue));
if (!(attribute = element.get_attribute(relativeOffsetAttrName))) {
std::string eMsg = "Missing attribute ";
std::string eMsg = "missing attribute ";
eMsg += relativeOffsetAttrName;
throw std::invalid_argument(eMsg);
}
@ -117,32 +112,20 @@ PlaylistElement :: configure(const xmlpp::Element & element)
xmlpp::Node::NodeList::iterator it = childNodes.begin();
if (it == childNodes.end()) {
std::string eMsg = "Missing ";
std::string eMsg = "missing ";
eMsg += audioClipElementName;
eMsg += " XML element";
throw std::invalid_argument(eMsg);
}
const xmlpp::Element * audioClipElement
const xmlpp::Element * audioClipElement
= dynamic_cast<const xmlpp::Element*> (*it);
if (!(attribute= audioClipElement->get_attribute(audioClipIdAttrName))) {
std::string eMsg = "Missing ";
eMsg += audioClipElementName;
eMsg += "attribute ";
eMsg += audioClipIdAttrName;
throw std::invalid_argument(eMsg);
}
std::stringstream audioClipStrStr;
UniqueId::IdType audioClipIdValue;
audioClipStrStr.str(attribute->get_value());
audioClipStrStr >> audioClipIdValue;
audioClipId.reset(new UniqueId(audioClipIdValue));
audioClip.reset(new AudioClip);
audioClip->configure(*audioClipElement); // may throw exception
++it;
if (it != childNodes.end()) {
std::string eMsg = "More than one ";
std::string eMsg = "more than one ";
eMsg += audioClipElementName;
eMsg += " XML element";
throw std::invalid_argument(eMsg);

View file

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.1 $
Version : $Revision: 1.2 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/PlaylistElementTest.cxx,v $
------------------------------------------------------------------------------*/
@ -108,8 +108,9 @@ PlaylistElementTest :: firstTest(void)
CPPUNIT_ASSERT(playlistElement->getId()->getId() == 707);
Ptr<const time_duration>::Ref relativeOffset
= playlistElement->getRelativeOffset();
CPPUNIT_ASSERT(relativeOffset->total_seconds() == 12*60 + 34);
CPPUNIT_ASSERT(playlistElement->getAudioClipId()->getId() == 10001);
CPPUNIT_ASSERT(relativeOffset->total_seconds() == 12*60 + 34);
CPPUNIT_ASSERT(playlistElement->getAudioClip()->getId()->getId()
== 10001);
} catch (std::invalid_argument &e) {
std::string eMsg = "semantic error in configuration file:\n";

View file

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.4 $
Version : $Revision: 1.5 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/PlaylistTest.cxx,v $
------------------------------------------------------------------------------*/
@ -120,16 +120,18 @@ PlaylistTest :: firstTest(void)
CPPUNIT_ASSERT(playlistElement->getId()->getId() == 101);
Ptr<const time_duration>::Ref relativeOffset
= playlistElement->getRelativeOffset();
CPPUNIT_ASSERT(relativeOffset->total_seconds() == 0);
CPPUNIT_ASSERT(playlistElement->getAudioClipId()->getId() == 10001);
CPPUNIT_ASSERT(relativeOffset->total_seconds() == 0);
CPPUNIT_ASSERT(playlistElement->getAudioClip()->getId()->getId()
== 10001);
++it;
CPPUNIT_ASSERT(it != playlist->end());
playlistElement = it->second;
CPPUNIT_ASSERT(playlistElement->getId()->getId() == 102);
relativeOffset = playlistElement->getRelativeOffset();
CPPUNIT_ASSERT(relativeOffset->total_seconds() == 60 * 60);
CPPUNIT_ASSERT(playlistElement->getAudioClipId()->getId() == 10002);
CPPUNIT_ASSERT(relativeOffset->total_seconds() == 60 * 60);
CPPUNIT_ASSERT(playlistElement->getAudioClip()->getId()->getId()
== 10002);
++it;
CPPUNIT_ASSERT(it == playlist->end());
@ -166,11 +168,14 @@ void
PlaylistTest :: addAudioClipTest(void)
throw (CPPUNIT_NS::Exception)
{
Ptr<UniqueId>::Ref audioClipId(new UniqueId(20001));
Ptr<UniqueId>::Ref clipId(new UniqueId(20001));
Ptr<time_duration>::Ref clipLength(new time_duration(0,30,0,0));
Ptr<AudioClip>::Ref audioClip(new AudioClip(clipId, clipLength));
Ptr<time_duration>::Ref relativeOffset(new time_duration(0,10,0,0));
// hour, min, sec, frac_sec
try {
playlist->addAudioClip(audioClipId, relativeOffset);
playlist->addAudioClip(audioClip, relativeOffset);
}
catch (std::invalid_argument &e) {
string eMsg = "addAudioClip returned with error: ";
@ -183,7 +188,8 @@ PlaylistTest :: addAudioClipTest(void)
++it;
Ptr<PlaylistElement>::Ref playlistElement = it->second;
CPPUNIT_ASSERT(playlistElement->getAudioClipId()->getId() == 20001);
CPPUNIT_ASSERT(playlistElement->getAudioClip()->getId()->getId()
== 20001);
Ptr<const time_duration>::Ref otherRelativeOffset
= playlistElement->getRelativeOffset();