2004-07-09 01:05:31 +00:00
|
|
|
|
/*
|
2005-02-24 06:32:57 +00:00
|
|
|
|
$Id: cdtext.c,v 1.3 2005/02/24 06:32:57 rocky Exp $
|
2004-07-09 01:05:31 +00:00
|
|
|
|
|
2005-01-27 03:10:06 +00:00
|
|
|
|
Copyright (C) 2004, 2005 Rocky Bernstein <rocky@panix.com>
|
2004-07-09 01:05:31 +00:00
|
|
|
|
toc reading routine adapted from cuetools
|
|
|
|
|
|
Copyright (C) 2003 Svend Sanjay Sorensen <ssorensen@fastmail.fm>
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
|
# include "config.h"
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#include <cdio/cdtext.h>
|
|
|
|
|
|
#include <cdio/logging.h>
|
2004-07-17 08:59:44 +00:00
|
|
|
|
#include "cdtext_private.h"
|
2004-07-09 01:05:31 +00:00
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_STDLIB_H
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
2004-07-16 21:29:24 +00:00
|
|
|
|
/*! Note: the order and number items (except CDTEXT_INVALID) should
|
|
|
|
|
|
match the cdtext_field_t enumeration. */
|
|
|
|
|
|
const char *cdtext_keywords[] =
|
|
|
|
|
|
{
|
|
|
|
|
|
"ARRANGER",
|
|
|
|
|
|
"COMPOSER",
|
|
|
|
|
|
"DISC_ID",
|
|
|
|
|
|
"GENRE",
|
|
|
|
|
|
"ISRC",
|
|
|
|
|
|
"MESSAGE",
|
|
|
|
|
|
"PERFORMER",
|
|
|
|
|
|
"SIZE_INFO",
|
|
|
|
|
|
"SONGWRITER",
|
|
|
|
|
|
"TITLE",
|
|
|
|
|
|
"TOC_INFO",
|
|
|
|
|
|
"TOC_INFO2",
|
|
|
|
|
|
"UPC_EAN",
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*! Return string representation of the enum values above */
|
|
|
|
|
|
const char *
|
|
|
|
|
|
cdtext_field2str (cdtext_field_t i)
|
|
|
|
|
|
{
|
2004-11-08 04:13:27 +00:00
|
|
|
|
if (i >= MAX_CDTEXT_FIELDS)
|
2004-07-16 21:29:24 +00:00
|
|
|
|
return "Invalid CDTEXT field index";
|
|
|
|
|
|
else
|
|
|
|
|
|
return cdtext_keywords[i];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-07-11 14:25:07 +00:00
|
|
|
|
/*! Free memory assocated with cdtext*/
|
|
|
|
|
|
void
|
2005-01-27 03:10:06 +00:00
|
|
|
|
cdtext_destroy (cdtext_t *p_cdtext)
|
2004-07-09 01:05:31 +00:00
|
|
|
|
{
|
2004-07-11 14:25:07 +00:00
|
|
|
|
cdtext_field_t i;
|
|
|
|
|
|
|
2005-02-24 06:32:57 +00:00
|
|
|
|
if (!p_cdtext) return;
|
2004-07-11 14:25:07 +00:00
|
|
|
|
for (i=0; i < MAX_CDTEXT_FIELDS; i++) {
|
2005-01-27 03:10:06 +00:00
|
|
|
|
if (p_cdtext->field[i]) {
|
|
|
|
|
|
free(p_cdtext->field[i]);
|
|
|
|
|
|
p_cdtext->field[i] = NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-07-11 14:25:07 +00:00
|
|
|
|
}
|
2004-07-09 01:05:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2004-07-11 14:25:07 +00:00
|
|
|
|
/*!
|
|
|
|
|
|
returns the CDTEXT value associated with key. NULL is returned
|
|
|
|
|
|
if key is CDTEXT_INVALID or the field is not set.
|
|
|
|
|
|
*/
|
2005-01-27 03:10:06 +00:00
|
|
|
|
char *
|
|
|
|
|
|
cdtext_get (cdtext_field_t key, const cdtext_t *p_cdtext)
|
2004-07-11 14:25:07 +00:00
|
|
|
|
{
|
|
|
|
|
|
if (key == CDTEXT_INVALID) return NULL;
|
2005-01-27 03:10:06 +00:00
|
|
|
|
return strdup(p_cdtext->field[key]);
|
2004-07-11 14:25:07 +00:00
|
|
|
|
}
|
2004-07-09 01:05:31 +00:00
|
|
|
|
|
2004-07-11 14:25:07 +00:00
|
|
|
|
/*! Initialize a new cdtext structure.
|
|
|
|
|
|
When the structure is no longer needed, release the
|
|
|
|
|
|
resources using cdtext_delete.
|
|
|
|
|
|
*/
|
|
|
|
|
|
void
|
2005-01-27 03:10:06 +00:00
|
|
|
|
cdtext_init (cdtext_t *p_cdtext)
|
2004-07-09 01:05:31 +00:00
|
|
|
|
{
|
2004-07-11 14:25:07 +00:00
|
|
|
|
cdtext_field_t i;
|
|
|
|
|
|
|
|
|
|
|
|
for (i=0; i < MAX_CDTEXT_FIELDS; i++) {
|
2005-01-27 03:10:06 +00:00
|
|
|
|
p_cdtext->field[i] = NULL;
|
2004-07-09 01:05:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
returns 0 if field is a CD-TEXT keyword, returns non-zero otherwise
|
|
|
|
|
|
*/
|
2004-07-11 14:25:07 +00:00
|
|
|
|
cdtext_field_t
|
2004-07-09 02:46:42 +00:00
|
|
|
|
cdtext_is_keyword (const char *key)
|
2004-07-09 01:05:31 +00:00
|
|
|
|
{
|
2004-07-11 02:26:15 +00:00
|
|
|
|
#if 0
|
2004-07-09 01:05:31 +00:00
|
|
|
|
char *item;
|
|
|
|
|
|
|
|
|
|
|
|
item = bsearch(key,
|
|
|
|
|
|
cdtext_keywords, 12,
|
|
|
|
|
|
sizeof (char *),
|
|
|
|
|
|
(int (*)(const void *, const void *))
|
|
|
|
|
|
strcmp);
|
|
|
|
|
|
return (NULL != item) ? 0 : 1;
|
2004-07-11 02:26:15 +00:00
|
|
|
|
#else
|
|
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < 13 ; i++)
|
|
|
|
|
|
if (0 == strcmp (cdtext_keywords[i], key)) {
|
2004-07-11 14:25:07 +00:00
|
|
|
|
return i;
|
2004-07-11 02:26:15 +00:00
|
|
|
|
}
|
2004-07-11 14:25:07 +00:00
|
|
|
|
return CDTEXT_INVALID;
|
2004-07-11 02:26:15 +00:00
|
|
|
|
#endif
|
2004-07-09 01:05:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*! sets cdtext's keyword entry to field.
|
|
|
|
|
|
*/
|
2004-07-17 08:59:44 +00:00
|
|
|
|
void
|
2005-01-27 03:10:06 +00:00
|
|
|
|
cdtext_set (cdtext_field_t key, const char *p_value, cdtext_t *p_cdtext)
|
2004-07-09 01:05:31 +00:00
|
|
|
|
{
|
2005-01-27 03:10:06 +00:00
|
|
|
|
if (NULL == p_value || key == CDTEXT_INVALID) return;
|
2004-07-11 14:25:07 +00:00
|
|
|
|
|
2005-01-27 03:10:06 +00:00
|
|
|
|
if (p_cdtext->field[key]) free (p_cdtext->field[key]);
|
|
|
|
|
|
p_cdtext->field[key] = strdup (p_value);
|
2004-07-11 14:25:07 +00:00
|
|
|
|
|
2004-07-09 02:46:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2004-07-17 08:59:44 +00:00
|
|
|
|
#define SET_CDTEXT_FIELD(FIELD) \
|
2005-01-27 03:10:06 +00:00
|
|
|
|
(*set_cdtext_field_fn)(p_user_data, i_track, i_first_track, FIELD, buffer);
|
2004-07-17 08:59:44 +00:00
|
|
|
|
|
2004-08-30 00:26:59 +00:00
|
|
|
|
/*
|
|
|
|
|
|
parse all CD-TEXT data retrieved.
|
|
|
|
|
|
*/
|
2004-07-17 08:59:44 +00:00
|
|
|
|
bool
|
2005-01-27 03:10:06 +00:00
|
|
|
|
cdtext_data_init(void *p_user_data, track_t i_first_track,
|
2004-09-03 23:20:11 +00:00
|
|
|
|
unsigned char *wdata,
|
2004-07-17 08:59:44 +00:00
|
|
|
|
set_cdtext_field_fn_t set_cdtext_field_fn)
|
|
|
|
|
|
{
|
2005-01-27 03:10:06 +00:00
|
|
|
|
CDText_data_t *p_data;
|
2004-07-17 08:59:44 +00:00
|
|
|
|
int i;
|
|
|
|
|
|
int j;
|
|
|
|
|
|
char buffer[256];
|
|
|
|
|
|
int idx;
|
|
|
|
|
|
int i_track;
|
|
|
|
|
|
bool b_ret = false;
|
|
|
|
|
|
|
|
|
|
|
|
memset( buffer, 0x00, sizeof(buffer) );
|
|
|
|
|
|
idx = 0;
|
|
|
|
|
|
|
2005-01-27 03:10:06 +00:00
|
|
|
|
p_data = (CDText_data_t *) (&wdata[4]);
|
2004-07-17 08:59:44 +00:00
|
|
|
|
for( i=0; i < CDIO_CDTEXT_MAX_PACK_DATA; i++ ) {
|
2004-08-30 00:26:59 +00:00
|
|
|
|
|
2004-08-30 01:59:13 +00:00
|
|
|
|
#if TESTED
|
2005-01-27 03:10:06 +00:00
|
|
|
|
if ( p_data->bDBC ) {
|
2004-08-30 00:26:59 +00:00
|
|
|
|
cdio_warn("Double-byte characters not supported");
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2004-08-30 01:59:13 +00:00
|
|
|
|
#endif
|
2004-08-30 00:26:59 +00:00
|
|
|
|
|
2005-01-27 03:10:06 +00:00
|
|
|
|
if( p_data->seq != i )
|
2004-07-17 08:59:44 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
2005-01-27 03:10:06 +00:00
|
|
|
|
if( (p_data->type >= 0x80)
|
|
|
|
|
|
&& (p_data->type <= 0x85) && (p_data->block == 0) ) {
|
|
|
|
|
|
i_track = p_data->i_track;
|
2004-07-17 08:59:44 +00:00
|
|
|
|
|
|
|
|
|
|
for( j=0; j < CDIO_CDTEXT_MAX_TEXT_DATA; j++ ) {
|
2005-01-27 03:10:06 +00:00
|
|
|
|
if( p_data->text[j] == 0x00 ) {
|
2004-07-17 08:59:44 +00:00
|
|
|
|
bool b_field_set=true;
|
2005-01-27 03:10:06 +00:00
|
|
|
|
switch( p_data->type) {
|
2004-07-17 08:59:44 +00:00
|
|
|
|
case CDIO_CDTEXT_TITLE:
|
|
|
|
|
|
SET_CDTEXT_FIELD(CDTEXT_TITLE);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case CDIO_CDTEXT_PERFORMER:
|
|
|
|
|
|
SET_CDTEXT_FIELD(CDTEXT_PERFORMER);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case CDIO_CDTEXT_SONGWRITER:
|
|
|
|
|
|
SET_CDTEXT_FIELD(CDTEXT_SONGWRITER);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case CDIO_CDTEXT_COMPOSER:
|
|
|
|
|
|
SET_CDTEXT_FIELD(CDTEXT_COMPOSER);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case CDIO_CDTEXT_ARRANGER:
|
|
|
|
|
|
SET_CDTEXT_FIELD(CDTEXT_ARRANGER);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case CDIO_CDTEXT_MESSAGE:
|
|
|
|
|
|
SET_CDTEXT_FIELD(CDTEXT_MESSAGE);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case CDIO_CDTEXT_DISCID:
|
|
|
|
|
|
SET_CDTEXT_FIELD(CDTEXT_DISCID);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case CDIO_CDTEXT_GENRE:
|
|
|
|
|
|
SET_CDTEXT_FIELD(CDTEXT_GENRE);
|
|
|
|
|
|
break;
|
|
|
|
|
|
default : b_field_set = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (b_field_set) {
|
|
|
|
|
|
b_ret = true;
|
|
|
|
|
|
i_track++;
|
|
|
|
|
|
idx = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
2005-01-27 03:10:06 +00:00
|
|
|
|
buffer[idx++] = p_data->text[j];
|
2004-07-17 08:59:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
buffer[idx] = 0x00;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2005-01-27 03:10:06 +00:00
|
|
|
|
p_data++;
|
2004-07-17 08:59:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
return b_ret;
|
|
|
|
|
|
}
|
|
|
|
|
|
|