From d4890af7807311b98f890972c775285f91547ec5 Mon Sep 17 00:00:00 2001 From: Alexander Capehart Date: Mon, 17 Feb 2025 14:39:47 -0700 Subject: [PATCH] musikr: add id3v1 tags to files --- musikr/src/main/jni/src/taglib/bridge.rs | 4 ++++ musikr/src/main/jni/src/taglib/flac.rs | 21 +++++++++++++++------ musikr/src/main/jni/src/taglib/mpeg.rs | 8 ++++++++ 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/musikr/src/main/jni/src/taglib/bridge.rs b/musikr/src/main/jni/src/taglib/bridge.rs index 9ec356d37..10c68927b 100644 --- a/musikr/src/main/jni/src/taglib/bridge.rs +++ b/musikr/src/main/jni/src/taglib/bridge.rs @@ -92,6 +92,8 @@ mod bridge_impl { #[cxx_name = "File"] type CPPFLACFile; fn xiphComment(self: Pin<&mut CPPFLACFile>, create: bool) -> *mut CPPXiphComment; + #[cxx_name = "ID3v1Tag"] + fn FLACID3v1Tag(self: Pin<&mut CPPFLACFile>, create: bool) -> *mut CPPID3v1Tag; #[cxx_name = "ID3v2Tag"] fn FLACID3v2Tag(self: Pin<&mut CPPFLACFile>, create: bool) -> *mut CPPID3v2Tag; #[namespace = "taglib_shim"] @@ -113,6 +115,8 @@ mod bridge_impl { #[namespace = "TagLib::MPEG"] #[cxx_name = "File"] type CPPMPEGFile; + #[cxx_name = "ID3v1Tag"] + fn MPEGID3v1Tag(self: Pin<&mut CPPMPEGFile>, create: bool) -> *mut CPPID3v1Tag; #[cxx_name = "ID3v2Tag"] fn MPEGID3v2Tag(self: Pin<&mut CPPMPEGFile>, create: bool) -> *mut CPPID3v2Tag; diff --git a/musikr/src/main/jni/src/taglib/flac.rs b/musikr/src/main/jni/src/taglib/flac.rs index d93709dab..3f417ecea 100644 --- a/musikr/src/main/jni/src/taglib/flac.rs +++ b/musikr/src/main/jni/src/taglib/flac.rs @@ -1,6 +1,7 @@ pub use super::bridge::CPPFLACFile; pub use super::bridge::CPPFLACPicture; use super::bridge::{CPPPictureList, FLACFile_pictureList, PictureList_to_vector, Picture_data, CPPByteVector}; +use super::id3v1::ID3v1Tag; use super::id3v2::ID3v2Tag; use super::tk::{ByteVector, OwnedByteVector}; pub use super::xiph::XiphComment; @@ -18,12 +19,6 @@ impl<'file_ref> FLACFile<'file_ref> { Self { this } } - pub fn id3v2_tag(&mut self) -> Option> { - let tag = self.this.pin_mut().FLACID3v2Tag(false); - let tag_ref = unsafe { tag.as_mut() }; - let tag_this = tag_ref.map(|tag| unsafe { RefThisMut::new(tag) }); - tag_this.map(|this| ID3v2Tag::new(this)) - } pub fn xiph_comments(&mut self) -> Option> { let tag = self.this.pin_mut().xiphComment(false); @@ -41,6 +36,20 @@ impl<'file_ref> FLACFile<'file_ref> { let this = unsafe { OwnedThis::new(pictures) }; this.map(|this| PictureList::new(this)) } + + pub fn id3v1_tag(&mut self) -> Option> { + let tag = self.this.pin_mut().FLACID3v1Tag(false); + let tag_ref = unsafe { tag.as_mut() }; + let tag_this = tag_ref.map(|tag| unsafe { RefThisMut::new(tag) }); + tag_this.map(|this| ID3v1Tag::new(this)) + } + + pub fn id3v2_tag(&mut self) -> Option> { + let tag = self.this.pin_mut().FLACID3v2Tag(false); + let tag_ref = unsafe { tag.as_mut() }; + let tag_this = tag_ref.map(|tag| unsafe { RefThisMut::new(tag) }); + tag_this.map(|this| ID3v2Tag::new(this)) + } } pub struct PictureList<'file_ref> { diff --git a/musikr/src/main/jni/src/taglib/mpeg.rs b/musikr/src/main/jni/src/taglib/mpeg.rs index 729b724c8..ea0029455 100644 --- a/musikr/src/main/jni/src/taglib/mpeg.rs +++ b/musikr/src/main/jni/src/taglib/mpeg.rs @@ -1,4 +1,5 @@ use super::bridge::{self, CPPMPEGFile}; +use super::id3v1::ID3v1Tag; use super::id3v2::ID3v2Tag; use super::this::{RefThisMut, This, ThisMut}; use std::pin::Pin; @@ -12,6 +13,13 @@ impl<'file_ref> MPEGFile<'file_ref> { Self { this } } + pub fn id3v1_tag(&mut self) -> Option> { + let tag = self.this.pin_mut().MPEGID3v1Tag(false); + let tag_ref = unsafe { tag.as_mut() }; + let tag_this = tag_ref.map(|tag| unsafe { RefThisMut::new(tag) }); + tag_this.map(|this| ID3v1Tag::new(this)) + } + pub fn id3v2_tag(&mut self) -> Option> { let tag = self.this.pin_mut().MPEGID3v2Tag(false); let tag_ref = unsafe { tag.as_mut() };