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 (
"");