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);
286 pthread_mutex_lock (&
mutex);
288 if (! -- tuple->refcount)
291 pthread_mutex_unlock (&
mutex);
304 const char * base, * ext, * sub;
307 uri_parse (filename, & base, & ext, & sub, & isub);
309 char path[base - filename + 1];
313 char name[ext - base + 1];
319 char extbuf[sub - ext];
336 pthread_mutex_lock (&
mutex);
349 newval->
x = oldval->
x;
353 new->nsubtunes = old->nsubtunes;
356 new->subtunes = g_memdup (old->subtunes, sizeof (
int) * old->nsubtunes);
358 pthread_mutex_unlock (&
mutex);
378 EXPORT
void tuple_set_int (Tuple * tuple,
int nfield,
const char * field,
int x)
385 pthread_mutex_lock (&
mutex);
390 pthread_mutex_unlock (&
mutex);
393 EXPORT
void tuple_set_str (Tuple * tuple,
int nfield,
const char * field,
const char * str)
401 if (! g_utf8_validate (str, -1,
NULL))
403 fprintf (stderr,
"Invalid UTF-8: %s\n", str);
412 pthread_mutex_lock (&
mutex);
419 pthread_mutex_unlock (&
mutex);
422 EXPORT
void tuple_unset (Tuple * tuple,
int nfield,
const char * field)
429 pthread_mutex_lock (&
mutex);
443 pthread_mutex_unlock (&
mutex);
463 pthread_mutex_lock (&
mutex);
469 type = tuple_fields[nfield].
type;
471 pthread_mutex_unlock (&
mutex);
475 EXPORT
char *
tuple_get_str (
const Tuple * tuple,
int nfield,
const char * field)
482 pthread_mutex_lock (&
mutex);
490 pthread_mutex_unlock (&
mutex);
506 EXPORT
int tuple_get_int (
const Tuple * tuple,
int nfield,
const char * field)
513 pthread_mutex_lock (&
mutex);
521 pthread_mutex_unlock (&
mutex);
525 #define APPEND(b, ...) snprintf (b + strlen (b), sizeof b - strlen (b), \
544 APPEND (buf, dngettext (PACKAGE,
"%d channel",
"%d channels",
552 APPEND (buf,
"%d kHz", rate / 1000);
563 pthread_mutex_lock (&
mutex);
565 g_free (tuple->subtunes);
566 tuple->subtunes =
NULL;
568 tuple->nsubtunes = n_subtunes;
570 tuple->subtunes = g_memdup (subtunes,
sizeof (
int) * n_subtunes);
572 pthread_mutex_unlock (&
mutex);
577 pthread_mutex_lock (&
mutex);
579 int n_subtunes = tuple->nsubtunes;
581 pthread_mutex_unlock (&
mutex);
587 pthread_mutex_lock (&
mutex);
590 if (n >= 0 && n < tuple->nsubtunes)
591 subtune = tuple->subtunes ? tuple->subtunes[n] : 1 + n;
593 pthread_mutex_unlock (&
mutex);
603 for (
int i = 0; i < G_N_ELEMENTS (fallbacks); i ++)
605 if (title && title[0])
612 return title ? title :
str_get (
"");