[easytag/wip/taglib-mp4-cxx: 3/4] Use C++ TagLib API instead of C wrapper



commit aa6eaf0082cc1fc144cdcd76d1c8113cc18de997
Author: David King <amigadave amigadave com>
Date:   Thu Mar 6 23:38:39 2014 +0000

    Use C++ TagLib API instead of C wrapper
    
    Eventually, this will enable handling of cover art and extended tags for
    MP4 files.

 Makefile.am                   |    6 ++-
 configure.ac                  |    2 +-
 src/charset.h                 |    3 +
 src/et_core.h                 |   19 ++++---
 src/log.h                     |    2 +
 src/misc.h                    |    4 +
 src/{mp4_tag.c => mp4_tag.cc} |  124 +++++++++++++++--------------------------
 src/mp4_tag.h                 |   23 +++-----
 8 files changed, 80 insertions(+), 103 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 0260c1c..0bdcf00 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -27,6 +27,10 @@ easytag_CFLAGS = \
        $(WARN_CFLAGS) \
        $(EASYTAG_CFLAGS)
 
+easytag_CXXFLAGS = \
+       $(WARN_CFLAGS) \
+       $(EASYTAG_CFLAGS)
+
 easytag_SOURCES = \
        src/id3lib/c_wrapper.cpp \
        src/libapetag/apetaglib.c \
@@ -55,7 +59,7 @@ easytag_SOURCES = \
        src/monkeyaudio_header.c \
        src/mpeg_header.c \
        src/mp4_header.c \
-       src/mp4_tag.c \
+       src/mp4_tag.cc \
        src/musepack_header.c \
        src/ogg_header.c \
        src/ogg_tag.c \
diff --git a/configure.ac b/configure.ac
index fbe1111..7fe6699 100644
--- a/configure.ac
+++ b/configure.ac
@@ -257,7 +257,7 @@ dnl ################################################
 dnl # taglib library
 dnl ################################################
 
-TAGLIB_DEPS="taglib_c >= 1.6.0"
+TAGLIB_DEPS="taglib >= 1.6.0"
 AS_IF([test "x$enable_mp4" != "xno"],
       [PKG_CHECK_EXISTS([$TAGLIB_DEPS], [have_taglib=yes], [have_taglib=no])],
       [have_taglib=no])
diff --git a/src/charset.h b/src/charset.h
index 201b601..90791dc 100644
--- a/src/charset.h
+++ b/src/charset.h
@@ -24,6 +24,8 @@
 
 #include <gtk/gtk.h>
 
+G_BEGIN_DECLS
+
 /***************
  * Declaration *
  ***************/
@@ -61,5 +63,6 @@ gchar *Charset_Get_Name_From_Title (const gchar *charset_title);
 void Charset_Insert_Locales_Init    (void);
 void Charset_Insert_Locales_Destroy (void);
 
+G_END_DECLS
 
 #endif /* __CHARSET_H__ */
diff --git a/src/et_core.h b/src/et_core.h
index c9dc610..e4159f2 100644
--- a/src/et_core.h
+++ b/src/et_core.h
@@ -28,6 +28,8 @@
 #include <config.h> // For definition of ENABLE_OGG, ...
 
 
+G_BEGIN_DECLS
+
 /***************
  * Declaration *
  ***************/
@@ -35,13 +37,13 @@
 /*
  * Colors Used (see declaration into et_core.c)
  */
-GdkColor LIGHT_BLUE;
-GdkColor RED;
-GdkColor LIGHT_RED;
-GdkColor GREY;
-GdkColor LIGHT_GREY;
-GdkColor YELLOW;
-GdkColor BLACK;
+extern GdkColor LIGHT_BLUE;
+extern GdkColor RED;
+extern GdkColor LIGHT_RED;
+extern GdkColor GREY;
+extern GdkColor LIGHT_GREY;
+extern GdkColor YELLOW;
+extern GdkColor BLACK;
 
 
 /*
@@ -332,7 +334,7 @@ struct _ET_Core
     GList *ETHistoryFileList;           // History list of files changes for undo/redo actions
 };
 
-ET_Core *ETCore;    // Main pointer to structure needed by EasyTAG
+extern ET_Core *ETCore;    // Main pointer to structure needed by EasyTAG
 
 
 
@@ -446,5 +448,6 @@ gint ET_Comp_Func_Sort_File_By_Descending_File_Bitrate    (ET_File *ETFile1, ET_
 gint ET_Comp_Func_Sort_File_By_Ascending_File_Samplerate  (ET_File *ETFile1, ET_File *ETFile2);
 gint ET_Comp_Func_Sort_File_By_Descending_File_Samplerate (ET_File *ETFile1, ET_File *ETFile2);
 
+G_END_DECLS
 
 #endif /* __ET_CORE_H__ */
diff --git a/src/log.h b/src/log.h
index 6aea0be..3aa1055 100644
--- a/src/log.h
+++ b/src/log.h
@@ -26,6 +26,7 @@
 
 //#include "et_core.h"
 
+G_BEGIN_DECLS
 
 /*
  * Types of errors
@@ -51,5 +52,6 @@ void       Log_Clean_Log_List   (void);
 void Log_Print (Log_Error_Type error_type,
                 gchar const *format, ...) G_GNUC_PRINTF (2, 3);
 
+G_END_DECLS
 
 #endif /* __LOG_H__ */
diff --git a/src/misc.h b/src/misc.h
index 1885d3b..ae04a25 100644
--- a/src/misc.h
+++ b/src/misc.h
@@ -24,6 +24,8 @@
 
 #include <gtk/gtk.h>
 
+G_BEGIN_DECLS
+
 /***************
  * Declaration *
  ***************/
@@ -110,4 +112,6 @@ gchar * et_track_number_to_string (const guint track_number);
 
 void et_on_child_exited (GPid pid, gint status, gpointer user_data);
 
+G_END_DECLS
+
 #endif /* __MISC_H__ */
diff --git a/src/mp4_tag.c b/src/mp4_tag.cc
similarity index 62%
rename from src/mp4_tag.c
rename to src/mp4_tag.cc
index fa047de..37d2a02 100644
--- a/src/mp4_tag.c
+++ b/src/mp4_tag.cc
@@ -1,6 +1,6 @@
-/* mp4_tag.c - 2005/08/06 */
 /*
  *  EasyTAG - Tag editor for MP3 and Ogg Vorbis files
+ *  Copyright (C) 2012-1014  David King <amigadave amigadave com>
  *  Copyright (C) 2001-2005  Jerome Couderc <easytag gmail com>
  *  Copyright (C) 2005  Michael Ihde <mike ihde randomwalking com>
  *  Copyright (C) 2005  Stewart Whitman <swhitman cox net>
@@ -37,9 +37,11 @@
 #include "et_core.h"
 #include "charset.h"
 
-#include <tag_c.h>
+#include <mp4file.h>
 
 
+extern "C" {
+
 /*
  * Mp4_Tag_Read_File_Tag:
  *
@@ -51,58 +53,46 @@
  */
 gboolean Mp4tag_Read_File_Tag (gchar *filename, File_Tag *FileTag)
 {
-    TagLib_File *mp4file;
-    TagLib_Tag *tag;
+    TagLib::Tag *tag;
     guint track;
 
     g_return_val_if_fail (filename != NULL && FileTag != NULL, FALSE);
 
-    /* Get data from tag */
-    mp4file = taglib_file_new_type(filename,TagLib_File_MP4);
-    if (mp4file == NULL)
-    {
-        gchar *filename_utf8 = filename_to_display(filename);
-        Log_Print(LOG_ERROR,_("Error while opening file: '%s' (%s)."),filename_utf8,_("MP4 format invalid"));
-        g_free(filename_utf8);
-        return FALSE;
-    }
+    /* Get data from tag. */
+    TagLib::MP4::File mp4file (filename);
 
-    /* Check for audio track */
-    if (!taglib_file_is_valid (mp4file))
+    if (!mp4file.isOpen ())
     {
         gchar *filename_utf8 = filename_to_display (filename);
-        Log_Print (LOG_ERROR, _("File contains no audio track: '%s'"),
-                   filename_utf8);
+        Log_Print (LOG_ERROR, _("Error while opening file: '%s' (%s)."),
+                   filename_utf8, _("MP4 format invalid"));
         g_free (filename_utf8);
-        taglib_file_free (mp4file);
         return FALSE;
     }
 
-    tag = taglib_file_tag (mp4file);
-    if (tag == NULL)
+    if (!(tag = mp4file.tag ()))
     {
         gchar *filename_utf8 = filename_to_display (filename);
         Log_Print (LOG_ERROR, _("Error reading tags from file: '%s'"),
                    filename_utf8);
         g_free (filename_utf8);
-        taglib_file_free (mp4file);
         return FALSE;
     }
 
     /*********
      * Title *
      *********/
-    FileTag->title = g_strdup(taglib_tag_title(tag));
+    FileTag->title = g_strdup (tag->title ().toCString (true));
 
     /**********
      * Artist *
      **********/
-    FileTag->artist = g_strdup(taglib_tag_artist(tag));
+    FileTag->artist = g_strdup (tag->title ().toCString (true));
 
     /*********
      * Album *
      *********/
-    FileTag->album = g_strdup(taglib_tag_album(tag));
+    FileTag->album = g_strdup (tag->title ().toCString (true));
 
     /****************
      * Album Artist *
@@ -112,12 +102,12 @@ gboolean Mp4tag_Read_File_Tag (gchar *filename, File_Tag *FileTag)
     /********
      * Year *
      ********/
-    FileTag->year = g_strdup_printf("%u", taglib_tag_year(tag));
+    FileTag->year = g_strdup_printf ("%u", tag->year ());
 
     /*************************
      * Track and Total Track *
      *************************/
-    track = taglib_tag_track(tag);
+    track = tag->track ();
 
     if (track != 0)
         FileTag->track = et_track_number_to_string (track);
@@ -126,12 +116,12 @@ gboolean Mp4tag_Read_File_Tag (gchar *filename, File_Tag *FileTag)
     /*********
      * Genre *
      *********/
-    FileTag->genre = g_strdup(taglib_tag_genre(tag));
+    FileTag->genre = g_strdup (tag->genre ().toCString (true));
 
     /***********
      * Comment *
      ***********/
-    FileTag->comment = g_strdup(taglib_tag_comment(tag));
+    FileTag->comment = g_strdup (tag->comment ().toCString (true));
 
     /**********************
      * Composer or Writer *
@@ -148,10 +138,6 @@ gboolean Mp4tag_Read_File_Tag (gchar *filename, File_Tag *FileTag)
      ***********/
     /* TODO: No encode_by support in the TagLib C API! */
 
-    /* Free allocated data */
-    taglib_tag_free_strings();
-    taglib_file_free(mp4file);
-
     return TRUE;
 }
 
@@ -169,8 +155,7 @@ gboolean Mp4tag_Write_File_Tag (ET_File *ETFile)
     File_Tag *FileTag;
     gchar    *filename;
     gchar    *filename_utf8;
-    TagLib_File *mp4file = NULL;
-    TagLib_Tag *tag;
+    TagLib::Tag *tag;
     gboolean success;
 
     g_return_val_if_fail (ETFile != NULL && ETFile->FileTag != NULL, FALSE);
@@ -180,100 +165,83 @@ gboolean Mp4tag_Write_File_Tag (ET_File *ETFile)
     filename_utf8 = ((File_Name *)ETFile->FileNameCur->data)->value_utf8;
 
     /* Open file for writing */
-    mp4file = taglib_file_new_type(filename, TagLib_File_MP4);
-    if (mp4file == NULL)
+    TagLib::MP4::File mp4file (filename);
+
+    if (!mp4file.isOpen ())
     {
-        Log_Print(LOG_ERROR,_("Error while opening file: '%s' (%s)."),filename_utf8,_("MP4 format invalid"));
+        Log_Print (LOG_ERROR, _("Error while opening file: '%s' (%s)."),
+                   filename_utf8, _("MP4 format invalid"));
         return FALSE;
     }
 
-    tag = taglib_file_tag (mp4file);
-    if (tag == NULL)
+    if (!(tag = mp4file.tag ()))
     {
         gchar *filename_utf8 = filename_to_display (filename);
         Log_Print (LOG_ERROR, _("Error reading tags from file: '%s'"),
                    filename_utf8);
         g_free (filename_utf8);
-        taglib_file_free (mp4file);
         return FALSE;
     }
 
     /*********
      * Title *
      *********/
-    if (FileTag->title && g_utf8_strlen(FileTag->title, -1) > 0)
-    {
-        taglib_tag_set_title(tag, FileTag->title);
-    }else
+    if (FileTag->title && *(FileTag->title))
     {
-        taglib_tag_set_title(tag,"");
+        TagLib::String string (FileTag->title, TagLib::String::UTF8);
+        tag->setTitle (string);
     }
 
     /**********
      * Artist *
      **********/
-    if (FileTag->artist && g_utf8_strlen(FileTag->artist, -1) > 0)
+    if (FileTag->artist && *(FileTag->artist))
     {
-        taglib_tag_set_artist(tag,FileTag->artist);
-    }else
-    {
-        taglib_tag_set_artist(tag,"");
+        TagLib::String string (FileTag->artist, TagLib::String::UTF8);
+        tag->setArtist (string);
     }
 
     /*********
      * Album *
      *********/
-    if (FileTag->album && g_utf8_strlen(FileTag->album, -1) > 0)
-    {
-        taglib_tag_set_album(tag,FileTag->album);
-    }else
+    if (FileTag->album && *(FileTag->album))
     {
-        taglib_tag_set_album(tag,"");
+        TagLib::String string (FileTag->album, TagLib::String::UTF8);
+        tag->setAlbum (string);
     }
 
-
     /********
      * Year *
      ********/
-    if (FileTag->year && g_utf8_strlen(FileTag->year, -1) > 0)
-    {
-        taglib_tag_set_year(tag,atoi(FileTag->year));
-    }else
+    if (FileTag->year)
     {
-        taglib_tag_set_year(tag,0);
+        tag->setYear (atoi (FileTag->year));
     }
 
     /*************************
      * Track and Total Track *
      *************************/
-    if ( FileTag->track && g_utf8_strlen(FileTag->track, -1) > 0 )
+    if (FileTag->track)
     {
-        taglib_tag_set_track(tag,atoi(FileTag->track));
-    }else
-    {
-        taglib_tag_set_track(tag,0);
+        tag->setTrack (atoi (FileTag->track));
     }
 
     /*********
      * Genre *
      *********/
-    if (FileTag->genre && g_utf8_strlen(FileTag->genre, -1) > 0 )
-    {
-        taglib_tag_set_genre(tag,FileTag->genre);
-    }else
+    if (FileTag->genre && *(FileTag->genre))
     {
-        taglib_tag_set_genre(tag,"");
+        TagLib::String string (FileTag->genre, TagLib::String::UTF8);
+        tag->setGenre (string);
     }
 
     /***********
      * Comment *
      ***********/
-    if (FileTag->comment && g_utf8_strlen(FileTag->comment, -1) > 0)
+    if (FileTag->comment && *(FileTag->comment))
     {
-        taglib_tag_set_comment(tag,FileTag->comment);
-    }else
-    {
-        taglib_tag_set_comment(tag,"");
+        TagLib::String string (FileTag->comment, TagLib::String::UTF8);
+        tag->setComment (string);
     }
 
     /**********************
@@ -288,11 +256,11 @@ gboolean Mp4tag_Write_File_Tag (ET_File *ETFile)
      * Picture *
      ***********/
 
-    success = taglib_file_save (mp4file) ? TRUE : FALSE;
-    taglib_file_free(mp4file);
+    success = mp4file.save () ? TRUE : FALSE;
 
     return success;
 }
 
+}
 
 #endif /* ENABLE_MP4 */
diff --git a/src/mp4_tag.h b/src/mp4_tag.h
index 2b426c2..64d7f54 100644
--- a/src/mp4_tag.h
+++ b/src/mp4_tag.h
@@ -1,6 +1,6 @@
-/* mp4_tag.h - 2005/08/06 */
 /*
  *  EasyTAG - Tag editor for MP3 and Ogg Vorbis files
+ *  Copyright (C) 2012-1014  David King <amigadave amigadave com>
  *  Copyright (C) 2001-2005  Jerome Couderc <easytag gmail com>
  *  Copyright (C) 2005  Michael Ihde <mike ihde randomwalking com>
  *
@@ -19,23 +19,16 @@
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
-
-#ifndef __MP4_TAG_H__
-#define __MP4_TAG_H__
-
+#ifndef ET_MP4_TAG_H_
+#define ET_MP4_TAG_H_
 
 #include "et_core.h"
 
-/****************
- * Declarations *
- ****************/
-
+G_BEGIN_DECLS
 
-
-/**************
- * Prototypes *
- **************/
-gboolean Mp4tag_Read_File_Tag  (gchar *filename, File_Tag *FileTag);
+gboolean Mp4tag_Read_File_Tag (gchar *filename, File_Tag *FileTag);
 gboolean Mp4tag_Write_File_Tag (ET_File *ETFile);
 
-#endif /* __MP4_TAG_H__ */
+G_END_DECLS
+
+#endif /* ET_MP4_TAG_H_ */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]