Commits

shuerhaaken committed 79ed70b

add labels to C bindings (test missing)

Comments (0)

Files changed (5)

bindings/c/taginfo_c.cc

     Info *i = reinterpret_cast<Info *>(info);
     i->set_is_compilation((bool)is_compilation);
 }
-//*****************TAG READ/WRITE API****************************************************
+
+
+void taginfo_info_get_track_labels(const TagInfo_Info *info,
+                                   char** data, int *data_length) {
+    const Info *i = reinterpret_cast<const Info *>(info);
+    StringList list = i->get_track_labels_list();
+    
+    *data_length = list.size();
+    *data = (char*) malloc(list.size() * sizeof(char*));
+    int j = 0;
+    for(StringList::ConstIterator it = list.begin(); it != list.end(); ++it) {
+        data[j] = ::strdup( (*it).toCString(true));
+        j++;
+    }
+}
+void taginfo_info_set_track_labels(TagInfo_Info *info,
+                                   const char** labels, int labels_length) {
+    Info *i = reinterpret_cast<Info *>(info);
+    StringList list = StringList();
+    for(int j = 0; j < labels_length; j++) {
+        if(labels[j]) {
+            list.append(labels[j]);
+        }
+    }
+    i->set_track_labels_list(list);
+}
+
+void taginfo_info_get_album_labels(const TagInfo_Info *info,
+                                   char** labels, int *labels_length) {
+    const Info *i = reinterpret_cast<const Info *>(info);
+    StringList list = i->get_album_labels_list();
+    
+    *labels_length = list.size();
+    *labels = (char*) malloc(list.size() * sizeof(char*));
+    int j = 0;
+    for(StringList::ConstIterator it = list.begin(); it != list.end(); ++it) {
+        labels[j] = ::strdup( (*it).toCString(true));
+        j++;
+    }
+}
+void taginfo_info_set_album_labels(TagInfo_Info *info,
+                                   const char* labels, int labels_length) {
+    Info *i = reinterpret_cast<Info *>(info);
+    StringList list = StringList();
+    for(int j = 0; j < labels_length; j++) {
+        if(labels[j]) {
+            list.append(labels[j]);
+        }
+    }
+    i->set_album_labels_list(list);
+}
+
+void taginfo_info_get_artist_labels(const TagInfo_Info *info,
+                                    char** labels, int *labels_length) {
+    const Info *i = reinterpret_cast<const Info *>(info);
+    StringList list = i->get_artist_labels_list();
+    
+    *labels_length = list.size();
+    *labels = (char*) malloc(list.size() * sizeof(char*));
+    int j = 0;
+    for(StringList::ConstIterator it = list.begin(); it != list.end(); ++it) {
+        labels[j] = ::strdup( (*it).toCString(true));
+        j++;
+    }
+}
+void taginfo_info_set_artist_labels(TagInfo_Info *info,
+                                    const char* labels, int labels_length) {
+    Info *i = reinterpret_cast<Info *>(info);
+    StringList list = StringList();
+    for(int j = 0; j < labels_length; j++) {
+        if(labels[j]) {
+            list.append(labels[j]);
+        }
+    }
+    i->set_artist_labels_list(list);
+}
+
+//****************/TAG READ/WRITE API****************************************************
 
 
 //*****************IMAGES****************************************************************

bindings/c/taginfo_c.h

 BOOL taginfo_info_get_is_compilation(const TagInfo_Info *info);
 void taginfo_info_set_is_compilation(TagInfo_Info *info, BOOL is_compilation);
 
+
+void taginfo_info_get_track_labels(const TagInfo_Info *info,
+                                   char** data, int *data_length);
+void taginfo_info_set_track_labels(TagInfo_Info *info,
+                                   const char* data, int data_length);
+
+void taginfo_info_get_album_labels(const TagInfo_Info *info,
+                                   char** data, int *data_length);
+void taginfo_info_set_album_labels(TagInfo_Info *info,
+                                   const char* data, int data_length);
+
+void taginfo_info_get_artist_labels(const TagInfo_Info *info,
+                                    char** data, int *data_length);
+void taginfo_info_set_artist_labels(TagInfo_Info *info,
+                                    const char* data, int data_length);
+
 BOOL taginfo_info_can_handle_image(const TagInfo_Info *info);
 BOOL taginfo_info_get_image(const TagInfo_Info *info,
                             char** data, int *data_length, 

libtaginfo/info.cc

     return length_seconds;
 }
 
-void Info::set_track_labels_list(const StringList new_track_labels_list) {
+void Info::set_track_labels_list(const StringList &new_track_labels_list) {
     track_labels = new_track_labels_list; // TODO does this work for StringList
     track_labels_string = join(new_track_labels_list, "|");
     changedflag |= CHANGED_TRACK_LABELS;
     return track_labels;
 }
 
-void Info::set_artist_labels_list(const StringList new_artist_labels_list) {
+void Info::set_artist_labels_list(const StringList &new_artist_labels_list) {
     artist_labels = new_artist_labels_list;
     artist_labels_string = join(new_artist_labels_list, "|");
     changedflag |= CHANGED_ARTIST_LABELS;
     return artist_labels;
 }
 
-void Info::set_album_labels_list(const StringList new_album_labels_list) {
+void Info::set_album_labels_list(const StringList &new_album_labels_list) {
     album_labels = new_album_labels_list;
     album_labels_string = join(new_album_labels_list, "|");
     changedflag |= CHANGED_ALBUM_LABELS;

libtaginfo/taginfo.h

             
             //Labels
             StringList get_track_labels_list() const;
-            void set_track_labels_list(const StringList new_track_labels_list);
+            void set_track_labels_list(const StringList &new_track_labels_list);
             StringList get_artist_labels_list() const;
-            void set_artist_labels_list(const StringList new_artist_labels_list);
+            void set_artist_labels_list(const StringList &new_artist_labels_list);
             StringList get_album_labels_list() const;
-            void set_album_labels_list(const StringList new_album_labels_list);
+            void set_album_labels_list(const StringList &new_album_labels_list);
             
             
             //Misc

libtaginfo/taginfo_internal.h

 
 
 inline StringList split(const String str, const String &separator) {
-    StringList list;
-    for(int index = 0;;) {
-        int sep = str.find(separator, index);
-        if(sep < 0) {
-            list.append(str.substr(index, str.size() - index));
-        break;
-        }
-        else {
-            list.append(str.substr(index, sep - index));
-            index = sep + separator.size();
-        }
-    }
-    return list;
+    return StringList::split(str, separator);
+//    StringList list;
+//    for(int index = 0;;) {
+//        int sep = str.find(separator, index);
+//        if(sep < 0) {
+//            list.append(str.substr(index, str.size() - index));
+//        break;
+//        }
+//        else {
+//            list.append(str.substr(index, sep - index));
+//            index = sep + separator.size();
+//        }
+//    }
+//    return list;
 }
 
 inline String join(const StringList strlist, const String &separator) {
-    String out("", String::UTF8);
-    for(StringList::ConstIterator it = strlist.begin(); it != strlist.end(); ++it) {
-      out.append(*it);
-      out.append(separator);
-    }
-    if(out.size() > 0)
-        return out.substr(0, out.size() - 1);
-    else
-        return out;
+    return strlist.toString("|");
+//    String out("", String::UTF8);
+//    for(StringList::ConstIterator it = strlist.begin(); it != strlist.end(); ++it) {
+//      out.append(*it);
+//      out.append(separator);
+//    }
+//    if(out.size() > 0)
+//        return out.substr(0, out.size() - 1);
+//    else
+//        return out;
 }