1
0

id3_field.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  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 10/30/00 JF
  13. #include <windows.h>
  14. #include <string.h>
  15. #include "id3_field.h"
  16. static ID3_FieldDef ID3FD_URL[] =
  17. {
  18. {ID3FN_URL, ID3FTY_ASCIISTRING, -1, 2, 0, ID3VC_HIGHER, NULL, ID3FN_NOFIELD},
  19. {ID3FN_NOFIELD }
  20. };
  21. static ID3_FieldDef ID3FD_UserURL[] =
  22. {
  23. // FIELD FIELD FIXED RENDER IF OR
  24. // NAME TYPE LEN VER REV WHAT? FLAGS LINKED FIELD
  25. {ID3FN_TEXTENC, ID3FTY_INTEGER, 1, 2, 0, ID3VC_HIGHER, NULL, ID3FN_NOFIELD },
  26. {ID3FN_DESCRIPTION, ID3FTY_ASCIISTRING, -1, 2, 0, ID3VC_HIGHER, ID3FF_NULL | ID3FF_ADJUSTENC, ID3FN_NOFIELD },
  27. {ID3FN_URL, ID3FTY_ASCIISTRING, -1, 2, 0, ID3VC_HIGHER, NULL, ID3FN_NOFIELD },
  28. {ID3FN_NOFIELD }
  29. };
  30. static ID3_FieldDef ID3FD_Text[] =
  31. {
  32. // FIELD FIELD FIXED RENDER IF OR
  33. // NAME TYPE LEN VER REV WHAT? FLAGS LINKED FIELD
  34. {ID3FN_TEXTENC, ID3FTY_INTEGER, 1, 2, 0, ID3VC_HIGHER, NULL, ID3FN_NOFIELD },
  35. {ID3FN_TEXT, ID3FTY_ASCIISTRING, -1, 2, 0, ID3VC_HIGHER, ID3FF_ADJUSTENC, ID3FN_NOFIELD },
  36. {ID3FN_NOFIELD }
  37. };
  38. static ID3_FieldDef ID3FD_UserText[] =
  39. {
  40. // FIELD FIELD FIXED RENDER IF OR
  41. // NAME TYPE LEN VER REV WHAT? FLAGS LINKED FIELD
  42. {ID3FN_TEXTENC, ID3FTY_INTEGER, 1, 2, 0, ID3VC_HIGHER, NULL, ID3FN_NOFIELD },
  43. {ID3FN_DESCRIPTION, ID3FTY_ASCIISTRING, -1, 2, 0, ID3VC_HIGHER, ID3FF_NULL | ID3FF_ADJUSTENC, ID3FN_NOFIELD },
  44. {ID3FN_TEXT, ID3FTY_ASCIISTRING, -1, 2, 0, ID3VC_HIGHER, ID3FF_ADJUSTENC, ID3FN_NOFIELD },
  45. {ID3FN_NOFIELD }
  46. };
  47. static ID3_FieldDef ID3FD_GeneralText[] =
  48. {
  49. // FIELD FIELD FIXED RENDER IF OR
  50. // NAME TYPE LEN VER REV WHAT? FLAGS LINKED FIELD
  51. {ID3FN_TEXTENC, ID3FTY_INTEGER, 1, 2, 0, ID3VC_HIGHER, NULL, ID3FN_NOFIELD },
  52. {ID3FN_LANGUAGE, ID3FTY_ASCIISTRING, 3, 2, 0, ID3VC_HIGHER, NULL, ID3FN_NOFIELD },
  53. {ID3FN_DESCRIPTION, ID3FTY_ASCIISTRING, -1, 2, 0, ID3VC_HIGHER, ID3FF_NULL | ID3FF_ADJUSTENC, ID3FN_NOFIELD },
  54. {ID3FN_TEXT, ID3FTY_ASCIISTRING, -1, 2, 0, ID3VC_HIGHER, ID3FF_ADJUSTENC, ID3FN_NOFIELD },
  55. {ID3FN_NOFIELD }
  56. };
  57. static ID3_FieldDef ID3FD_Picture[] =
  58. {
  59. // FIELD FIELD FIXED RENDER IF OR
  60. // NAME TYPE LEN VER REV WHAT? FLAGS LINKED FIELD
  61. {ID3FN_TEXTENC, ID3FTY_INTEGER, 1, 2, 0, ID3VC_HIGHER, NULL, ID3FN_NOFIELD },
  62. {ID3FN_IMAGEFORMAT, ID3FTY_ASCIISTRING, 3, 2, 0, ID3VC_LOWER, NULL, ID3FN_NOFIELD },
  63. {ID3FN_MIMETYPE, ID3FTY_ASCIISTRING, -1, 3, 0, ID3VC_HIGHER, ID3FF_NULL, ID3FN_NOFIELD },
  64. {ID3FN_PICTURETYPE, ID3FTY_INTEGER, 1, 2, 0, ID3VC_HIGHER, NULL, ID3FN_NOFIELD },
  65. {ID3FN_DESCRIPTION, ID3FTY_ASCIISTRING, -1, 2, 0, ID3VC_HIGHER, ID3FF_NULL | ID3FF_ADJUSTENC, ID3FN_NOFIELD },
  66. {ID3FN_DATA, ID3FTY_BINARY, -1, 2, 0, ID3VC_HIGHER, NULL, ID3FN_NOFIELD },
  67. {ID3FN_NOFIELD }
  68. };
  69. static ID3_FieldDef ID3FD_GEO[] =
  70. {
  71. // FIELD FIELD FIXED RENDER IF OR
  72. // NAME TYPE LEN VER REV WHAT? FLAGS LINKED FIELD
  73. {ID3FN_TEXTENC, ID3FTY_INTEGER, 1, 2, 0, ID3VC_HIGHER, NULL, ID3FN_NOFIELD },
  74. {ID3FN_MIMETYPE, ID3FTY_ASCIISTRING, -1, 2, 0, ID3VC_HIGHER, ID3FF_NULL, ID3FN_NOFIELD },
  75. {ID3FN_FILENAME, ID3FTY_ASCIISTRING, -1, 2, 0, ID3VC_HIGHER, ID3FF_NULL | ID3FF_ADJUSTENC, ID3FN_NOFIELD },
  76. {ID3FN_DESCRIPTION, ID3FTY_ASCIISTRING, -1, 2, 0, ID3VC_HIGHER, ID3FF_NULL | ID3FF_ADJUSTENC, ID3FN_NOFIELD },
  77. {ID3FN_DATA, ID3FTY_BINARY, -1, 2, 0, ID3VC_HIGHER, NULL, ID3FN_NOFIELD },
  78. {ID3FN_NOFIELD }
  79. };
  80. static ID3_FieldDef ID3FD_UFI[] =
  81. {
  82. // FIELD FIELD FIXED RENDER IF OR
  83. // NAME TYPE LEN VER REV WHAT? FLAGS LINKED FIELD
  84. {ID3FN_OWNER, ID3FTY_ASCIISTRING, -1, 2, 0, ID3VC_HIGHER, ID3FF_NULL, ID3FN_NOFIELD },
  85. {ID3FN_DATA, ID3FTY_BINARY, -1, 2, 0, ID3VC_HIGHER, NULL, ID3FN_NOFIELD },
  86. {ID3FN_NOFIELD }
  87. };
  88. static ID3_FieldDef ID3FD_PRIVATE[] =
  89. {
  90. // FIELD FIELD FIXED RENDER IF OR
  91. // NAME TYPE LEN VER REV WHAT? FLAGS LINKED FIELD
  92. {ID3FN_OWNER, ID3FTY_ASCIISTRING, -1, 3, 0, ID3VC_HIGHER, ID3FF_NULL, ID3FN_NOFIELD },
  93. {ID3FN_DATA, ID3FTY_BINARY, -1, 3, 0, ID3VC_HIGHER, NULL, ID3FN_NOFIELD },
  94. {ID3FN_NOFIELD }
  95. };
  96. static ID3_FieldDef ID3FD_PlayCounter[] =
  97. {
  98. // FIELD FIELD FIXED RENDER IF OR
  99. // NAME TYPE LEN VER REV WHAT? FLAGS LINKED FIELD
  100. {ID3FN_COUNTER, ID3FTY_INTEGER, 4, 2, 0, ID3VC_HIGHER, NULL, ID3FN_NOFIELD },
  101. {ID3FN_NOFIELD }
  102. };
  103. static ID3_FieldDef ID3FD_Popularimeter[] =
  104. {
  105. // FIELD FIELD FIXED RENDER IF OR
  106. // NAME TYPE LEN VER REV WHAT? FLAGS LINKED FIELD
  107. {ID3FN_EMAIL, ID3FTY_ASCIISTRING, -1, 2, 0, ID3VC_HIGHER, ID3FF_NULL, ID3FN_NOFIELD },
  108. {ID3FN_RATING, ID3FTY_INTEGER, 1, 2, 0, ID3VC_HIGHER, NULL, ID3FN_NOFIELD },
  109. {ID3FN_COUNTER, ID3FTY_INTEGER, 4, 2, 0, ID3VC_HIGHER, NULL, ID3FN_NOFIELD },
  110. {ID3FN_NOFIELD }
  111. };
  112. static ID3_FieldDef ID3FD_Registration[] =
  113. {
  114. // FIELD FIELD FIXED RENDER IF OR
  115. // NAME TYPE LEN VER REV WHAT? FLAGS LINKED FIELD
  116. {ID3FN_OWNER, ID3FTY_ASCIISTRING, -1, 3, 0, ID3VC_HIGHER, ID3FF_NULL, ID3FN_NOFIELD },
  117. {ID3FN_SYMBOL, ID3FTY_INTEGER, 1, 3, 0, ID3VC_HIGHER, NULL, ID3FN_NOFIELD },
  118. {ID3FN_DATA, ID3FTY_BINARY, -1, 3, 0, ID3VC_HIGHER, NULL, ID3FN_NOFIELD },
  119. {ID3FN_NOFIELD }
  120. };
  121. static ID3_FieldDef ID3FD_InvolvedPeople[] =
  122. {
  123. // FIELD FIELD FIXED RENDER IF OR
  124. // NAME TYPE LEN VER REV WHAT? FLAGS LINKED FIELD
  125. {ID3FN_TEXTENC, ID3FTY_INTEGER, 1, 2, 0, ID3VC_HIGHER, NULL, ID3FN_NOFIELD },
  126. {ID3FN_TEXT, ID3FTY_ASCIISTRING, -1, 2, 0, ID3VC_HIGHER, ID3FF_NULL | ID3FF_NULLDIVIDE | ID3FF_ADJUSTENC, ID3FN_NOFIELD },
  127. {ID3FN_NOFIELD }
  128. };
  129. static ID3_FieldDef ID3FD_Volume[] =
  130. {
  131. // FIELD FIELD FIXED RENDER IF OR
  132. // NAME TYPE LEN VER REV WHAT? FLAGS LINKED FIELD
  133. {ID3FN_VOLUMEADJ, ID3FTY_INTEGER, 1, 2, 0, ID3VC_HIGHER, NULL, ID3FN_NOFIELD },
  134. {ID3FN_NUMBITS, ID3FTY_INTEGER, 1, 2, 0, ID3VC_HIGHER, NULL, ID3FN_NOFIELD },
  135. {ID3FN_VOLCHGRIGHT, ID3FTY_BITFIELD, -1, 2, 0, ID3VC_HIGHER, ID3FF_ADJUSTEDBY, ID3FN_NUMBITS },
  136. {ID3FN_VOLCHGLEFT, ID3FTY_BITFIELD, -1, 2, 0, ID3VC_HIGHER, ID3FF_ADJUSTEDBY, ID3FN_NUMBITS },
  137. {ID3FN_PEAKVOLRIGHT, ID3FTY_BITFIELD, -1, 2, 0, ID3VC_HIGHER, ID3FF_ADJUSTEDBY, ID3FN_NUMBITS },
  138. {ID3FN_PEAKVOLLEFT, ID3FTY_BITFIELD, -1, 2, 0, ID3VC_HIGHER, ID3FF_ADJUSTEDBY, ID3FN_NUMBITS },
  139. {ID3FN_NOFIELD }
  140. };
  141. static ID3_FieldDef ID3FD_MCDI[] =
  142. {
  143. // FIELD FIELD FIXED RENDER IF OR
  144. // NAME TYPE LEN VER REV WHAT? FLAGS LINKED FIELD
  145. {ID3FN_CD_TOC, ID3FTY_BINARY, -1, 3, 0, ID3VC_HIGHER, NULL, ID3FN_NOFIELD},
  146. {ID3FN_NOFIELD }
  147. };
  148. static ID3_FieldDef ID3FD_Text_v2_4[] =
  149. {
  150. // FIELD FIELD FIXED RENDER IF OR
  151. // NAME TYPE LEN VER REV WHAT? FLAGS LINKED FIELD
  152. {ID3FN_TEXTENC, ID3FTY_INTEGER, 1, 4, 0, ID3VC_HIGHER, NULL, ID3FN_NOFIELD },
  153. {ID3FN_TEXT, ID3FTY_ASCIISTRING, -1, 4, 0, ID3VC_HIGHER, ID3FF_ADJUSTENC, ID3FN_NOFIELD },
  154. {ID3FN_NOFIELD }
  155. };
  156. static ID3_FieldDef ID3FD_Timestamp1[] =
  157. {
  158. // FIELD FIELD FIXED RENDER IF OR
  159. // NAME TYPE LEN VER REV WHAT? FLAGS LINKED FIELD
  160. {ID3FN_TIMESTAMP, ID3FTY_INTEGER, 1, 2, 0, ID3VC_HIGHER, NULL, ID3FN_NOFIELD },
  161. {ID3FN_DATA, ID3FTY_BINARY, -1, 3, 0, ID3VC_HIGHER, NULL, ID3FN_NOFIELD },
  162. {ID3FN_NOFIELD }
  163. };
  164. static ID3_FieldDef ID3FD_Timestamp2[] =
  165. {
  166. // FIELD FIELD FIXED RENDER IF OR
  167. // NAME TYPE LEN VER REV WHAT? FLAGS LINKED FIELD
  168. {ID3FN_TEXTENC, ID3FTY_INTEGER, 1, 2, 0, ID3VC_HIGHER, NULL, ID3FN_NOFIELD },
  169. {ID3FN_LANGUAGE, ID3FTY_ASCIISTRING, 3, 2, 0, ID3VC_HIGHER, NULL, ID3FN_NOFIELD },
  170. {ID3FN_TIMESTAMP, ID3FTY_INTEGER, 1, 2, 0, ID3VC_HIGHER, NULL, ID3FN_NOFIELD },
  171. {ID3FN_CONTENTTYPE, ID3FTY_INTEGER, 1, 2, 0, ID3VC_HIGHER, NULL, ID3FN_NOFIELD },
  172. {ID3FN_DESCRIPTION, ID3FTY_ASCIISTRING, -1, 2, 0, ID3VC_HIGHER, ID3FF_NULL | ID3FF_ADJUSTENC, ID3FN_NOFIELD },
  173. {ID3FN_NOFIELD }
  174. };
  175. static ID3_FrameDef ID3_FrameDefs[] =
  176. {
  177. //FRAME ID SHORTID LONGID PRI TAGDISCARD FILEDISCARD HANDLER FIELDDEFS
  178. {ID3FID_ENCODEDBY, "TEN", "TENC", false, true, NULL, ID3FD_Text },
  179. {ID3FID_ORIGALBUM, "TOT", "TOAL", false, false, NULL, ID3FD_Text },
  180. {ID3FID_PUBLISHER, "TPB", "TPUB", false, false, NULL, ID3FD_Text },
  181. {ID3FID_ENCODERSETTINGS, "TSS", "TSSE", false, false, NULL, ID3FD_Text },
  182. {ID3FID_ORIGFILENAME, "TOF", "TOFN", false, false, NULL, ID3FD_Text },
  183. {ID3FID_LANGUAGE, "TLA", "TLAN", false, false, NULL, ID3FD_Text },
  184. {ID3FID_PARTINSET, "TPA", "TPOS", false, false, NULL, ID3FD_Text },
  185. {ID3FID_DATE, "TDA", "TDAT", false, false, NULL, ID3FD_Text },
  186. {ID3FID_TIME, "TIM", "TIME", false, false, NULL, ID3FD_Text },
  187. {ID3FID_RECORDINGDATES, "TRD", "TRDA", false, false, NULL, ID3FD_Text },
  188. {ID3FID_MEDIATYPE, "TMT", "TMED", false, false, NULL, ID3FD_Text },
  189. {ID3FID_FILETYPE, "TFT", "TFLT", false, false, NULL, ID3FD_Text },
  190. {ID3FID_NETRADIOSTATION, "TRN", "TRSN", false, false, NULL, ID3FD_Text },
  191. {ID3FID_NETRADIOOWNER, "TRO", "TRSO", false, false, NULL, ID3FD_Text },
  192. {ID3FID_LYRICIST, "TXT", "TEXT", false, false, NULL, ID3FD_Text },
  193. {ID3FID_ORIGARTIST, "TOA", "TOPE", false, false, NULL, ID3FD_Text },
  194. {ID3FID_ORIGLYRICIST, "TOL", "TOLY", false, false, NULL, ID3FD_Text },
  195. {ID3FID_CONTENTGROUP, "TT1", "TIT1", false, false, NULL, ID3FD_Text },
  196. {ID3FID_TITLE, "TT2", "TIT2", false, false, NULL, ID3FD_Text },
  197. {ID3FID_SUBTITLE, "TT3", "TIT3", false, false, NULL, ID3FD_Text },
  198. {ID3FID_LEADARTIST, "TP1", "TPE1", false, false, NULL, ID3FD_Text },
  199. {ID3FID_BAND, "TP2", "TPE2", false, false, NULL, ID3FD_Text },
  200. {ID3FID_CONDUCTOR, "TP3", "TPE3", false, false, NULL, ID3FD_Text },
  201. {ID3FID_MIXARTIST, "TP4", "TPE4", false, false, NULL, ID3FD_Text },
  202. {ID3FID_ALBUM, "TAL", "TALB", false, false, NULL, ID3FD_Text },
  203. {ID3FID_YEAR, "TYE", "TYER", false, false, NULL, ID3FD_Text },
  204. {ID3FID_COMPOSER, "TCM", "TCOM", false, false, NULL, ID3FD_Text },
  205. {ID3FID_COPYRIGHT, "TCR", "TCOP", false, false, NULL, ID3FD_Text },
  206. {ID3FID_PRODUCEDNOTICE, " ", "TPRO", false, false, NULL, ID3FD_Text },
  207. {ID3FID_CONTENTTYPE, "TCO", "TCON", false, false, NULL, ID3FD_Text },
  208. {ID3FID_TRACKNUM, "TRK", "TRCK", false, false, NULL, ID3FD_Text },
  209. {ID3FID_USERTEXT, "TXX", "TXXX", false, false, NULL, ID3FD_UserText },
  210. {ID3FID_COMMENT, "COM", "COMM", false, false, NULL, ID3FD_GeneralText },
  211. {ID3FID_TERMSOFUSE, " ", "USER", false, false, NULL, ID3FD_GeneralText },
  212. {ID3FID_UNSYNCEDLYRICS, "ULT", "USLT", false, false, NULL, ID3FD_GeneralText },
  213. {ID3FID_SYNCEDLYRICS, "SLT", "SYLT", false, false, NULL, ID3FD_Timestamp2 },
  214. {ID3FID_SYNCEDTEMPOCODE, "STC", "SYTC", false, false, NULL, ID3FD_Timestamp1 },
  215. // URL Frames
  216. {ID3FID_WWWAUDIOFILE, "WAF", "WOAF", false, false, NULL, ID3FD_URL },
  217. {ID3FID_WWWARTIST, "WAR", "WOAR", false, false, NULL, ID3FD_URL },
  218. {ID3FID_WWWAUDIOSOURCE, "WAS", "WOAS", false, false, NULL, ID3FD_URL },
  219. {ID3FID_WWWCOMMERCIALINFO, "WCM", "WCOM", false, false, NULL, ID3FD_URL },
  220. {ID3FID_WWWCOPYRIGHT, "WCP", "WCOP", false, false, NULL, ID3FD_URL },
  221. {ID3FID_WWWPUBLISHER, "WPB", "WPUB", false, false, NULL, ID3FD_URL },
  222. {ID3FID_WWWPAYMENT, "WPY", "WPAY", false, false, NULL, ID3FD_URL },
  223. {ID3FID_WWWRADIOPAGE, "WRA", "WORS", false, false, NULL, ID3FD_URL },
  224. {ID3FID_WWWUSER, "WXX", "WXXX", false, false, NULL, ID3FD_UserURL },
  225. // misc frames
  226. {ID3FID_INVOLVEDPEOPLE, "IPL", "IPLS", false, false, NULL, ID3FD_InvolvedPeople },
  227. {ID3FID_PICTURE, "PIC", "APIC", false, false, NULL, ID3FD_Picture },
  228. {ID3FID_GENERALOBJECT, "GEO", "GEOB", false, false, NULL, ID3FD_GEO },
  229. {ID3FID_UNIQUEFILEID, "UFI", "UFID", false, false, NULL, ID3FD_UFI },
  230. {ID3FID_PRIVATE, " ", "PRIV", false, false, NULL, ID3FD_PRIVATE },
  231. {ID3FID_PLAYCOUNTER, "CNT", "PCNT", false, false, NULL, ID3FD_PlayCounter },
  232. {ID3FID_POPULARIMETER, "POP", "POPM", false, false, NULL, ID3FD_Popularimeter },
  233. {ID3FID_CRYPTOREG, " ", "ENCR", false, false, NULL, ID3FD_Registration },
  234. {ID3FID_GROUPINGREG, " ", "GRID", false, false, NULL, ID3FD_Registration },
  235. {ID3FID_SIGNATURE, " ", "SIGN", false, false, NULL, ID3FD_Registration },
  236. {ID3FID_MCDI, "MCI", "MCDI", false, false, NULL, ID3FD_MCDI},
  237. {ID3FID_BPM, "TBP", "TBPM", false, false, NULL, ID3FD_Text},
  238. {ID3FID_KEY, "TKE", "TKEY", false, false, NULL, ID3FD_Text},
  239. {ID3FID_MOOD, " ", "TMOO", false, false, NULL, ID3FD_Text},
  240. {ID3FID_ISRC, "TRC", "TSRC", false, false, NULL, ID3FD_Text},
  241. {ID3FID_RECORDINGTIME, " ", "TDRC", false, false, NULL, ID3FD_Text},
  242. {ID3FID_COMPILATION, "TCP", "TCMP", false, false, NULL, ID3FD_Text},
  243. {ID3FID_ALBUMSORT, "TSA", "TSOA", false, false, NULL, ID3FD_Text},
  244. {ID3FID_ALBUMARTISTSORT, "TS2", "TSO2", false, false, NULL, ID3FD_Text},
  245. {ID3FID_PERFORMERSORT, "TSP", "TSOP", false, false, NULL, ID3FD_Text},
  246. {ID3FID_COMPOSERSORT, "TSC", "TSOC", false, false, NULL, ID3FD_Text},
  247. {ID3FID_TITLESORT, "TST", "TSOT", false, false, NULL, ID3FD_Text},
  248. {ID3FID_REPLAYGAIN, " ", "RGAD", false, false, NULL, ID3FD_UserText },
  249. {ID3FID_VOLUMEADJ, "RVA", "RVAD", false, false, NULL, ID3FD_Volume },
  250. {ID3FID_INVOLVEDPEOPLE2, " ", "TIPL", false, false, NULL, ID3FD_InvolvedPeople },
  251. {ID3FID_CREDITS, " ", "TMCL", false, false, NULL, ID3FD_InvolvedPeople },
  252. {ID3FID_ENCODINGTIME, " ", "TDEN", false, false, NULL, ID3FD_Text },
  253. {ID3FID_FILEOWNER, " ", "TOWN", false, false, NULL, ID3FD_Text },
  254. {ID3FID_LENGTH, "TLE", "TLEN", false, false, NULL, ID3FD_Text },
  255. {ID3FID_ORIGYEAR, "TOR", "TORY", false, false, NULL, ID3FD_Text },
  256. {ID3FID_ORIGRELEASETIME, " ", "TDOR", false, false, NULL, ID3FD_Text },
  257. {ID3FID_RELEASETIME, " ", "TDRL", false, false, NULL, ID3FD_Text },
  258. {ID3FID_SETSUBTITLE, " ", "TSST", false, false, NULL, ID3FD_Text },
  259. {ID3FID_TAGGINGTIME, " ", "TDTG", false, false, NULL, ID3FD_Text },
  260. {ID3FID_PLAYLISTDELAY, "TDY", "TDLY", false, false, NULL, ID3FD_Text },
  261. {ID3FID_PODCAST, " ", "PCST", false, false, NULL, ID3FD_Text },
  262. {ID3FID_PODCASTCATEGORY, " ", "TCAT", false, false, NULL, ID3FD_Text },
  263. {ID3FID_PODCASTDESC, " ", "TDES", false, false, NULL, ID3FD_Text },
  264. {ID3FID_PODCASTID, " ", "TGID", false, false, NULL, ID3FD_Text },
  265. {ID3FID_PODCASTURL, " ", "WFED", false, false, NULL, ID3FD_URL },
  266. {ID3FID_NOFRAME }
  267. };
  268. ID3_Field::ID3_Field(void)
  269. {
  270. name = ID3FN_NOFIELD;
  271. type = ID3FTY_INTEGER;
  272. data = 0;
  273. size = 0;
  274. flags = 0;
  275. //SetVersion(3,0);
  276. version = 3;
  277. revision = 0;
  278. fixedLength = -1;
  279. ioVersion = 3;
  280. ioRevision = 0;
  281. control = ID3VC_HIGHER;
  282. Clear();
  283. }
  284. ID3_Field::~ID3_Field(void)
  285. {
  286. Clear();
  287. }
  288. void ID3_Field::Clear(void)
  289. {
  290. if (data && type != ID3FTY_INTEGER) free(data);
  291. type = ID3FTY_INTEGER;
  292. data = 0;
  293. size = sizeof (luint);
  294. hasChanged = true;
  295. return;
  296. }
  297. void ID3_Field::SetVersion (uchar ver, uchar rev)
  298. {
  299. if (version != ver || revision != rev) hasChanged = true;
  300. version = ver;
  301. revision = rev;
  302. return;
  303. }
  304. bool ID3_Field::HasChanged (void)
  305. {
  306. return hasChanged;
  307. }
  308. luint ID3_Field::Size(void)
  309. {
  310. return BinSize (false);
  311. }
  312. luint ID3_Field::BinSize(bool withExtras)
  313. {
  314. luint bytes = 0;
  315. if (control == ID3VC_HIGHER)
  316. {
  317. if (version < ioVersion || revision < ioRevision)
  318. return 0;
  319. }
  320. else
  321. {
  322. if (version > ioVersion || revision > ioRevision)
  323. return 0;
  324. }
  325. bytes = size;
  326. if (withExtras)
  327. {
  328. if (!data && size)
  329. {
  330. if (flags & ID3FF_NULL)
  331. bytes = 2;
  332. else
  333. bytes = 0;
  334. }
  335. // if we are a Unicode string, add 2 bytes for the BOM (but
  336. // only if there is a string to render - regardless of NULL)
  337. if (type == ID3FTY_UNICODESTRING && data && size) bytes += 2;
  338. // if we are an ASCII string, divide by sizeof (wchar_t)
  339. // because internally we store the string as Unicode, so
  340. // the ASCII version will only be half as long
  341. if (type == ID3FTY_UTF8STRING)
  342. {
  343. if (data && size)
  344. bytes = WideCharToMultiByte(CP_UTF8, 0, (const wchar_t *)data, (int)(size/sizeof(wchar_t)), 0, 0, 0, 0);
  345. else
  346. bytes /= sizeof(wchar_t);
  347. }
  348. if (type == ID3FTY_ASCIISTRING)
  349. {
  350. // TODO: this statement isn't correct (especially for double byte)
  351. // we could use WideCharToMultiByte to determine an exact byte count
  352. bytes /= sizeof (wchar_t);
  353. }
  354. }
  355. else
  356. {
  357. // because it seems that the application called us via ID3_Field::Size()
  358. // we are going to return the number of characters, not bytes, so if
  359. // the string is Unicode, we will half the 'bytes' variable because
  360. // Unicode strings have twice as many bytes as they do characters
  361. if (type == ID3FTY_UNICODESTRING)
  362. bytes /= sizeof(wchar_t);
  363. }
  364. // check to see if we are within the legal limit for this field
  365. // -1 means arbitrary length field
  366. if (fixedLength != -1)
  367. bytes = fixedLength;
  368. return bytes;
  369. }
  370. luint ID3_Field::Parse(uchar *buffer, luint posn, luint buffSize)
  371. {
  372. if (control == ID3VC_HIGHER)
  373. {
  374. if (version < ioVersion || revision < ioRevision)
  375. return 0;
  376. }
  377. else
  378. {
  379. if (version > ioVersion || revision > ioRevision)
  380. return 0;
  381. }
  382. switch(type)
  383. {
  384. case ID3FTY_INTEGER:
  385. return ParseInteger(buffer, posn, buffSize);
  386. case ID3FTY_BINARY:
  387. return ParseBinary(buffer, posn, buffSize);
  388. case ID3FTY_ASCIISTRING:
  389. return ParseASCIIString(buffer, posn, buffSize);
  390. case ID3FTY_UNICODESTRING:
  391. return ParseUnicodeString(buffer, posn, buffSize);
  392. case ID3FTY_UTF8STRING:
  393. return ParseUTF8String(buffer, posn, buffSize);
  394. default:
  395. //ID3_THROW (ID3E_UnknownFieldType);
  396. break;
  397. }
  398. return 0;
  399. }
  400. ID3_FrameDef *ID3_FindFrameDef(ID3_FrameID id)
  401. {
  402. luint cur = 0;
  403. while (1)
  404. {
  405. if (ID3_FrameDefs[cur].id == id)
  406. return &ID3_FrameDefs[cur];
  407. if (ID3_FrameDefs[cur].id == ID3FID_NOFRAME)
  408. return NULL;
  409. cur++;
  410. }
  411. }
  412. ID3_FrameID ID3_FindFrameID(const char *id)
  413. {
  414. luint cur = 0;
  415. while (1)
  416. {
  417. if (ID3_FrameDefs[cur].id == ID3FID_NOFRAME)
  418. return ID3FID_NOFRAME;
  419. if (((strncmp(ID3_FrameDefs[cur].shortTextID, id, 3) == 0) && strlen (id) == 3)
  420. || ((strncmp(ID3_FrameDefs[cur].longTextID, id, 4) == 0) && strlen (id) == 4))
  421. return ID3_FrameDefs[cur].id;
  422. cur++;
  423. }
  424. }
  425. luint ID3_Field::Render(uchar *buffer)
  426. {
  427. if (control == ID3VC_HIGHER)
  428. {
  429. if (version < ioVersion || revision < ioRevision)
  430. return 0;
  431. }
  432. else
  433. {
  434. if (version > ioVersion || revision > ioRevision)
  435. return 0;
  436. }
  437. switch(type)
  438. {
  439. case ID3FTY_INTEGER:
  440. return RenderInteger(buffer);
  441. case ID3FTY_BINARY:
  442. return RenderBinary(buffer);
  443. case ID3FTY_ASCIISTRING:
  444. return RenderLatinString(buffer);
  445. case ID3FTY_UNICODESTRING:
  446. return RenderUnicodeString(buffer);
  447. case ID3FTY_UTF8STRING:
  448. return RenderUTF8String(buffer);
  449. default:
  450. // ID3_THROW (ID3E_UnknownFieldType);
  451. break;
  452. }
  453. return 0;
  454. }