76 #define BIT(i) ((int64_t) 1 << (i))
157 static pthread_mutex_t
mutex = PTHREAD_MUTEX_INITIALIZER;
174 fprintf (stderr,
"Unknown tuple field name \"%s\".\n", name);
183 return tuple_fields[field].
name;
191 return tuple_fields[field].
type;
196 if ((tuple->setmask &
BIT (field)))
198 for (TupleBlock * block = tuple->blocks; block; block = block->next)
202 if (block->fields[i] == field)
206 tuple->setmask &= ~
BIT (field);
207 block->fields[i] = -1;
210 return & block->vals[i];
219 tuple->setmask |=
BIT (field);
221 for (TupleBlock * block = tuple->blocks; block; block = block->next)
225 if (block->fields[i] < 0)
227 block->fields[i] = field;
228 return & block->vals[i];
233 TupleBlock * block = g_slice_new0 (TupleBlock);
236 block->next = tuple->blocks;
237 tuple->blocks = block;
239 block->fields[0] = field;
240 return & block->vals[0];
246 for (TupleBlock * block = tuple->blocks; block; block = next)
252 int field = block->fields[i];
257 memset (block, 0,
sizeof (TupleBlock));
258 g_slice_free (TupleBlock, block);
261 g_free(tuple->subtunes);
263 memset (tuple, 0,
sizeof (Tuple));
264 g_slice_free (Tuple, tuple);
269 Tuple * tuple = g_slice_new0 (Tuple);
276 pthread_mutex_lock (&
mutex);
280 pthread_mutex_unlock (&
mutex);
289 pthread_mutex_lock (&
mutex);
291 if (! -- tuple->refcount)
294 pthread_mutex_unlock (&
mutex);
307 const char * base, * ext, * sub;
310 uri_parse (filename, & base, & ext, & sub, & isub);
312 char path[base - filename + 1];
316 char name[ext - base + 1];
322 char extbuf[sub - ext];
339 pthread_mutex_lock (&
mutex);
352 newval->
x = oldval->
x;
356 new->nsubtunes = old->nsubtunes;
359 new->subtunes = g_memdup (old->subtunes, sizeof (
int) * old->nsubtunes);
361 pthread_mutex_unlock (&
mutex);
381 EXPORT
void tuple_set_int (Tuple * tuple,
int nfield,
const char * field,
int x)
388 pthread_mutex_lock (&
mutex);
393 pthread_mutex_unlock (&
mutex);
396 EXPORT
void tuple_set_str (Tuple * tuple,
int nfield,
const char * field,
const char * str)
404 if (! g_utf8_validate (str, -1,
NULL))
406 fprintf (stderr,
"Invalid UTF-8: %s\n", str);
415 pthread_mutex_lock (&
mutex);
422 pthread_mutex_unlock (&
mutex);
425 EXPORT
void tuple_unset (Tuple * tuple,
int nfield,
const char * field)
432 pthread_mutex_lock (&
mutex);
446 pthread_mutex_unlock (&
mutex);
466 pthread_mutex_lock (&
mutex);
472 type = tuple_fields[nfield].
type;
474 pthread_mutex_unlock (&
mutex);
478 EXPORT
char *
tuple_get_str (
const Tuple * tuple,
int nfield,
const char * field)
485 pthread_mutex_lock (&
mutex);
493 pthread_mutex_unlock (&
mutex);
509 EXPORT
int tuple_get_int (
const Tuple * tuple,
int nfield,
const char * field)
516 pthread_mutex_lock (&
mutex);
524 pthread_mutex_unlock (&
mutex);
528 #define APPEND(b, ...) snprintf (b + strlen (b), sizeof b - strlen (b), \
547 APPEND (buf, dngettext (PACKAGE,
"%d channel",
"%d channels",
555 APPEND (buf,
"%d kHz", rate / 1000);
566 pthread_mutex_lock (&
mutex);
568 g_free (tuple->subtunes);
569 tuple->subtunes =
NULL;
571 tuple->nsubtunes = n_subtunes;
573 tuple->subtunes = g_memdup (subtunes,
sizeof (
int) * n_subtunes);
575 pthread_mutex_unlock (&
mutex);
580 pthread_mutex_lock (&
mutex);
582 int n_subtunes = tuple->nsubtunes;
584 pthread_mutex_unlock (&
mutex);
590 pthread_mutex_lock (&
mutex);
593 if (n >= 0 && n < tuple->nsubtunes)
594 subtune = tuple->subtunes ? tuple->subtunes[n] : 1 + n;
596 pthread_mutex_unlock (&
mutex);
606 for (
int i = 0; i < G_N_ELEMENTS (fallbacks); i ++)
608 if (title && title[0])
615 return title ? title :
str_get (
"");
Structure for holding and passing around miscellaneous track metadata.
TupleVal vals[BLOCK_VALS]
Total number of subsongs in the file.
int nsubtunes
Number of subtunes, if any.
static float a[EQ_BANDS][2]
EXPORT void tuple_set_str(Tuple *tuple, int nfield, const char *field, const char *str)
String representing quality, such as "lossy", "lossless", "sequenced".
static pthread_mutex_t mutex
static float b[EQ_BANDS][2]
File name part of the location URI.
Index number of subsong/tune.
EXPORT int tuple_field_by_name(const char *name)
EXPORT void tuple_set_int(Tuple *tuple, int nfield, const char *field, int x)
static TupleVal * lookup_val(Tuple *tuple, int field, bool_t add, bool_t remove)
EXPORT void str_decode_percent(const char *str, int len, char *out)
Composer of song, if different than artist.
Path part of the location URI.
EXPORT void tuple_set_filename(Tuple *tuple, const char *filename)
Sets filename/URI related fields of a #Tuple structure, based on the given filename argument...
char * str_ref(char *str)
EXPORT Tuple * tuple_new(void)
EXPORT void tuple_set_subtunes(Tuple *tuple, int n_subtunes, const int *subtunes)
static void tuple_destroy_unlocked(Tuple *tuple)
int * subtunes
Array of int containing subtune index numbers.
EXPORT void tuple_unref(Tuple *tuple)
EXPORT TupleValueType tuple_field_get_type(int field)
EXPORT const char * tuple_field_get_name(int field)
EXPORT void tuple_unset(Tuple *tuple, int nfield, const char *field)
EXPORT Tuple * tuple_copy(const Tuple *old)
Creates a copy of given Tuple structure, with copied data.
EXPORT char * tuple_format_title(Tuple *tuple, const char *format)
EXPORT int tuple_get_nth_subtune(Tuple *tuple, int n)
void str_unref(char *str)
EXPORT void uri_parse(const char *uri, const char **base_p, const char **ext_p, const char **sub_p, int *isub_p)
Filename extension part of the location URI.
EXPORT char * tuple_get_str(const Tuple *tuple, int nfield, const char *field)
EXPORT Tuple * tuple_new_from_filename(const char *filename)
Allocates a new #Tuple structure, setting filename/URI related fields based on the given filename arg...
EXPORT Tuple * tuple_ref(Tuple *tuple)
EXPORT TupleValueType tuple_get_value_type(const Tuple *tuple, int nfield, const char *field)
Returns TupleValueType of given #Tuple field.
Basic Tuple handling API.
static const TupleBasicType tuple_fields[TUPLE_FIELDS]
Ordered table of basic #Tuple field names and their TupleValueType.
Track length in milliseconds.
static const FieldDictEntry field_dict[TUPLE_FIELDS]
EXPORT int tuple_get_n_subtunes(Tuple *tuple)
static int field_dict_compare(const void *a, const void *b)
EXPORT void tuple_set_format(Tuple *t, const char *format, int chans, int rate, int brate)
char * str_get(const char *str)
Year of production/performance/etc.
EXPORT int tuple_get_int(const Tuple *tuple, int nfield, const char *field)
Returns integer associated to #Tuple field.