strawberry-audio-player-win.../3rdparty/taglib/mpeg/id3v2/frames/eventtimingcodesframe.cpp

127 lines
4.6 KiB
C++
Raw Normal View History

2018-05-10 15:29:28 +02:00
/***************************************************************************
copyright : (C) 2014 by Urs Fleisch
email : ufleisch@users.sourceforge.net
***************************************************************************/
/***************************************************************************
* This library is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License version *
* 2.1 as published by the Free Software Foundation. *
* *
* This library is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA *
* 02110-1301 USA *
* *
* Alternatively, this file is available under the Mozilla Public *
* License Version 1.1. You may obtain a copy of the License at *
* http://www.mozilla.org/MPL/ *
***************************************************************************/
#include "eventtimingcodesframe.h"
2020-06-26 23:30:30 +02:00
#include "tbytevectorlist.h"
#include "id3v2tag.h"
#include "tdebug.h"
#include "tpropertymap.h"
2018-05-10 15:29:28 +02:00
using namespace Strawberry_TagLib::TagLib;
2018-05-10 15:29:28 +02:00
using namespace ID3v2;
2020-06-13 19:02:42 +02:00
class EventTimingCodesFrame::EventTimingCodesFramePrivate {
public:
2020-06-26 23:30:30 +02:00
explicit EventTimingCodesFramePrivate() : timestampFormat(EventTimingCodesFrame::AbsoluteMilliseconds) {}
2018-05-10 15:29:28 +02:00
EventTimingCodesFrame::TimestampFormat timestampFormat;
EventTimingCodesFrame::SynchedEventList synchedEvents;
};
////////////////////////////////////////////////////////////////////////////////
// public members
////////////////////////////////////////////////////////////////////////////////
EventTimingCodesFrame::EventTimingCodesFrame() : Frame("ETCO"), d(new EventTimingCodesFramePrivate()) {}
2018-05-10 15:29:28 +02:00
EventTimingCodesFrame::EventTimingCodesFrame(const ByteVector &data) : Frame(data), d(new EventTimingCodesFramePrivate()) {
2018-05-10 15:29:28 +02:00
setData(data);
}
2020-06-13 19:02:42 +02:00
EventTimingCodesFrame::~EventTimingCodesFrame() {
2018-05-10 15:29:28 +02:00
delete d;
}
2020-06-13 19:02:42 +02:00
String EventTimingCodesFrame::toString() const {
2018-05-10 15:29:28 +02:00
return String();
}
EventTimingCodesFrame::TimestampFormat
2020-06-13 19:02:42 +02:00
EventTimingCodesFrame::timestampFormat() const {
2018-05-10 15:29:28 +02:00
return d->timestampFormat;
}
EventTimingCodesFrame::SynchedEventList
2020-06-13 19:02:42 +02:00
EventTimingCodesFrame::synchedEvents() const {
2018-05-10 15:29:28 +02:00
return d->synchedEvents;
}
void EventTimingCodesFrame::setTimestampFormat(
2020-06-13 19:02:42 +02:00
EventTimingCodesFrame::TimestampFormat f) {
2018-05-10 15:29:28 +02:00
d->timestampFormat = f;
}
void EventTimingCodesFrame::setSynchedEvents(
2020-06-13 19:02:42 +02:00
const EventTimingCodesFrame::SynchedEventList &e) {
2018-05-10 15:29:28 +02:00
d->synchedEvents = e;
}
////////////////////////////////////////////////////////////////////////////////
// protected members
////////////////////////////////////////////////////////////////////////////////
2020-06-13 19:02:42 +02:00
void EventTimingCodesFrame::parseFields(const ByteVector &data) {
2020-06-26 23:30:30 +02:00
const size_t end = data.size();
2020-06-13 19:02:42 +02:00
if (end < 1) {
2018-05-10 15:29:28 +02:00
debug("An event timing codes frame must contain at least 1 byte.");
return;
}
d->timestampFormat = TimestampFormat(data[0]);
2020-06-26 23:30:30 +02:00
size_t pos = 1;
2018-05-10 15:29:28 +02:00
d->synchedEvents.clear();
2020-06-13 19:02:42 +02:00
while (pos + 4 < end) {
2018-05-10 15:29:28 +02:00
EventType type = static_cast<EventType>(static_cast<unsigned char>(data[pos++]));
2020-06-26 23:30:30 +02:00
unsigned int time = data.toUInt32BE(pos);
2018-05-10 15:29:28 +02:00
pos += 4;
d->synchedEvents.append(SynchedEvent(time, type));
}
2018-05-10 15:29:28 +02:00
}
2020-06-13 19:02:42 +02:00
ByteVector EventTimingCodesFrame::renderFields() const {
2018-05-10 15:29:28 +02:00
ByteVector v;
v.append(char(d->timestampFormat));
for (SynchedEventList::ConstIterator it = d->synchedEvents.begin(); it != d->synchedEvents.end(); ++it) {
2018-05-10 15:29:28 +02:00
const SynchedEvent &entry = *it;
v.append(char(entry.type));
2020-06-26 23:30:30 +02:00
v.append(ByteVector::fromUInt32BE(entry.time));
2018-05-10 15:29:28 +02:00
}
return v;
2018-05-10 15:29:28 +02:00
}
////////////////////////////////////////////////////////////////////////////////
// private members
////////////////////////////////////////////////////////////////////////////////
EventTimingCodesFrame::EventTimingCodesFrame(const ByteVector &data, Header *h) : Frame(h), d(new EventTimingCodesFramePrivate()) {
2018-05-10 15:29:28 +02:00
parseFields(fieldData(data));
}