77 #define BIT(i) ((int64_t) 1 << (i))
158 static pthread_mutex_t
mutex = PTHREAD_MUTEX_INITIALIZER;
175 fprintf (stderr,
"Unknown tuple field name \"%s\".\n", name);
184 return tuple_fields[field].
name;
192 return tuple_fields[field].
type;
197 if ((tuple->setmask &
BIT (field)))
199 for (TupleBlock * block = tuple->blocks; block; block = block->next)
203 if (block->fields[i] == field)
207 tuple->setmask &= ~
BIT (field);
208 block->fields[i] = -1;
211 return & block->vals[i];
220 tuple->setmask |=
BIT (field);
222 for (TupleBlock * block = tuple->blocks; block; block = block->next)
226 if (block->fields[i] < 0)
228 block->fields[i] = field;
229 return & block->vals[i];
234 TupleBlock * block = g_slice_new0 (TupleBlock);
237 block->next = tuple->blocks;
238 tuple->blocks = block;
240 block->fields[0] = field;
241 return & block->vals[0];
247 for (TupleBlock * block = tuple->blocks; block; block = next)
253 int field = block->fields[i];
258 memset (block, 0,
sizeof (TupleBlock));
259 g_slice_free (TupleBlock, block);
262 g_free(tuple->subtunes);
264 memset (tuple, 0,
sizeof (Tuple));
265 g_slice_free (Tuple, tuple);
270 Tuple * tuple = g_slice_new0 (Tuple);
277 pthread_mutex_lock (&
mutex);
281 pthread_mutex_unlock (&
mutex);
287 pthread_mutex_lock (&
mutex);
289 if (! -- tuple->refcount)
292 pthread_mutex_unlock (&
mutex);
305 const char * base, * ext, * sub;
308 uri_parse (filename, & base, & ext, & sub, & isub);
310 char path[base - filename + 1];
314 char name[ext - base + 1];
320 char extbuf[sub - ext];
337 pthread_mutex_lock (&
mutex);
350 newval->
x = oldval->
x;
354 new->nsubtunes = old->nsubtunes;
357 new->subtunes = g_memdup (old->subtunes, sizeof (
int) * old->nsubtunes);
359 pthread_mutex_unlock (&
mutex);
379 EXPORT
void tuple_set_int (Tuple * tuple,
int nfield,
const char * field,
int x)
386 pthread_mutex_lock (&
mutex);
391 pthread_mutex_unlock (&
mutex);
394 EXPORT
void tuple_set_str (Tuple * tuple,
int nfield,
const char * field,
const char * str)
402 if (! g_utf8_validate (str, -1,
NULL))
404 fprintf (stderr,
"Invalid UTF-8: %s\n", str);
413 pthread_mutex_lock (&
mutex);
420 pthread_mutex_unlock (&
mutex);
423 EXPORT
void tuple_unset (Tuple * tuple,
int nfield,
const char * field)
430 pthread_mutex_lock (&
mutex);
444 pthread_mutex_unlock (&
mutex);
464 pthread_mutex_lock (&
mutex);
470 type = tuple_fields[nfield].
type;
472 pthread_mutex_unlock (&
mutex);
476 EXPORT
char *
tuple_get_str (
const Tuple * tuple,
int nfield,
const char * field)
483 pthread_mutex_lock (&
mutex);
491 pthread_mutex_unlock (&
mutex);
507 EXPORT
int tuple_get_int (
const Tuple * tuple,
int nfield,
const char * field)
514 pthread_mutex_lock (&
mutex);
522 pthread_mutex_unlock (&
mutex);
526 #define APPEND(b, ...) snprintf (b + strlen (b), sizeof b - strlen (b), \
545 APPEND (buf, dngettext (PACKAGE,
"%d channel",
"%d channels",
553 APPEND (buf,
"%d kHz", rate / 1000);
564 pthread_mutex_lock (&
mutex);
566 g_free (tuple->subtunes);
567 tuple->subtunes =
NULL;
569 tuple->nsubtunes = n_subtunes;
571 tuple->subtunes = g_memdup (subtunes,
sizeof (
int) * n_subtunes);
573 pthread_mutex_unlock (&
mutex);
578 pthread_mutex_lock (&
mutex);
580 int n_subtunes = tuple->nsubtunes;
582 pthread_mutex_unlock (&
mutex);
588 pthread_mutex_lock (&
mutex);
591 if (n >= 0 && n < tuple->nsubtunes)
592 subtune = tuple->subtunes ? tuple->subtunes[n] : 1 + n;
594 pthread_mutex_unlock (&
mutex);
604 for (
int i = 0; i < G_N_ELEMENTS (fallbacks); i ++)
606 if (title && title[0])
613 return title ? title :
str_get (
"");