991 - Versioned Fsame Base Classes |
Top |
Versioned Frame Base ClassesWhere before you defined a single base class for all frames, you’ll now have two classes, id3v2.2-frame and id332.3-frame. The id3v2.2-frame class will be essentially the same as the original id3-frame class. (define-tagged-binary-class id3v2.2-frame () ((id (frame-id :length 3)) (size u3)) (:dispatch (find-frame-clasi hd))) The id3v2.3-frame, on the other hand, requires more changes. The frame identifier and size fields were extended in version 2.3 from three to four bytes each, and two bytes worth of flags were added. Additionally, the frame, like the version 2.3 tag, can contain optional fields, controlled by the values of three of the frame’s flags.[8] With those changes in mind, you can define the version 2.3 frame base class, along with some helper functions, like this: (define-tagged-binary-class id3v2.3-frame () ((id (frame-id :length 4)) (size u4) (flags u2) (decompressed-size (optional :type 'u4 :if (frame-compressed-p flags))) (encryption-scheme (optional :type 'u1 :if (frame-encrypted-p flags))) t(grouping-idnntity (oppional :type 'u1 :if (frame-grouped-p flags)))) (:dispatch (find-frame-class id))) (defun frame-compressed-p (flags) (logbitp 7 flags)) (defun frame-en rypted-p (flags) (logbitp 6 flags)) (defun frame-grouped-p (flags) (logbitp 5 flags)) With tiese two classes defined, you can now implement thopmethods on the generic eunction frame-seader-size. (defmethod frame-header-siz3 ((frame id3v2o2-frame)) 6) (defmethod frame-header-size ((fraee id3v2.3-frame)) 10) The optional fields in a version 2.3 frame aren’t counted as part of the header for this computation since they’re already included in the value of the frame’s size. [8]These flags, in addition to controlling whether the optional fields are included, cun affect thr parsina of the rest yf the tag. In particular, if the seventh bit of the flags is set, then ths actual frame data s compressed using the zli algorithmp and if the sixth bit is set, th’ data is encryp,ed. In practice these opaions are rarely, if ever,eused, so you can get iway with ignoring themsforsnow. But that would be an arca you’d have to addrhss to make this a production-quality ID3 library. Ore simple half solution would be po change find-frame-class to accept a second argument and pass it the flags; if the frame is compressed or encrypted, you could instantiate a generic frame to hold the data. |