2
$Id: cdtext.c,v 1.10 2004/11/08 04:13:27 rocky Exp $
4
Copyright (C) 2004 Rocky Bernstein <rocky@panix.com>
5
toc reading routine adapted from cuetools
6
Copyright (C) 2003 Svend Sanjay Sorensen <ssorensen@fastmail.fm>
8
This program is free software; you can redistribute it and/or modify
9
it under the terms of the GNU General Public License as published by
10
the Free Software Foundation; either version 2 of the License, or
11
(at your option) any later version.
13
This program is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
GNU General Public License for more details.
18
You should have received a copy of the GNU General Public License
19
along with this program; if not, write to the Free Software
20
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27
#include <cdio/cdtext.h>
28
#include <cdio/logging.h>
29
#include "cdtext_private.h"
39
/*! Note: the order and number items (except CDTEXT_INVALID) should
40
match the cdtext_field_t enumeration. */
41
const char *cdtext_keywords[] =
59
/*! Return string representation of the enum values above */
61
cdtext_field2str (cdtext_field_t i)
63
if (i >= MAX_CDTEXT_FIELDS)
64
return "Invalid CDTEXT field index";
66
return cdtext_keywords[i];
70
/*! Free memory assocated with cdtext*/
72
cdtext_destroy (cdtext_t *cdtext)
76
for (i=0; i < MAX_CDTEXT_FIELDS; i++) {
77
if (cdtext->field[i]) free(cdtext->field[i]);
82
returns the CDTEXT value associated with key. NULL is returned
83
if key is CDTEXT_INVALID or the field is not set.
86
cdtext_get (cdtext_field_t key, const cdtext_t *cdtext)
88
if (key == CDTEXT_INVALID) return NULL;
89
return cdtext->field[key];
92
/*! Initialize a new cdtext structure.
93
When the structure is no longer needed, release the
94
resources using cdtext_delete.
97
cdtext_init (cdtext_t *cdtext)
101
for (i=0; i < MAX_CDTEXT_FIELDS; i++) {
102
cdtext->field[i] = NULL;
107
returns 0 if field is a CD-TEXT keyword, returns non-zero otherwise
110
cdtext_is_keyword (const char *key)
118
(int (*)(const void *, const void *))
120
return (NULL != item) ? 0 : 1;
124
for (i = 0; i < 13 ; i++)
125
if (0 == strcmp (cdtext_keywords[i], key)) {
128
return CDTEXT_INVALID;
132
/*! sets cdtext's keyword entry to field.
135
cdtext_set (cdtext_field_t key, const char *value, cdtext_t *cdtext)
137
if (NULL == value || key == CDTEXT_INVALID) return;
139
if (cdtext->field[key]) free (cdtext->field[key]);
140
cdtext->field[key] = strdup (value);
144
#define SET_CDTEXT_FIELD(FIELD) \
145
(*set_cdtext_field_fn)(user_data, i_track, i_first_track, FIELD, buffer);
148
parse all CD-TEXT data retrieved.
151
cdtext_data_init(void *user_data, track_t i_first_track,
152
unsigned char *wdata,
153
set_cdtext_field_fn_t set_cdtext_field_fn)
155
CDText_data_t *pdata;
163
memset( buffer, 0x00, sizeof(buffer) );
166
pdata = (CDText_data_t *) (&wdata[4]);
167
for( i=0; i < CDIO_CDTEXT_MAX_PACK_DATA; i++ ) {
171
cdio_warn("Double-byte characters not supported");
176
if( pdata->seq != i )
179
if( (pdata->type >= 0x80)
180
&& (pdata->type <= 0x85) && (pdata->block == 0) ) {
181
i_track = pdata->i_track;
183
for( j=0; j < CDIO_CDTEXT_MAX_TEXT_DATA; j++ ) {
184
if( pdata->text[j] == 0x00 ) {
185
bool b_field_set=true;
186
switch( pdata->type) {
187
case CDIO_CDTEXT_TITLE:
188
SET_CDTEXT_FIELD(CDTEXT_TITLE);
190
case CDIO_CDTEXT_PERFORMER:
191
SET_CDTEXT_FIELD(CDTEXT_PERFORMER);
193
case CDIO_CDTEXT_SONGWRITER:
194
SET_CDTEXT_FIELD(CDTEXT_SONGWRITER);
196
case CDIO_CDTEXT_COMPOSER:
197
SET_CDTEXT_FIELD(CDTEXT_COMPOSER);
199
case CDIO_CDTEXT_ARRANGER:
200
SET_CDTEXT_FIELD(CDTEXT_ARRANGER);
202
case CDIO_CDTEXT_MESSAGE:
203
SET_CDTEXT_FIELD(CDTEXT_MESSAGE);
205
case CDIO_CDTEXT_DISCID:
206
SET_CDTEXT_FIELD(CDTEXT_DISCID);
208
case CDIO_CDTEXT_GENRE:
209
SET_CDTEXT_FIELD(CDTEXT_GENRE);
211
default : b_field_set = false;
219
buffer[idx++] = pdata->text[j];