File indexing completed on 2025-01-05 04:32:39
0001 /*************************************************************************** 0002 copyright : (C) 2014 by Urs Fleisch 0003 email : ufleisch@users.sourceforge.net 0004 ***************************************************************************/ 0005 0006 /*************************************************************************** 0007 * This library is free software; you can redistribute it and/or modify * 0008 * it under the terms of the GNU Lesser General Public License version * 0009 * 2.1 as published by the Free Software Foundation. * 0010 * * 0011 * This library is distributed in the hope that it will be useful, but * 0012 * WITHOUT ANY WARRANTY; without even the implied warranty of * 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 0014 * Lesser General Public License for more details. * 0015 * * 0016 * You should have received a copy of the GNU Lesser General Public * 0017 * License along with this library; if not, write to the Free Software * 0018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 0019 * 02110-1301 USA * 0020 * * 0021 * Alternatively, this file is available under the Mozilla Public * 0022 * License Version 1.1. You may obtain a copy of the License at * 0023 * http://www.mozilla.org/MPL/ * 0024 ***************************************************************************/ 0025 0026 #define BUILD_WITH_KID3 0027 #include "eventtimingcodesframe.h" 0028 #include <tbytevectorlist.h> 0029 #include <id3v2tag.h> 0030 #ifdef BUILD_WITH_KID3 0031 #define debug(s) 0032 #else 0033 #include <tdebug.h> 0034 #endif 0035 0036 using namespace TagLib; 0037 using namespace ID3v2; 0038 0039 class EventTimingCodesFrame::EventTimingCodesFramePrivate 0040 { 0041 public: 0042 EventTimingCodesFramePrivate() : 0043 timestampFormat(EventTimingCodesFrame::AbsoluteMilliseconds) {} 0044 EventTimingCodesFrame::TimestampFormat timestampFormat; 0045 EventTimingCodesFrame::SynchedEventList synchedEvents; 0046 }; 0047 0048 //////////////////////////////////////////////////////////////////////////////// 0049 // public members 0050 //////////////////////////////////////////////////////////////////////////////// 0051 0052 EventTimingCodesFrame::EventTimingCodesFrame() : 0053 Frame("ETCO") 0054 { 0055 d = new EventTimingCodesFramePrivate; 0056 } 0057 0058 EventTimingCodesFrame::EventTimingCodesFrame(const ByteVector &data) : 0059 Frame(data) 0060 { 0061 d = new EventTimingCodesFramePrivate; 0062 setData(data); 0063 } 0064 0065 EventTimingCodesFrame::~EventTimingCodesFrame() 0066 { 0067 delete d; 0068 } 0069 0070 String EventTimingCodesFrame::toString() const 0071 { 0072 return String(); 0073 } 0074 0075 EventTimingCodesFrame::TimestampFormat 0076 EventTimingCodesFrame::timestampFormat() const 0077 { 0078 return d->timestampFormat; 0079 } 0080 0081 EventTimingCodesFrame::SynchedEventList 0082 EventTimingCodesFrame::synchedEvents() const 0083 { 0084 return d->synchedEvents; 0085 } 0086 0087 void EventTimingCodesFrame::setTimestampFormat( 0088 EventTimingCodesFrame::TimestampFormat f) 0089 { 0090 d->timestampFormat = f; 0091 } 0092 0093 void EventTimingCodesFrame::setSynchedEvents( 0094 const EventTimingCodesFrame::SynchedEventList &e) 0095 { 0096 d->synchedEvents = e; 0097 } 0098 0099 //////////////////////////////////////////////////////////////////////////////// 0100 // protected members 0101 //////////////////////////////////////////////////////////////////////////////// 0102 0103 void EventTimingCodesFrame::parseFields(const ByteVector &data) 0104 { 0105 const int end = data.size(); 0106 if(end < 1) { 0107 debug("An event timing codes frame must contain at least 1 byte."); 0108 return; 0109 } 0110 0111 d->timestampFormat = TimestampFormat(data[0]); 0112 0113 int pos = 1; 0114 d->synchedEvents.clear(); 0115 while(pos + 4 < end) { 0116 EventType type = EventType(uchar(data[pos++])); 0117 uint time = data.mid(pos, 4).toUInt(true); 0118 pos += 4; 0119 d->synchedEvents.append(SynchedEvent(time, type)); 0120 } 0121 } 0122 0123 ByteVector EventTimingCodesFrame::renderFields() const 0124 { 0125 ByteVector v; 0126 0127 v.append(char(d->timestampFormat)); 0128 for(SynchedEventList::ConstIterator it = d->synchedEvents.begin(); 0129 it != d->synchedEvents.end(); 0130 ++it) { 0131 const SynchedEvent &entry = *it; 0132 v.append(char(entry.type)); 0133 v.append(ByteVector::fromUInt(entry.time)); 0134 } 0135 0136 return v; 0137 } 0138 0139 //////////////////////////////////////////////////////////////////////////////// 0140 // private members 0141 //////////////////////////////////////////////////////////////////////////////// 0142 0143 EventTimingCodesFrame::EventTimingCodesFrame(const ByteVector &data, Header *h) 0144 : Frame(h) 0145 { 0146 d = new EventTimingCodesFramePrivate(); 0147 parseFields(fieldData(data)); 0148 }