Commits

Matias De lellis  committed 54ddf15

Skeleton to save the tags according changes.
Add example on C binding to save title.

  • Participants
  • Parent commits c964f9f

Comments (0)

Files changed (12)

File bindings/c/taginfo_c.cc

 
 BOOL taginfo_info_write(TagInfo_Info *info) {
     Info *i = reinterpret_cast<Info *>(info);
-    return i->write(CHANGED_DATA_TAGS); //TODO
+    return i->write();
 }
 
 void taginfo_info_enable_string_management(BOOL management) {
 
 char *taginfo_info_get_title(const TagInfo_Info *info) {
     const Info *i = reinterpret_cast<const Info *>(info);
-    char *s = ::strdup(i->track_name.toCString(true));
  1. Matias De lellis author

    shuerhaaken Here fail with: taginfo_c.cc:86:38: error: passing 'const TagInfo::Info' as 'this' argument of 'TagLib::String TagInfo::Info::get_track_name()' discards qualifiers [-fpermissive]

    I do not understand the error. Can you help me?

+    String title = i->get_track_name();
+    char *s = ::strdup(title.toCString(true));
     if(stringManagementEnabled)
         strings.prepend(s);
     return s;
 }
 void taginfo_info_set_title(TagInfo_Info *info, const char *title) {
     Info *i = reinterpret_cast<Info *>(info);
-    i->track_name = String(title, String::UTF8);
+    i->set_track_name(String(title, String::UTF8));
 }
 
 

File libtaginfo/apeinfo.cc

 }
 
 
-bool ApeInfo::write(const int changedflag) {
+bool ApeInfo::write(void) {
     if(read_cnt < write_cnt)
         return false;
     ApeTag * Tag = ape_file.get_tag();

File libtaginfo/asfinfo.cc

 }
 
 
-bool ASFInfo::write(const int changedflag) {
+bool ASFInfo::write(void) {
     if(m_ASFTag) {
         if(changedflag & CHANGED_DATA_TAGS) {
             m_ASFTag->removeItem("WM/PartOfSet");
             check_asf_label_frame(m_ASFTag, "TRACK_LABELS", track_labels_str);
         }
     }
-    return Info::write(changedflag);
+    return Info::write();
 }
 
 

File libtaginfo/flacinfo.cc

 
 
 
-bool FlacInfo::write(const int changedflag) {
+bool FlacInfo::write(void) {
     if(m_XiphComment) {
         if(changedflag & CHANGED_DATA_TAGS) {
             m_XiphComment->addField("DISCNUMBER", disk_str);
             check_xiph_label_frame(m_XiphComment, "TRACK_LABELS", track_labels_str);
         }
     }
-    return Info::write(changedflag);
+    return Info::write();
 }
 
 

File libtaginfo/info.cc

     taglib_tag     = NULL;
     
     set_file_name(filename);
-    
+
     tracknumber = 0;
     year = 0;
     length_seconds = 0;
     playcount = 0;
     is_compilation = false;
     has_image = false;
+
+	changedflag = CHANGED_DATA_NONE;
 };
 
 
 }
 
 void Info::write_virtual_tags(TagLib::Tag * tag) {
-    if(tag) {
+    if(changedflag & CHANGED_TITLE_TAG)
         tag->setTitle(track_name);
+    if(changedflag & CHANGED_ARTIST_TAG)
         tag->setArtist(artist);
+    if(changedflag & CHANGED_ALBUM_TAG)
         tag->setAlbum(album);
+    if(changedflag & CHANGED_GENRE_TAG)
         tag->setGenre(genre);
+    if(changedflag & CHANGED_COMMENT_TAG)
         tag->setComment(comments);
+    if(changedflag & CHANGED_TRACKNO_TAG)
         tag->setTrack(tracknumber); // set the id3v1 track
+    if(changedflag & CHANGED_YEAR_TAG)
         tag->setYear(year);
-    }
 }
 
-bool Info::write(const int changedflag) {
-    if(taglib_tag && (changedflag & CHANGED_DATA_TAGS))
+bool Info::write() {
+    if(taglib_tag && changedflag)
         write_virtual_tags(taglib_tag);
     
     if(!taglib_file->save())
     return true;
 }
 
+void Info::set_track_name(String new_track_name) {
+    track_name = new_track_name;
+    changedflag |= CHANGED_TITLE_TAG;
+}
+String Info::get_track_name(void) {
+    return track_name;
+}
  1. Matias De lellis author

    This is the basic idea. Should be make that all the are saved according to flag changedflag. Note that before changeflag was an argument, and now is private to Info

 
 bool Info::can_handle_images(void) {
     return false;

File libtaginfo/mp3info.cc

 
 
 
-bool Mp3Info::write(const int changedflag) {
+bool Mp3Info::write(void) {
     if(taglib_tagId3v2) {
         if(changedflag & CHANGED_DATA_TAGS) {
             TagLib::ID3v2::TextIdentificationFrame * frame;
             id3v2_check_label_frame(taglib_tagId3v2, "TRACK_LABELS", track_labels_str);
         }
     }
-    return Info::write(changedflag);
+    return Info::write();
 }
 
 

File libtaginfo/mp4info.cc

 }
 
 
-bool Mp4Info::write(const int changedflag) {
+bool Mp4Info::write(void) {
     if(m_Mp4Tag) {
         if(changedflag & CHANGED_DATA_TAGS) {
             m_Mp4Tag->itemListMap()["aART"] = TagLib::StringList(album_artist);
             mp4_check_label_frame(m_Mp4Tag, "----:com.apple.iTunes:TRACK_LABELS", track_labels_str);
         }
     }
-    return Info::write(changedflag);
+    return Info::write();
 }
 
 bool Mp4Info::can_handle_images(void) {

File libtaginfo/mpcinfo.cc

 }
 
 
-bool MpcInfo::write(const int changedflag) {
+bool MpcInfo::write(void) {
     if(taglib_apetag) {
         if(changedflag & CHANGED_DATA_TAGS) {
             taglib_apetag->addValue("COMPOSER", composer);
             check_ape_label_frame(taglib_apetag, "TRACK_LABELS",  track_labels_str);
         }
     }
-    return Info::write(changedflag);
+    return Info::write();
 }
 
 

File libtaginfo/ogginfo.cc

 }
 
 
-bool OggInfo::write(const int changedflag) {
+bool OggInfo::write(void) {
     if(m_XiphComment) {
             if(changedflag & CHANGED_DATA_TAGS) {
             m_XiphComment->addField("DISCNUMBER", disk_str);
             check_xiph_label_frame(m_XiphComment, "TRACK_LABELS", track_labels_str);
         }
     }
-    return Info::write(changedflag);
+    return Info::write();
 }
 
 bool OggInfo::can_handle_images(void) {

File libtaginfo/taginfo.h

     };
     
     enum ChangedData {
-        CHANGED_DATA_NONE   = 0,
-        CHANGED_DATA_TAGS   = (1 << 0),
-        CHANGED_DATA_IMAGES = (1 << 1),
-        CHANGED_DATA_LYRICS = (1 << 2),
-        CHANGED_DATA_LABELS = (1 << 3),
-        CHANGED_DATA_RATING = (1 << 2)
+        CHANGED_DATA_NONE        = 0,
+        CHANGED_ARTIST_TAG       = (1 << 0),
+        CHANGED_ALBUM_TAG        = (1 << 1),
+        CHANGED_TITLE_TAG        = (1 << 2),
+        CHANGED_GENRE_TAG        = (1 << 3),
+        CHANGED_COMMENT_TAG      = (1 << 4),
+        CHANGED_TRACKNO_TAG      = (1 << 5),
+        CHANGED_YEAR_TAG         = (1 << 6),
+        CHANGED_DATA_ALBUMARTIST = (1 << 7),
+        CHANGED_DATA_DISK_STR    = (1 << 8),
+        CHANGED_DATA_IMAGES      = (1 << 9),
+        CHANGED_DATA_LYRICS      = (1 << 10),
+        CHANGED_DATA_LABELS      = (1 << 11),
+        CHANGED_DATA_RATING      = (1 << 11),
+        CHANGED_DATA_TAGS        = (1 << 12) // Kept for compatibility: TODO: Remove
     };
     
     enum ImageType {
             int year;
             
             //access functions
-            String get_track_name();
+            String get_track_name(void);
             void   set_track_name(String new_track_name);
             
             String get_genre();
             bool is_compilation;
             bool has_image;
             
+            int changedflag;
             
             Info(const string &filename = "");
             ~Info();
             
             
             virtual bool read(void);
-            virtual bool write(const int changedflag);
+            virtual bool write(void);
             
             virtual bool can_handle_images(void);
             virtual bool get_image(char*& data, int &data_length, ImageType &image_type);
             virtual bool set_image(char* data, int data_length, ImageType image_type);
-            
+
             virtual bool can_handle_lyrics(void);
             virtual String get_lyrics(void);
             virtual bool set_lyrics(const String &lyrics);
             ~Mp3Info();
             
             virtual bool read(void);
-            virtual bool write(const int changedflag);
+            virtual bool write();
             
             virtual bool can_handle_images(void);
             virtual bool get_image(char*& data, int &data_length, ImageType &image_type);
             ~FlacInfo();
             
             virtual bool read(void);
-            virtual bool write(const int changedflag);
+            virtual bool write(void);
             
             virtual bool can_handle_images(void);
             virtual bool get_image(char*& data, int &data_length, ImageType &image_type);
             ~OggInfo();
             
             virtual bool read(void);
-            virtual bool write(const int changedflag);
+            virtual bool write(void);
             
             virtual bool can_handle_images(void);
             virtual bool get_image(char*& data, int &data_length, ImageType &image_type);
             ~Mp4Info();
             
             virtual bool read(void);
-            virtual bool write(const int changedflag);
+            virtual bool write(void);
             
             virtual bool can_handle_images(void);
             virtual bool get_image(char*& data, int &data_length, ImageType &image_type);
             ~ApeInfo();
             
             virtual bool read(void);
-            virtual bool write(const int changedflag);
+            virtual bool write(void);
             
             virtual bool can_handle_lyrics(void);
             virtual String get_lyrics(void);
             ~MpcInfo();
             
             virtual bool read(void);
-            virtual bool write(const int changedflag);
+            virtual bool write(void);
             
             virtual bool can_handle_images(void);
             virtual bool get_image(char*& data, int &data_length, ImageType &image_type);
             ~WavPackInfo();
             
             virtual bool read(void);
-            virtual bool write(const int changedflag);
+            virtual bool write(void);
             
             virtual bool can_handle_images(void);
             virtual bool get_image(char*& data, int &data_length, ImageType &image_type);
             ~TrueAudioInfo();
             
             virtual bool read(void);
-            virtual bool write(const int changedflag);
+            virtual bool write(void);
             
             virtual bool can_handle_images(void);
             virtual bool get_image(char*& data, int &data_length, ImageType &image_type);
             ~ASFInfo();
             
             virtual bool read(void);
-            virtual bool write(const int changedflag);
+            virtual bool write(void);
             
             virtual bool can_handle_images(void);
             virtual bool get_image(char*& data, int &data_length, ImageType &image_type);

File libtaginfo/trueaudioinfo.cc

 }
 
 
-bool TrueAudioInfo::write(const int changedflag) {
+bool TrueAudioInfo::write(void) {
     if(taglib_tagId3v2) {
             if(changedflag & CHANGED_DATA_TAGS) {
             TagLib::ID3v2::TextIdentificationFrame * frame;
             id3v2_check_label_frame(taglib_tagId3v2, "TRACK_LABELS", track_labels_str);
         }
     }
-    return Info::write(changedflag);
+    return Info::write();
 }
 
 

File libtaginfo/wavpackinfo.cc

 }
 
 
-bool WavPackInfo::write(const int changedflag) {
+bool WavPackInfo::write(void) {
     if(taglib_apetag) {
         if(changedflag & CHANGED_DATA_TAGS) {
             taglib_apetag->addValue("COMPOSER", composer);
             check_ape_label_frame(taglib_apetag, "TRACK_LABELS", track_labels_str);
         }
     }
-    return Info::write(changedflag);
+    return Info::write();
 }
 
 bool WavPackInfo::can_handle_images(void) {