1
0

id3_field.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. // The authors have released ID3Lib as Public Domain (PD) and claim no copyright,
  2. // patent or other intellectual property protection in this work. This means that
  3. // it may be modified, redistributed and used in commercial and non-commercial
  4. // software and hardware without restrictions. ID3Lib is distributed on an "AS IS"
  5. // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
  6. //
  7. // The ID3Lib authors encourage improvements and optimisations to be sent to the
  8. // ID3Lib coordinator, currently Dirk Mahoney ([email protected]). Approved
  9. // submissions may be altered, and will be included and released under these terms.
  10. //
  11. // Mon Nov 23 18:34:01 1998
  12. // improved/optimized/whatEVER jan-08-2006 benski
  13. #ifndef ID3LIB_FIELD_H
  14. #define ID3LIB_FIELD_H
  15. #include <wchar.h>
  16. #include "id3_types.h"
  17. #include "id3_error.h"
  18. // field flags
  19. #define ID3FF_NULL (1 << 0)
  20. #define ID3FF_NULLDIVIDE (1 << 1)
  21. #define ID3FF_ADJUSTENC (1 << 2)
  22. #define ID3FF_ADJUSTEDBY (1 << 3)
  23. enum ID3_TextEnc
  24. {
  25. ID3TE_ASCII = 0,
  26. ID3TE_UNICODE = 1, // UTF-16
  27. ID3TE_UTF16_BE = 2, // UTF-16 big endian, no BOM
  28. ID3TE_UTF8 = 3, // UTF-8
  29. };
  30. enum ID3_FieldType
  31. {
  32. ID3FTY_INTEGER = 0,
  33. ID3FTY_BITFIELD,
  34. ID3FTY_BINARY,
  35. ID3FTY_ASCIISTRING,
  36. ID3FTY_UNICODESTRING,
  37. ID3FTY_UTF8STRING,
  38. };
  39. enum ID3_FieldID
  40. {
  41. ID3FN_NOFIELD = 0,
  42. ID3FN_TEXTENC,
  43. ID3FN_TEXT,
  44. ID3FN_URL,
  45. ID3FN_DATA,
  46. ID3FN_DESCRIPTION,
  47. ID3FN_OWNER,
  48. ID3FN_EMAIL,
  49. ID3FN_RATING,
  50. ID3FN_FILENAME,
  51. ID3FN_LANGUAGE,
  52. ID3FN_PICTURETYPE,
  53. ID3FN_IMAGEFORMAT,
  54. ID3FN_MIMETYPE,
  55. ID3FN_TIMESTAMP,
  56. ID3FN_CONTENTTYPE,
  57. ID3FN_COUNTER,
  58. ID3FN_SYMBOL,
  59. ID3FN_VOLUMEADJ,
  60. ID3FN_NUMBITS,
  61. ID3FN_VOLCHGRIGHT,
  62. ID3FN_VOLCHGLEFT,
  63. ID3FN_PEAKVOLRIGHT,
  64. ID3FN_PEAKVOLLEFT,
  65. ID3FN_CD_TOC,
  66. ID3FN_LASTFIELDID
  67. };
  68. enum ID3_FrameID
  69. {
  70. ID3FID_NOFRAME = 0,
  71. ID3FID_ENCODEDBY,
  72. ID3FID_ORIGALBUM,
  73. ID3FID_PUBLISHER,
  74. ID3FID_ENCODERSETTINGS,
  75. ID3FID_ORIGFILENAME,
  76. ID3FID_LANGUAGE,
  77. ID3FID_PARTINSET,
  78. ID3FID_DATE,
  79. ID3FID_TIME,
  80. ID3FID_RECORDINGDATES,
  81. ID3FID_MEDIATYPE,
  82. ID3FID_FILETYPE,
  83. ID3FID_NETRADIOSTATION,
  84. ID3FID_NETRADIOOWNER,
  85. ID3FID_LYRICIST,
  86. ID3FID_ORIGARTIST,
  87. ID3FID_ORIGLYRICIST,
  88. ID3FID_CONTENTGROUP,
  89. ID3FID_TITLE,
  90. ID3FID_SUBTITLE,
  91. ID3FID_LEADARTIST,
  92. ID3FID_BAND,
  93. ID3FID_CONDUCTOR,
  94. ID3FID_MIXARTIST,
  95. ID3FID_ALBUM,
  96. ID3FID_YEAR,
  97. ID3FID_COMPOSER,
  98. ID3FID_COPYRIGHT,
  99. ID3FID_PRODUCEDNOTICE,
  100. ID3FID_CONTENTTYPE,
  101. ID3FID_TRACKNUM,
  102. ID3FID_USERTEXT,
  103. ID3FID_COMMENT,
  104. ID3FID_TERMSOFUSE,
  105. ID3FID_UNSYNCEDLYRICS,
  106. ID3FID_SYNCEDLYRICS,
  107. ID3FID_SYNCEDTEMPOCODE,
  108. ID3FID_WWWAUDIOFILE,
  109. ID3FID_WWWARTIST,
  110. ID3FID_WWWAUDIOSOURCE,
  111. ID3FID_WWWCOMMERCIALINFO,
  112. ID3FID_WWWCOPYRIGHT,
  113. ID3FID_WWWPUBLISHER,
  114. ID3FID_WWWPAYMENT,
  115. ID3FID_WWWRADIOPAGE,
  116. ID3FID_WWWUSER,
  117. ID3FID_INVOLVEDPEOPLE,
  118. ID3FID_PICTURE,
  119. ID3FID_GENERALOBJECT,
  120. ID3FID_UNIQUEFILEID,
  121. ID3FID_PRIVATE,
  122. ID3FID_PLAYCOUNTER,
  123. ID3FID_POPULARIMETER,
  124. ID3FID_CRYPTOREG,
  125. ID3FID_GROUPINGREG,
  126. ID3FID_SIGNATURE,
  127. ID3FID_MCDI,
  128. ID3FID_BPM,
  129. ID3FID_KEY,
  130. ID3FID_MOOD,
  131. ID3FID_ISRC,
  132. ID3FID_RECORDINGTIME,
  133. ID3FID_COMPILATION,
  134. ID3FID_ALBUMSORT,
  135. ID3FID_ALBUMARTISTSORT,
  136. ID3FID_PERFORMERSORT,
  137. ID3FID_COMPOSERSORT,
  138. ID3FID_TITLESORT,
  139. ID3FID_REPLAYGAIN,
  140. ID3FID_VOLUMEADJ,
  141. ID3FID_INVOLVEDPEOPLE2,
  142. ID3FID_CREDITS,
  143. ID3FID_ENCODINGTIME,
  144. ID3FID_FILEOWNER,
  145. ID3FID_LENGTH,
  146. ID3FID_ORIGYEAR,
  147. ID3FID_ORIGRELEASETIME,
  148. ID3FID_RELEASETIME,
  149. ID3FID_SETSUBTITLE,
  150. ID3FID_TAGGINGTIME,
  151. ID3FID_PLAYLISTDELAY,
  152. ID3FID_PODCAST,
  153. ID3FID_PODCASTCATEGORY,
  154. ID3FID_PODCASTDESC,
  155. ID3FID_PODCASTID,
  156. ID3FID_PODCASTURL,
  157. };
  158. enum ID3_VerCtl
  159. {
  160. ID3VC_HIGHER = 0,
  161. ID3VC_LOWER
  162. };
  163. struct ID3_FieldDef
  164. {
  165. ID3_FieldID id;
  166. ID3_FieldType type;
  167. lsint fixedLength;
  168. uchar version;
  169. uchar revision;
  170. ID3_VerCtl control;
  171. luint flags;
  172. ID3_FieldID linkedField;
  173. };
  174. class ID3_Frame;
  175. // TODO: add minimum/maximum version & revision
  176. struct ID3_FrameDef
  177. {
  178. ID3_FrameID id;
  179. char *shortTextID;
  180. char *longTextID;
  181. bool tagDiscard;
  182. bool fileDiscard;
  183. bool (*parseHandler)(ID3_Frame *frame);
  184. ID3_FieldDef *fieldDefs;
  185. };
  186. class ID3_Field
  187. {
  188. public:
  189. ID3_Field(void);
  190. ~ID3_Field(void);
  191. void Clear(void);
  192. luint Size(void);
  193. luint GetNumTextItems(void);
  194. // integer field functions
  195. //ID3_Field& operator= (luint newData);
  196. void Set(luint newData);
  197. luint Get(void);
  198. // Unicode string field functions
  199. //ID3_Field& operator= (wchar_t *string);
  200. void SetUnicode(const wchar_t *string);
  201. luint GetUnicode(wchar_t *buffer, luint maxChars, luint itemNum = 1);
  202. void AddUnicode(const wchar_t *string);
  203. // ASCII string field functions
  204. //ID3_Field& operator= (char *string);
  205. void SetLatin(const char *string);
  206. void SetLocal(const char *string);
  207. void SetUTF8(const char *string);
  208. luint GetLocal(char *buffer, luint maxChars, luint itemNum = 1);
  209. luint GetLatin(char *buffer, luint maxChars, luint itemNum = 1);
  210. void AddLocal(const char *string);
  211. void AddLatin(const char *string);
  212. // binary field functions
  213. void Set(uchar *newData, luint newSize);
  214. void Get(uchar *buffer, luint buffLength);
  215. // *** PRIVATE INTERNAL DATA - DO NOT USE *** PRIVATE INTERNAL DATA - DO NOT USE ***
  216. luint BinSize(bool withExtras = true);
  217. bool HasChanged(void);
  218. void SetVersion(uchar ver, uchar rev);
  219. luint Render(uchar *buffer);
  220. luint Parse(uchar *buffer, luint posn, luint buffSize);
  221. ID3_FieldID name; // the ID of this field
  222. ID3_FieldType type; // what type is this field or should be
  223. lsint fixedLength; // if this is positive, the length of the field is fixed
  224. uchar ioVersion; // specific version
  225. uchar ioRevision; // specific revision
  226. ID3_VerCtl control; // render if ver/rev is higher, or lower than frame::version, frame::revision?
  227. luint flags; // special field flags
  228. uchar version; // the version being rendered/parsed
  229. uchar revision; // the revision being rendered/parsed
  230. bool hasChanged; // has the field changed since the last parse/render?
  231. protected:
  232. luint RenderInteger (uchar *buffer);
  233. luint RenderLatinString(uchar *buffer);
  234. luint RenderUnicodeString (uchar *buffer);
  235. luint RenderUTF8String(uchar *buffer);
  236. luint RenderBinary (uchar *buffer);
  237. luint ParseInteger (uchar *buffer, luint posn, luint buffSize);
  238. luint ParseASCIIString (uchar *buffer, luint posn, luint buffSize);
  239. luint ParseUnicodeString (uchar *buffer, luint posn, luint buffSize);
  240. luint ParseUTF8String(uchar *buffer, luint posn, luint buffSize);
  241. luint ParseBinary (uchar *buffer, luint posn, luint buffSize);
  242. uchar *data;
  243. luint size;
  244. };
  245. ID3_FrameDef *ID3_FindFrameDef (ID3_FrameID id);
  246. ID3_FrameID ID3_FindFrameID(const char *id);
  247. #endif