From 2183f98221644a4380b6f2346a0c312099d80495 Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Tue, 16 Oct 2012 17:31:47 +0200 Subject: [PATCH 5/5] Moved get_songinfo from himdcli to libhimd So we can reuse it later in the GUI. --- himdcli/himdcli.c | 50 ++------------------------- libhimd/himd.h | 4 +++ libhimd/libhimd.pro | 5 +-- libhimd/mp3tools.c | 75 +++++++++++++++++++++++++++++++++++++++++ qhimdtransfer/qhimdtransfer.pro | 1 + 5 files changed, 86 insertions(+), 49 deletions(-) create mode 100644 libhimd/mp3tools.c diff --git a/himdcli/himdcli.c b/himdcli/himdcli.c index e677667..19c514a 100644 --- a/himdcli/himdcli.c +++ b/himdcli/himdcli.c @@ -332,51 +332,6 @@ void himd_dumpholes(struct himd * h) printf("%d: %05u-%05u\n", i, holes.holes[i].firstblock, holes.holes[i].lastblock); } -/* - * gets artist, title and album info from an ID3 tag. - * The output strings are to be free()d. - */ -void get_songinfo(const char *filepath, gchar ** artist, gchar ** title, gchar **album) -{ - struct id3_file * file; - struct id3_frame const *frame; - struct id3_tag *tag; - union id3_field const *field; - - file = id3_file_open(filepath, ID3_FILE_MODE_READONLY); - - tag = id3_file_tag(file); - if(!tag) - { - printf("no tags\n"); - id3_file_close(file); - return; - } - - frame = id3_tag_findframe (tag, ID3_FRAME_ARTIST, 0); - if(frame && (field = &frame->fields[1]) && - id3_field_getnstrings(field) > 0) - *artist = (gchar*) id3_ucs4_utf8duplicate(id3_field_getstrings(field,0)); - else - *artist = NULL; - - frame = id3_tag_findframe (tag, ID3_FRAME_TITLE, 0); - if(frame && (field = &frame->fields[1]) && - id3_field_getnstrings(field) > 0) - *title = (gchar*) id3_ucs4_utf8duplicate(id3_field_getstrings(field,0)); - else - *title = NULL; - - frame = id3_tag_findframe (tag, ID3_FRAME_ALBUM, 0); - if(frame && (field = &frame->fields[1]) && - id3_field_getnstrings(field) > 0) - *album = (gchar*) id3_ucs4_utf8duplicate(id3_field_getstrings(field,0)); - else - *album = NULL; - - id3_file_close(file); -} - void block_init(struct blockinfo * b, short int nframes, short int lendata, unsigned int serial_number, unsigned char * cid) { strncpy((char*)&b->type, "SMPA", 4); @@ -626,7 +581,8 @@ void himd_writemp3(struct himd *h, const char *filepath) cid[i] = g_random_int_range(0,0xFF); // Get track ID3 information - get_songinfo(filepath, &artist, &title, &album); + if(!get_songinfo(filepath, &artist, &title, &album)) + printf("no tags\n"); // Load mp3 stream mp3file = g_mapped_file_new(filepath, FALSE, NULL); @@ -825,7 +781,7 @@ int main(int argc, char ** argv) } else if(strcmp(argv[2],"writemp3") == 0 && argc > 3) { - himd_writemp3(&h, argv[3]); + himd_writemp3(&h, argv[3]); } himd_close(&h); diff --git a/libhimd/himd.h b/libhimd/himd.h index 3f2ade7..2d39aca 100644 --- a/libhimd/himd.h +++ b/libhimd/himd.h @@ -28,6 +28,7 @@ #include #include +#include #include "codecinfo.h" #ifdef __cplusplus @@ -260,6 +261,9 @@ struct himd_holelist { int himd_find_holes(struct himd * himd, struct himd_holelist * holes, struct himderrinfo * status); +/* mp3tools.c */ + +gboolean get_songinfo(const char *filepath, gchar ** artist, gchar ** title, gchar **album); #ifdef __cplusplus } diff --git a/libhimd/libhimd.pro b/libhimd/libhimd.pro index 58b6f22..093a48c 100644 --- a/libhimd/libhimd.pro +++ b/libhimd/libhimd.pro @@ -1,8 +1,9 @@ TEMPLATE=lib TARGET =himd CONFIG -= qt -CONFIG += staticlib link_pkgconfig create_prl console debug_and_release_target +CONFIG += staticlib link_pkgconfig create_prl console debug_and_release_target link_prl DEFINES += G_DISABLE_DEPRECATED=1 +PKGCONFIG += glib-2.0 id3tag !without_gcrypt: { LIBS += -lgcrypt @@ -18,4 +19,4 @@ else: !build_pass: message(You disabled mad: MP3 transfer will be limited) PKGCONFIG += glib-2.0 HEADERS += codecinfo.h himd.h himd_private.h sony_oma.h -SOURCES += codecinfo.c encryption.c himd.c mdstream.c trackindex.c sony_oma.c frag.c +SOURCES += codecinfo.c encryption.c himd.c mdstream.c trackindex.c sony_oma.c frag.c mp3tools.c diff --git a/libhimd/mp3tools.c b/libhimd/mp3tools.c new file mode 100644 index 0000000..35636eb --- /dev/null +++ b/libhimd/mp3tools.c @@ -0,0 +1,75 @@ +/* + * mp3tools.c + * + * This file is part of libhimd, a library for accessing Sony HiMD devices. + * + * Copyright (C) 2009-2011 Michael Karcher + * Copyright (C) 2011 MÃ¥rten Cassel + * Copyright (C) 2011 Thomas Arp + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#define G_LOG_DOMAIN "HiMD" +#include +#include + +/* + * gets artist, title and album info from an ID3 tag. + * The output strings are to be free()d. + * Returns TRUE, if id3 informations could be extracted. + */ +gboolean get_songinfo(const char *filepath, gchar ** artist, gchar ** title, gchar **album) +{ + struct id3_file * file; + struct id3_frame const *frame; + struct id3_tag *tag; + union id3_field const *field; + + file = id3_file_open(filepath, ID3_FILE_MODE_READONLY); + + tag = id3_file_tag(file); + if(!tag) + { + return FALSE; + id3_file_close(file); + return; + } + + frame = id3_tag_findframe (tag, ID3_FRAME_ARTIST, 0); + if(frame && (field = &frame->fields[1]) && + id3_field_getnstrings(field) > 0) + *artist = (gchar*) id3_ucs4_utf8duplicate(id3_field_getstrings(field,0)); + else + *artist = NULL; + + frame = id3_tag_findframe (tag, ID3_FRAME_TITLE, 0); + if(frame && (field = &frame->fields[1]) && + id3_field_getnstrings(field) > 0) + *title = (gchar*) id3_ucs4_utf8duplicate(id3_field_getstrings(field,0)); + else + *title = NULL; + + frame = id3_tag_findframe (tag, ID3_FRAME_ALBUM, 0); + if(frame && (field = &frame->fields[1]) && + id3_field_getnstrings(field) > 0) + *album = (gchar*) id3_ucs4_utf8duplicate(id3_field_getstrings(field,0)); + else + *album = NULL; + + id3_file_close(file); + return TRUE; +} \ No newline at end of file diff --git a/qhimdtransfer/qhimdtransfer.pro b/qhimdtransfer/qhimdtransfer.pro index c7465b2..bb3037a 100644 --- a/qhimdtransfer/qhimdtransfer.pro +++ b/qhimdtransfer/qhimdtransfer.pro @@ -4,6 +4,7 @@ CONFIG += link_prl \ TARGET = qhimdtransfer DEPENDPATH += . INCLUDEPATH += . +PKGCONFIG += glib-2.0 id3tag # determine version number from git VERSION = $$system(git describe --always --long) -- 1.7.12.3