tag.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #pragma once
  2. #include "header.h"
  3. #include "nu/PtrDeque.h"
  4. #include "frame.h"
  5. #include "extendedheader.h"
  6. /* benski> random thoughts
  7. Frames are stored as raw bytes. Users of this library will have to parse/encode
  8. on their own. But we'll supply a helper library for that.
  9. new frames must be created from the tag object (not standalone "new ID3v2::Frame")
  10. so that revision & version information (and any relevant tag-wide flags) can be inherited
  11. */
  12. namespace ID3v2
  13. {
  14. class Tag : public ID3v2::Header
  15. {
  16. public:
  17. Tag(const ID3v2::Header &header);
  18. virtual ~Tag() {}
  19. /* finds the first frame with the desired identifier. */
  20. ID3v2::Frame *FindFirstFrame(const int8_t *id) const;
  21. /* finds the next frame with the same identifier as the passed in frame
  22. "frame" parameter MUST be a frame returned from the same Tag object! */
  23. ID3v2::Frame *FindNextFrame(const ID3v2::Frame *frame) const;
  24. void RemoveFrame(ID3v2::Frame *frame);
  25. void RemoveFrames(const int8_t *id);
  26. void AddFrame(ID3v2::Frame *frame);
  27. virtual int Parse(const void *data, size_t len)=0;
  28. virtual int SerializedSize(uint32_t *length, uint32_t padding_size, int flags) const=0;
  29. // tag will be padded up to length. use SerializedSize() to retrieve the length to use!
  30. virtual int Serialize(void *data, uint32_t len, int flags) const=0;
  31. virtual ID3v2::Frame *FindFirstFrame(int frame_id) const = 0;
  32. virtual void RemoveFrames(int frame_id)=0;
  33. virtual ID3v2::Frame *NewFrame(int frame_id, int flags) const=0;
  34. ID3v2::Frame *EnumerateFrame(const ID3v2::Frame *position) const;
  35. protected:
  36. typedef nu::PtrDeque<ID3v2::Frame> FrameList;
  37. nu::PtrDeque<ID3v2::Frame> frames;
  38. };
  39. }
  40. namespace ID3v2_2
  41. {
  42. class Tag : public ID3v2::Tag
  43. {
  44. public:
  45. Tag(const ID3v2::Header &header);
  46. ~Tag();
  47. int Parse(const void *data, size_t len);
  48. int SerializedSize(uint32_t *length, uint32_t padding_size, int flags) const;
  49. int Serialize(void *data, uint32_t len, int flags) const;
  50. /* finds the first frame with the desired identifier. */
  51. ID3v2_2::Frame *FindFirstFrame(int frame_id) const;
  52. /* finds the next frame with the same identifier as the passed in frame
  53. "frame" parameter MUST be a frame returned from the same Tag object! */
  54. void RemoveFrames(int frame_id);
  55. ID3v2_2::Frame *NewFrame(int frame_id, int flags) const;
  56. private:
  57. ID3v2_3::ExtendedHeader extendedHeader;
  58. };
  59. }
  60. namespace ID3v2_3
  61. {
  62. class Tag : public ID3v2::Tag
  63. {
  64. public:
  65. Tag(const ID3v2::Header &header);
  66. ~Tag();
  67. int Parse(const void *data, size_t len);
  68. int SerializedSize(uint32_t *length, uint32_t padding_size, int flags) const;
  69. int Serialize(void *data, uint32_t len, int flags) const;
  70. /* finds the first frame with the desired identifier. */
  71. ID3v2_3::Frame *FindFirstFrame(int frame_id) const;
  72. void RemoveFrames(int frame_id);
  73. ID3v2_3::Frame *NewFrame(int frame_id, int flags) const;
  74. private:
  75. ID3v2_3::ExtendedHeader extendedHeader;
  76. };
  77. }
  78. namespace ID3v2_4
  79. {
  80. class Tag : public ID3v2::Tag
  81. {
  82. public:
  83. Tag(const ID3v2::Header &header);
  84. ~Tag();
  85. int Parse(const void *data, size_t len);
  86. int SerializedSize(uint32_t *length, uint32_t padding_size, int flags) const;
  87. int Serialize(void *data, uint32_t len, int flags) const;
  88. /* finds the first frame with the desired identifier. */
  89. ID3v2_4::Frame *FindFirstFrame(int frame_id) const;
  90. /* finds the next frame with the same identifier as the passed in frame
  91. "frame" parameter MUST be a frame returned from the same Tag object! */
  92. ID3v2::Frame *FindNextFrame(const ID3v2::Frame *frame) const { return FindNextFrame((const Frame *)frame); }
  93. void RemoveFrames(int frame_id);
  94. ID3v2_4::Frame *NewFrame(int frame_id, int flags) const;
  95. private:
  96. ID3v2_4::ExtendedHeader extendedHeader;
  97. };
  98. }