Commit 9745f25e authored by Josh Coalson's avatar Josh Coalson
Browse files

major plugin revamp based on x-fixer's code

parent 838408a3
......@@ -37,4 +37,4 @@ all default: $(DEFAULT_BUILD)
VERSION=\"1.1.1\"
CONFIG_CFLAGS=-DHAVE_INTTYPES_H
CONFIG_CFLAGS=-D_GNU_SOURCE -DHAVE_INTTYPES_H -DHAVE_WCSDUP -DHAVE_WCSCASECMP
......@@ -147,10 +147,16 @@ AM_PROG_AS
AC_PROG_CXX
AC_PROG_MAKE_SET
dnl In order to have access to any available wcsdup() and wcscasecmp()
AC_GNU_SOURCE
dnl check for getopt in standard library
dnl AC_CHECK_FUNCS(getopt_long , , [LIBOBJS="$LIBOBJS getopt.o getopt1.o"] )
AC_CHECK_FUNCS(getopt_long, [], [])
dnl Check for uncommon wide char functions
AC_CHECK_FUNCS(wcsdup, wcscasecmp, [], [])
AC_CANONICAL_HOST
case "$host_cpu" in
i*86) cpu_ia32=true ; AC_DEFINE(FLAC__CPU_IA32) ;;
......
This diff is collapsed.
/* plugin_common - Routines common to several plugins
* Copyright (C) 2002,2003,2004 Josh Coalson
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef FLAC__PLUGIN_COMMON__CANONICAL_TAG_H
#define FLAC__PLUGIN_COMMON__CANONICAL_TAG_H
#include "id3v1.h"
typedef struct {
char *title;
char *composer;
char *performer;
char *album;
char *year_recorded;
char *year_performed;
char *track_number;
char *tracks_in_album;
char *genre;
char *comment;
} FLAC_Plugin__CanonicalTag;
FLAC_Plugin__CanonicalTag *FLAC_plugin__canonical_tag_new();
void FLAC_plugin__canonical_tag_delete(FLAC_Plugin__CanonicalTag *);
void FLAC_plugin__canonical_tag_init(FLAC_Plugin__CanonicalTag *);
void FLAC_plugin__canonical_tag_clear(FLAC_Plugin__CanonicalTag *);
/* For each null field in dest, move the corresponding field from src
* WATCHOUT: note that src is not-const, because fields are 'moved' from
* src to dest and the src field is set to null.
*/
void FLAC_plugin__canonical_tag_merge(FLAC_Plugin__CanonicalTag *dest, FLAC_Plugin__CanonicalTag *src);
void FLAC_plugin__canonical_tag_convert_from_id3v1(FLAC_Plugin__CanonicalTag *, const FLAC_Plugin__Id3v1_Tag *);
/* Returns a merged tag based on any Vorbis comments, id3v2 tag, and id3v1.
* In case of overlaps the preceding precedence applies.
*/
void FLAC_plugin__canonical_tag_get_combined(const char *filename, FLAC_Plugin__CanonicalTag *tag);
#endif
/* plugin_common - Routines common to several plugins
* Copyright (C) 2002,2003,2004 Josh Coalson
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef FLAC__PLUGIN_COMMON__CANONICAL_TAG_H
#define FLAC__PLUGIN_COMMON__CANONICAL_TAG_H
#include "id3v1.h"
#include "id3v2.h"
/* TODO: splay tree? */
typedef struct tagFLAC__tag_entry FLAC__tag_entry;
struct tagFLAC__tag_entry
{
FLAC__tag_entry *next, *prev;
/* TODO: name in ascii? */
wchar_t *name;
wchar_t *value;
};
typedef struct {
FLAC__tag_entry *head, *tail;
unsigned count;
} FLAC_Plugin__CanonicalTag;
typedef FLAC__tag_entry *FLAC__tag_iterator;
FLAC_Plugin__CanonicalTag *FLAC_plugin__canonical_tag_new();
void FLAC_plugin__canonical_tag_init(FLAC_Plugin__CanonicalTag *);
void FLAC_plugin__canonical_tag_clear(FLAC_Plugin__CanonicalTag *);
void FLAC_plugin__canonical_tag_delete(FLAC_Plugin__CanonicalTag *);
/* note that multiple fields with the same name are allowed.
* set - adds field if it's not present yet, or replaces
* existing field if it's present.
*/
void FLAC_plugin__canonical_set(FLAC_Plugin__CanonicalTag *tag, const wchar_t *name, const wchar_t *value);
void FLAC_plugin__canonical_set_ansi(FLAC_Plugin__CanonicalTag *tag, const wchar_t *name, const char *value);
/* set_new - only adds field if it's not present yet. */
void FLAC_plugin__canonical_set_new(FLAC_Plugin__CanonicalTag *tag, const wchar_t *name, const wchar_t *value);
/* add - adds field if it's not present yet, or merges value with existing
* field, if it's present. (sep - separator string to use when merging;
* if sep==NULL no merging occurs - always adds new field)
*/
void FLAC_plugin__canonical_add(FLAC_Plugin__CanonicalTag *tag, const wchar_t *name, const wchar_t *value, const wchar_t *sep);
void FLAC_plugin__canonical_add_utf8(FLAC_Plugin__CanonicalTag *tag, const char *name, const char *value, unsigned namelen, unsigned vallen, const char *sep); /* 'namelen'/'vallen' may be (unsigned)(-1) if 'name'/'value' is NUL-terminated */
/* gets value of the first field with the given name (NULL if field not found) */
const wchar_t *FLAC_plugin__canonical_get(const FLAC_Plugin__CanonicalTag *tag, const wchar_t *name);
/* removes first field with the given name.
* (returns 'true' if deleted, 'false' if not found)
*/
FLAC__bool FLAC_plugin__canonical_remove(FLAC_Plugin__CanonicalTag *tag, const wchar_t *name);
/* removes all fields with the given name. */
void FLAC_plugin__canonical_remove_all(FLAC_Plugin__CanonicalTag *tag, const wchar_t *name);
/* enumeration */
static __inline unsigned FLAC_plugin__canonical_get_count(FLAC_Plugin__CanonicalTag *tag)
{
return tag->count;
}
static __inline FLAC__tag_iterator FLAC_plugin__canonical_first(FLAC_Plugin__CanonicalTag *tag)
{
return tag->head;
}
static __inline FLAC__tag_iterator FLAC_plugin__canonical_next(FLAC__tag_iterator it)
{
return it->next;
}
static __inline wchar_t *FLAC_plugin__canonical_get_name(FLAC__tag_iterator it)
{
return it->name;
}
static __inline wchar_t *FLAC_plugin__canonical_get_value(FLAC__tag_iterator it)
{
return it->value;
}
/* returns a new string containing the current entry in UTF-8 in "NAME=VALUE" form */
char *FLAC_plugin__canonical_get_formatted(FLAC__tag_iterator it);
void FLAC_plugin__canonical_tag_merge(FLAC_Plugin__CanonicalTag *dest, const FLAC_Plugin__CanonicalTag *src);
void FLAC_plugin__canonical_tag_convert_from_id3v1(FLAC_Plugin__CanonicalTag *, const FLAC_Plugin__Id3v1_Tag *);
void FLAC_plugin__canonical_tag_convert_from_id3v2(FLAC_Plugin__CanonicalTag *, const FLAC_Plugin__Id3v2_Tag *);
void FLAC_plugin__canonical_tag_add_id3v1(const char *filename, FLAC_Plugin__CanonicalTag *tag);
void FLAC_plugin__canonical_tag_add_id3v2(const char *filename, FLAC_Plugin__CanonicalTag *tag);
/* Returns a merged tag based on any Vorbis comments, id3v2 tag, and id3v1.
* In case of overlaps the preceding precedence applies.
*
* sep - separator to use when merging fields with same name (in VorbisComment).
* should be in UTF-8. if sep==NULL, no merging occurs, so multiple fields
* with the same name can exist.
*/
void FLAC_plugin__canonical_tag_get_combined(const char *filename, FLAC_Plugin__CanonicalTag *tag, const char *sep);
/* helpers */
wchar_t *FLAC_plugin__convert_ansi_to_wide(const char *src);
wchar_t *FLAC_plugin__convert_utf8_to_ucs2(const char *src, unsigned length); /* 'length' may be (unsigned)(-1) if 'src' is NUL-terminated */
char *FLAC_plugin__convert_ucs2_to_utf8(const wchar_t *src);
#endif
/* plugin_common - Routines common to several plugins
* Copyright (C) 2002,2003,2004 Josh Coalson
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <stdio.h>
#include "FLAC/assert.h"
#include "id3v1.h"
#include "locale_hack.h"
/*
* Do not sort genres!!
* Last Update: 2000/04/30
*/
static const char * const FLAC_plugin__id3v1_tag_genre_table[] =
{
"Blues", /* 0 */
"Classic Rock",
"Country",
"Dance",
"Disco",
"Funk", /* 5 */
"Grunge",
"Hip-Hop",
"Jazz",
"Metal",
"New Age", /* 10 */
"Oldies",
"Other",
"Pop",
"R&B",
"Rap", /* 15 */
"Reggae",
"Rock",
"Techno",
"Industrial",
"Alternative", /* 20 */
"Ska",
"Death Metal",
"Pranks",
"Soundtrack",
"Euro-Techno", /* 25 */
"Ambient",
"Trip-Hop",
"Vocal",
"Jazz+Funk",
"Fusion", /* 30 */
"Trance",
"Classical",
"Instrumental",
"Acid",
"House", /* 35 */
"Game",
"Sound Clip",
"Gospel",
"Noise",
"Altern Rock", /* 40 */
"Bass",
"Soul",
"Punk",
"Space",
"Meditative", /* 45 */
"Instrumental Pop",
"Instrumental Rock",
"Ethnic",
"Gothic",
"Darkwave", /* 50 */
"Techno-Industrial",
"Electronic",
"Pop-Folk",
"Eurodance",
"Dream", /* 55 */
"Southern Rock",
"Comedy",
"Cult",
"Gangsta",
"Top 40", /* 60 */
"Christian Rap",
"Pop/Funk",
"Jungle",
"Native American",
"Cabaret", /* 65 */
"New Wave",
"Psychadelic",
"Rave",
"Showtunes",
"Trailer", /* 70 */
"Lo-Fi",
"Tribal",
"Acid Punk",
"Acid Jazz",
"Polka", /* 75 */
"Retro",
"Musical",
"Rock & Roll",
"Hard Rock",
"Folk", /* 80 */
"Folk/Rock",
"National Folk",
"Fast Fusion",
"Swing",
"Bebob", /* 85 */
"Latin",
"Revival",
"Celtic",
"Bluegrass",
"Avantgarde", /* 90 */
"Gothic Rock",
"Progressive Rock",
"Psychedelic Rock",
"Symphonic Rock",
"Slow Rock", /* 95 */
"Big Band",
"Chorus",
"Easy Listening",
"Acoustic",
"Humour", /* 100 */
"Speech",
"Chanson",
"Opera",
"Chamber Music",
"Sonata", /* 105 */
"Symphony",
"Booty Bass",
"Primus",
"Porn Groove",
"Satire", /* 110 */
"Slow Jam",
"Club",
"Tango",
"Samba",
"Folklore", /* 115 */
"Ballad",
"Power Ballad",
"Rhythmic Soul",
"Freestyle",
"Duet", /* 120 */
"Punk Rock",
"Drum Solo",
"A Capella",
"Euro-House",
"Dance Hall", /* 125 */
"Goa",
"Drum & Bass",
"Club-House",
"Hardcore",
"Terror", /* 130 */
"Indie",
"BritPop",
"Negerpunk",
"Polsk Punk",
"Beat", /* 135 */
"Christian Gangsta Rap",
"Heavy Metal",
"Black Metal",
"Crossover",
"Contemporary Christian",/* 140 */
"Christian Rock",
"Merengue",
"Salsa",
"Thrash Metal",
"Anime", /* 145 */
"JPop",
"Synthpop"
};
FLAC__bool FLAC_plugin__id3v1_tag_get(const char *filename, FLAC_Plugin__Id3v1_Tag *tag)
{
char raw[128];
FILE *f;
FLAC__ASSERT(0 != filename);
FLAC__ASSERT(0 != tag);
memset(tag, 0, sizeof(FLAC_Plugin__Id3v1_Tag));
if(0 == (f = fopen(filename, "rb")))
return false;
if(-1 == fseek(f, -128, SEEK_END)) {
fclose(f);
return false;
}
if(fread(raw, 1, 128, f) < 128) {
fclose(f);
return false;
}
fclose(f);
if(strncmp(raw, "TAG", 3))
return false;
else {
memcpy(tag->tag, raw, 3);
memcpy(tag->title, raw+3, 30);
memcpy(tag->artist, raw+33, 30);
memcpy(tag->album, raw+63, 30);
memcpy(tag->year, raw+93, 4);
memcpy(tag->comment.v1_0.comment, raw+97, 30);
tag->genre = raw[127];
return true;
}
}
const char *FLAC_plugin__id3v1_tag_get_genre_as_string(unsigned char genre_code)
{
if (genre_code < FLAC_plugin__id3v1_tag_genre_table_max())
return gettext(FLAC_plugin__id3v1_tag_genre_table[genre_code]);
return "";
}
unsigned FLAC_plugin__id3v1_tag_genre_table_max()
{
return sizeof(FLAC_plugin__id3v1_tag_genre_table) / sizeof(FLAC_plugin__id3v1_tag_genre_table[0]) - 1;
}
/* plugin_common - Routines common to several plugins
* Copyright (C) 2002,2003,2004 Josh Coalson
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <stdio.h>
#include "FLAC/assert.h"
#include "id3v1.h"
#include "locale_hack.h"
/*
* Do not sort genres!!
* Last Update: 2000/04/30
*/
static const char * const FLAC_plugin__id3v1_tag_genre_table[] =
{
"Blues", /* 0 */
"Classic Rock",
"Country",
"Dance",
"Disco",
"Funk", /* 5 */
"Grunge",
"Hip-Hop",
"Jazz",
"Metal",
"New Age", /* 10 */
"Oldies",
"Other",
"Pop",
"R&B",
"Rap", /* 15 */
"Reggae",
"Rock",
"Techno",
"Industrial",
"Alternative", /* 20 */
"Ska",
"Death Metal",
"Pranks",
"Soundtrack",
"Euro-Techno", /* 25 */
"Ambient",
"Trip-Hop",
"Vocal",
"Jazz+Funk",
"Fusion", /* 30 */
"Trance",
"Classical",
"Instrumental",
"Acid",
"House", /* 35 */
"Game",
"Sound Clip",
"Gospel",
"Noise",
"Altern Rock", /* 40 */
"Bass",
"Soul",
"Punk",
"Space",
"Meditative", /* 45 */
"Instrumental Pop",
"Instrumental Rock",
"Ethnic",
"Gothic",
"Darkwave", /* 50 */
"Techno-Industrial",
"Electronic",
"Pop-Folk",
"Eurodance",
"Dream", /* 55 */
"Southern Rock",
"Comedy",
"Cult",
"Gangsta",
"Top 40", /* 60 */
"Christian Rap",
"Pop/Funk",
"Jungle",
"Native American",
"Cabaret", /* 65 */
"New Wave",
"Psychadelic",
"Rave",
"Showtunes",
"Trailer", /* 70 */
"Lo-Fi",
"Tribal",
"Acid Punk",
"Acid Jazz",
"Polka", /* 75 */
"Retro",
"Musical",
"Rock & Roll",
"Hard Rock",
"Folk", /* 80 */
"Folk/Rock",
"National Folk",
"Fast Fusion",
"Swing",
"Bebob", /* 85 */
"Latin",
"Revival",
"Celtic",
"Bluegrass",
"Avantgarde", /* 90 */
"Gothic Rock",
"Progressive Rock",
"Psychedelic Rock",
"Symphonic Rock",
"Slow Rock", /* 95 */
"Big Band",
"Chorus",
"Easy Listening",
"Acoustic",
"Humour", /* 100 */
"Speech",
"Chanson",
"Opera",
"Chamber Music",
"Sonata", /* 105 */
"Symphony",
"Booty Bass",
"Primus",
"Porn Groove",
"Satire", /* 110 */
"Slow Jam",
"Club",
"Tango",
"Samba",
"Folklore", /* 115 */
"Ballad",
"Power Ballad",
"Rhythmic Soul",
"Freestyle",
"Duet", /* 120 */
"Punk Rock",
"Drum Solo",
"A Capella",
"Euro-House",
"Dance Hall", /* 125 */
"Goa",
"Drum & Bass",
"Club-House",
"Hardcore",
"Terror", /* 130 */
"Indie",
"BritPop",
"Negerpunk",
"Polsk Punk",
"Beat", /* 135 */
"Christian Gangsta Rap",
"Heavy Metal",
"Black Metal",
"Crossover",
"Contemporary Christian",/* 140 */
"Christian Rock",
"Merengue",
"Salsa",
"Thrash Metal",
"Anime", /* 145 */
"JPop",
"Synthpop"
};
FLAC__bool FLAC_plugin__id3v1_tag_get(const char *filename, FLAC_Plugin__Id3v1_Tag *tag)
{
FILE *f;
int res;
FLAC__ASSERT(0 != filename);
FLAC__ASSERT(0 != tag);
memset(tag, 0, sizeof(FLAC_Plugin__Id3v1_Tag));
if(0 == (f = fopen(filename, "rb")))
return false;
if(-1 == fseek(f, -128, SEEK_END)) {
fclose(f);
return false;
}
res = fread(tag, 128, 1, f);