tagparser/tagtarget.cpp

101 lines
2.7 KiB
C++
Raw Normal View History

2015-09-06 19:57:33 +02:00
#include "./tagtarget.h"
2015-04-22 19:22:01 +02:00
2015-09-06 19:57:33 +02:00
#include "./matroska/matroskatagid.h"
2015-04-22 19:22:01 +02:00
#include <c++utilities/conversion/stringconversion.h>
#include <list>
using namespace std;
using namespace ConversionUtilities;
namespace Media {
2016-05-26 01:59:22 +02:00
/*!
* \brief Returns a string representation for the specified \a tagTargetLevel.
*/
const char *tagTargetLevelName(TagTargetLevel tagTargetLevel)
{
switch(tagTargetLevel) {
case TagTargetLevel::Shot:
return "shot";
case TagTargetLevel::Subtrack:
return "subtrack, part, movement, scene";
case TagTargetLevel::Track:
return "track, song, chapter";
case TagTargetLevel::Part:
return "part, session";
case TagTargetLevel::Album:
return "album, opera, concert, movie, episode";
case TagTargetLevel::Edition:
return "edition, issue, volume, opus, season, sequel";
case TagTargetLevel::Collection:
return "collection";
default:
return "";
}
}
2016-05-14 00:24:01 +02:00
/*!
* \class Media::TagTarget
* \brief The TagTarget class specifies the target of a tag.
*
* Tags might only target a specific track, chapter, ...
*
* Specifying a target is currently only fully supported by Matroska.
*
* Since Ogg saves tags at stream level, the stream can be specified
* by passing a TagTarget instance to OggContainer::createTag().
* However, only the first track in the tracks() array is considered
* and any other values are just ignored.
*
* In any other tag formats, the specified target is (currently)
* completely ignored.
*/
2015-04-22 19:22:01 +02:00
/*!
* \brief Returns the string representation of the current instance.
2016-05-26 01:59:22 +02:00
* \remarks Uses the specified \a tagTargetLevel if no levelName() is assigned.
2015-04-22 19:22:01 +02:00
*/
2016-05-26 01:59:22 +02:00
string TagTarget::toString(TagTargetLevel tagTargetLevel) const
2015-04-22 19:22:01 +02:00
{
list<string> parts;
parts.emplace_back();
string &level = parts.back();
if(this->level()) {
level.append("level " + numberToString(this->level()));
}
string name;
if(!levelName().empty()) {
name = levelName();
} else {
2016-05-26 01:59:22 +02:00
name = tagTargetLevelName(tagTargetLevel);
2015-04-22 19:22:01 +02:00
}
if(!name.empty()) {
if(!level.empty()) {
level.append(" ");
}
level.append("»");
level.append(name);
level.append("«");
}
if(level.empty()) {
level.append("undefined target");
}
for(auto v : tracks()) {
parts.emplace_back("track " + numberToString(v));
}
for(auto v : chapters()) {
parts.emplace_back("chapter " + numberToString(v));
}
for(auto v : editions()) {
parts.emplace_back("edition " + numberToString(v));
}
for(auto v : attachments()) {
parts.emplace_back("attachment " + numberToString(v));
}
return joinStrings(parts, ", ");
}
}