add empdd support for song xtags

This commit is contained in:
Mike Blumenkrantz 2016-10-02 10:48:37 -04:00
parent cf2057ae96
commit 399976045b
6 changed files with 109 additions and 27 deletions

View File

@ -68,6 +68,7 @@ void Empd_Empdd_Song_free(Empd_Empdd_Song * val)
eina_stringshare_del(val->name); eina_stringshare_del(val->name);
eina_stringshare_del(val->date); eina_stringshare_del(val->date);
eina_stringshare_del(val->disc); eina_stringshare_del(val->disc);
eina_stringshare_del(val->albumimage);
free(val); free(val);
} }
@ -91,6 +92,7 @@ Empd_Empdd_Song * Empd_Empdd_Song_copy(Empd_Empdd_Song * orig)
copy->disc = eina_stringshare_ref(orig->disc); copy->disc = eina_stringshare_ref(orig->disc);
copy->song_pos = orig->song_pos; copy->song_pos = orig->song_pos;
copy->songid = orig->songid; copy->songid = orig->songid;
copy->albumimage = eina_stringshare_ref(orig->albumimage);
return copy; return copy;
} }
@ -125,6 +127,8 @@ Eina_Bool Empd_Empdd_Song_eq(Empd_Empdd_Song * a, Empd_Empdd_Song * b)
return EINA_FALSE; return EINA_FALSE;
if (a->songid != b->songid) if (a->songid != b->songid)
return EINA_FALSE; return EINA_FALSE;
if (a->albumimage != b->albumimage)
return EINA_FALSE;
return EINA_TRUE; return EINA_TRUE;
} }
@ -171,6 +175,9 @@ void Empd_Empdd_Song_print(const char *pre, int indent, const Empd_Empdd_Song *a
for (i = 0; i < indent; i++) for (i = 0; i < indent; i++)
printf("%s", pre); printf("%s", pre);
printf("songid: %i\n", a->songid); printf("songid: %i\n", a->songid);
for (i = 0; i < indent; i++)
printf("%s", pre);
printf("albumimage: %s\n", a->albumimage);
} }
Eina_Bool Empd_Empdd_Song_isnull(Empd_Empdd_Song * a) Eina_Bool Empd_Empdd_Song_isnull(Empd_Empdd_Song * a)
@ -201,6 +208,8 @@ Eina_Bool Empd_Empdd_Song_isnull(Empd_Empdd_Song * a)
return EINA_FALSE; return EINA_FALSE;
if (a->songid != 0) if (a->songid != 0)
return EINA_FALSE; return EINA_FALSE;
if (a->albumimage != NULL)
return EINA_FALSE;
return EINA_TRUE; return EINA_TRUE;
} }

View File

@ -30,6 +30,7 @@ struct Empd_Empdd_Song
Eina_Stringshare * disc; /* */ Eina_Stringshare * disc; /* */
int song_pos; /* */ int song_pos; /* */
int songid; /* */ int songid; /* */
Eina_Stringshare * albumimage; /* */
}; };
static inline Empd_Empdd_Song *Empd_Empdd_Song_new(void) static inline Empd_Empdd_Song *Empd_Empdd_Song_new(void)

View File

@ -11,9 +11,9 @@ Eina_Value *Empd_Empdd_Song_to_azy_value(const Empd_Empdd_Song * azy_user_type)
if (!azy_user_type) return NULL; if (!azy_user_type) return NULL;
st_desc = eina_value_util_struct_desc_new(); st_desc = eina_value_util_struct_desc_new();
members = malloc(12 * sizeof(Eina_Value_Struct_Member)); members = malloc(13 * sizeof(Eina_Value_Struct_Member));
st_desc->members = members; st_desc->members = members;
st_desc->member_count = 12; st_desc->member_count = 13;
members[0].name = eina_stringshare_add("uri"); members[0].name = eina_stringshare_add("uri");
offset = eina_value_util_type_offset(EINA_VALUE_TYPE_STRINGSHARE, offset); offset = eina_value_util_type_offset(EINA_VALUE_TYPE_STRINGSHARE, offset);
members[0].offset = offset; members[0].offset = offset;
@ -74,6 +74,11 @@ Eina_Value *Empd_Empdd_Song_to_azy_value(const Empd_Empdd_Song * azy_user_type)
members[11].offset = offset; members[11].offset = offset;
offset += eina_value_util_type_size(EINA_VALUE_TYPE_INT); offset += eina_value_util_type_size(EINA_VALUE_TYPE_INT);
members[11].type = EINA_VALUE_TYPE_INT; members[11].type = EINA_VALUE_TYPE_INT;
members[12].name = eina_stringshare_add("albumimage");
offset = eina_value_util_type_offset(EINA_VALUE_TYPE_STRINGSHARE, offset);
members[12].offset = offset;
offset += eina_value_util_type_size(EINA_VALUE_TYPE_STRINGSHARE);
members[12].type = EINA_VALUE_TYPE_STRINGSHARE;
st_desc->size = offset; st_desc->size = offset;
value_struct = eina_value_struct_new(st_desc); value_struct = eina_value_struct_new(st_desc);
@ -113,6 +118,9 @@ Eina_Value *Empd_Empdd_Song_to_azy_value(const Empd_Empdd_Song * azy_user_type)
val = eina_value_util_int_new(azy_user_type->songid); val = eina_value_util_int_new(azy_user_type->songid);
eina_value_struct_value_set(value_struct, "songid", val); eina_value_struct_value_set(value_struct, "songid", val);
eina_value_free(val); eina_value_free(val);
val = eina_value_util_stringshare_new(azy_user_type->albumimage);
eina_value_struct_value_set(value_struct, "albumimage", val);
eina_value_free(val);
return value_struct; return value_struct;
} }
@ -365,6 +373,29 @@ Eina_Bool azy_value_to_Empd_Empdd_Song(const Eina_Value *value_struct, Empd_Empd
eina_value_flush(&val); eina_value_flush(&val);
} }
found = EINA_FALSE; found = EINA_FALSE;
if ((!arg) && eina_value_struct_value_get(value_struct, "albumimage", &val))
found = EINA_TRUE;
else
{
char buf[128];
snprintf(buf, sizeof(buf), "arg%d", arg++);
if (eina_value_struct_value_get(value_struct, buf, &val))
found = EINA_TRUE;
}
if (found)
{
if (arg)
{
char *str = NULL;
if (eina_value_get(&val, &str))
azy_user_type_tmp->albumimage = eina_stringshare_add(str);
}
else
eina_value_util_stringshare_copy(&val, &azy_user_type_tmp->albumimage);
eina_value_flush(&val);
}
found = EINA_FALSE;
*azy_user_type = azy_user_type_tmp; *azy_user_type = azy_user_type_tmp;
return EINA_TRUE; return EINA_TRUE;

View File

@ -14,6 +14,7 @@ struct Empdd_Song
string disc; string disc;
int song_pos; int song_pos;
int songid; int songid;
string albumimage;
}; };
struct Array_Songs struct Array_Songs

View File

@ -36,8 +36,11 @@ typedef struct EMPD
Eina_List *pending; Eina_List *pending;
Eina_List *pending_xtags;
Eina_List *current_queue; Eina_List *current_queue;
Eina_List *current_queue_xtags;
void *cur; void *cur;
Eina_Hash *cur_xtags;
E_Slist *cmds, *last; E_Slist *cmds, *last;
unsigned int reconnect_fail; unsigned int reconnect_fail;
@ -145,7 +148,7 @@ static const Eldbus_Signal empd_signals[] =
{"u", "update_id"}), 0}, {"u", "update_id"}), 0},
[EMPD_SIGNAL_CURRENT_SONG] = {"CurrentSong", ELDBUS_ARGS({"s", "uri"}, {"t", "last_modified"}, {"u", "duration"}, [EMPD_SIGNAL_CURRENT_SONG] = {"CurrentSong", ELDBUS_ARGS({"s", "uri"}, {"t", "last_modified"}, {"u", "duration"},
{"s", "artist"}, {"s", "composer"}, {"s", "title"}, {"s", "album"}, {"i", "track"}, {"s", "artist"}, {"s", "composer"}, {"s", "title"}, {"s", "album"}, {"i", "track"},
{"s", "name"}, {"s", "date"}, {"s", "disc"}, {"s", "genre"}, {"i", "song_pos"}, {"i", "songid"}), 0}, {"s", "name"}, {"s", "date"}, {"s", "disc"}, {"s", "genre"}, {"i", "song_pos"}, {"i", "songid"}, {"s", "albumimage"}), 0},
[EMPD_SIGNAL_QUEUE_LIST] = {"QueueList", ELDBUS_ARGS({"a(stusssisssii)", "array_of_songs"}), 0}, [EMPD_SIGNAL_QUEUE_LIST] = {"QueueList", ELDBUS_ARGS({"a(stusssisssii)", "array_of_songs"}), 0},
[EMPD_SIGNAL_QUEUE_CHANGES_META] = {"QueueChangesMeta", ELDBUS_ARGS({"a(stusssisssii)", "array_of_songs"}), 0}, [EMPD_SIGNAL_QUEUE_CHANGES_META] = {"QueueChangesMeta", ELDBUS_ARGS({"a(stusssisssii)", "array_of_songs"}), 0},
[EMPD_SIGNAL_DATABASE_UPDATE_BEGIN] = {"DatabaseUpdateBegin", NULL, 0}, [EMPD_SIGNAL_DATABASE_UPDATE_BEGIN] = {"DatabaseUpdateBegin", NULL, 0},
@ -346,29 +349,37 @@ pinger_cb(void *d EINA_UNUSED)
} }
static void static void
queue_list_info_send(Eldbus_Message *msg, Eina_List *queue_list, unsigned int start, long num, Eina_Bool sig) queue_list_info_send(Eldbus_Message *msg, Eina_List *queue_list, Eina_List *queue_list_xtags, unsigned int start, long num, Eina_Bool sig)
{ {
Eldbus_Message_Iter *iter, *array, *struc; Eldbus_Message_Iter *iter, *array, *struc;
Eina_List *l; Eina_List *l, *ll = queue_list_xtags;
struct mpd_song *so; struct mpd_song *so;
unsigned int cur = 0; unsigned int cur = 0;
iter = eldbus_message_iter_get(msg); iter = eldbus_message_iter_get(msg);
array = eldbus_message_iter_container_new(iter, 'a', "(stusssisssii)"); array = eldbus_message_iter_container_new(iter, 'a', "(stusssisssiis)");
EINA_LIST_FOREACH(queue_list, l, so) EINA_LIST_FOREACH(queue_list, l, so)
{ {
/* holy shit. */ /* holy shit. */
const char *track = mpd_song_get_tag(so, MPD_TAG_TRACK, 0); const char *track = mpd_song_get_tag(so, MPD_TAG_TRACK, 0);
const char *albumimage;
Eina_Hash *h = eina_list_data_get(ll);
if (cur++ < start) continue; if (cur++ < start)
eldbus_message_iter_arguments_append(array, "(stusssisssii)", &struc); {
eldbus_message_iter_arguments_append(struc, "stusssisssii", ll = ll->next;
continue;
}
albumimage = eina_hash_find(h, "X-AlbumImage");
eldbus_message_iter_arguments_append(array, "(stusssisssiis)", &struc);
eldbus_message_iter_arguments_append(struc, "stusssisssiis",
STRING_SAFETY(mpd_song_get_uri(so)), mpd_song_get_last_modified(so), mpd_song_get_duration(so), STRING_SAFETY(mpd_song_get_uri(so)), mpd_song_get_last_modified(so), mpd_song_get_duration(so),
STRING_SAFETY(mpd_song_get_tag(so, MPD_TAG_ARTIST, 0)), STRING_SAFETY(mpd_song_get_tag(so, MPD_TAG_TITLE, 0)), STRING_SAFETY(mpd_song_get_tag(so, MPD_TAG_ARTIST, 0)), STRING_SAFETY(mpd_song_get_tag(so, MPD_TAG_TITLE, 0)),
STRING_SAFETY(mpd_song_get_tag(so, MPD_TAG_ALBUM, 0)), STRING_SAFETY(mpd_song_get_tag(so, MPD_TAG_ALBUM, 0)),
track ? atoi(track) : 0, STRING_SAFETY(mpd_song_get_tag(so, MPD_TAG_NAME, 0)), STRING_SAFETY(mpd_song_get_tag(so, MPD_TAG_DATE, 0)), track ? atoi(track) : 0, STRING_SAFETY(mpd_song_get_tag(so, MPD_TAG_NAME, 0)), STRING_SAFETY(mpd_song_get_tag(so, MPD_TAG_DATE, 0)),
STRING_SAFETY(mpd_song_get_tag(so, MPD_TAG_DISC, 0)), mpd_song_get_pos(so), mpd_song_get_id(so)); STRING_SAFETY(mpd_song_get_tag(so, MPD_TAG_DISC, 0)), mpd_song_get_pos(so), mpd_song_get_id(so), STRING_SAFETY(albumimage));
eldbus_message_iter_container_close(array, struc); eldbus_message_iter_container_close(array, struc);
ll = ll->next;
if (mpd_song_get_pos(so) == num) break; if (mpd_song_get_pos(so) == num) break;
} }
eldbus_message_iter_container_close(iter, array); eldbus_message_iter_container_close(iter, array);
@ -383,7 +394,7 @@ queue_list_send(Eldbus_Message *msg, unsigned int start, long num)
if (!msg) if (!msg)
msg = eldbus_service_signal_new(empd_iface, EMPD_SIGNAL_QUEUE_LIST); msg = eldbus_service_signal_new(empd_iface, EMPD_SIGNAL_QUEUE_LIST);
queue_list_info_send(msg, empd->current_queue, start, num, sig); queue_list_info_send(msg, empd->current_queue, empd->current_queue_xtags, start, num, sig);
} }
static Eina_Bool static Eina_Bool
@ -619,31 +630,43 @@ fdh_func(void *d EINA_UNUSED, Ecore_Fd_Handler *fdh EINA_UNUSED)
if (res == MPD_PARSER_PAIR) if (res == MPD_PARSER_PAIR)
{ {
if (!empd->cur) int i;
for (i = 0; i < 2; i++)
{ {
empd->cur = mpd_song_begin(&(struct mpd_pair){name, value}); if (!empd->cur)
break; {
} empd->cur = mpd_song_begin(&(struct mpd_pair){name, value});
mpd_song_feed(so, &(struct mpd_pair){name, value}); empd->cur_xtags = eina_hash_string_superfast_new(free);
//fprintf(stderr, "[%s]|FEED\n", cmd_txt[cmd_get()]); break;
if (cmd_get() != EMPD_COMMAND_CURRENT_SONG) }
{ if (mpd_song_feed(so, &(struct mpd_pair){name, value}))
if (!strcmp(name, "Id")) {
if (mpd_tag_name_parse(name) == MPD_TAG_UNKNOWN)
eina_hash_add(empd->cur_xtags, name, strdup(value ?: ""));
break;
}
else if (cmd_get() != EMPD_COMMAND_CURRENT_SONG)
{ {
/* at end of current song, push to list /* at end of current song, push to list
* for sending all at once later * for sending all at once later
*/ */
empd->pending = eina_list_append(empd->pending, so); empd->pending = eina_list_append(empd->pending, so);
empd->pending_xtags = eina_list_append(empd->pending_xtags, empd->cur_xtags);
empd->cur = NULL; empd->cur = NULL;
empd->cur_xtags = NULL;
} }
} }
//fprintf(stderr, "[%s]|FEED\n", cmd_txt[cmd_get()]);
} }
else if (cmd_get() == EMPD_COMMAND_CURRENT_SONG) else if (cmd_get() == EMPD_COMMAND_CURRENT_SONG)
{ {
const char *track; const char *track;
char *albumimage;
if (!so) break; //no current song if (!so) break; //no current song
track = mpd_song_get_tag(so, MPD_TAG_TRACK, 0); track = mpd_song_get_tag(so, MPD_TAG_TRACK, 0);
albumimage = eina_hash_find(empd->cur_xtags, "X-AlbumImage");
//fprintf(stderr, "CURRENT\n"); //fprintf(stderr, "CURRENT\n");
@ -653,19 +676,21 @@ fdh_func(void *d EINA_UNUSED, Ecore_Fd_Handler *fdh EINA_UNUSED)
STRING_SAFETY(mpd_song_get_tag(so, MPD_TAG_TITLE, 0)), STRING_SAFETY(mpd_song_get_tag(so, MPD_TAG_ALBUM, 0)), STRING_SAFETY(mpd_song_get_tag(so, MPD_TAG_TITLE, 0)), STRING_SAFETY(mpd_song_get_tag(so, MPD_TAG_ALBUM, 0)),
track ? atoi(track) : 0, STRING_SAFETY(mpd_song_get_tag(so, MPD_TAG_NAME, 0)), STRING_SAFETY(mpd_song_get_tag(so, MPD_TAG_DATE, 0)), track ? atoi(track) : 0, STRING_SAFETY(mpd_song_get_tag(so, MPD_TAG_NAME, 0)), STRING_SAFETY(mpd_song_get_tag(so, MPD_TAG_DATE, 0)),
STRING_SAFETY(mpd_song_get_tag(so, MPD_TAG_DISC, 0)), STRING_SAFETY(mpd_song_get_tag(so, MPD_TAG_GENRE, 0)), STRING_SAFETY(mpd_song_get_tag(so, MPD_TAG_DISC, 0)), STRING_SAFETY(mpd_song_get_tag(so, MPD_TAG_GENRE, 0)),
mpd_song_get_pos(so), mpd_song_get_id(so)); mpd_song_get_pos(so), mpd_song_get_id(so), STRING_SAFETY(albumimage));
mpd_song_free(so); mpd_song_free(so);
} }
else if (cmd_get() == EMPD_COMMAND_QUEUE_CHANGES_META) else if (cmd_get() == EMPD_COMMAND_QUEUE_CHANGES_META)
{ {
Eina_List *l, *ll; Eina_List *l, *ll;
Eldbus_Message *msg; Eldbus_Message *msg;
Eina_Hash *h;
unsigned int n;
if (res != MPD_PARSER_SUCCESS) if (res != MPD_PARSER_SUCCESS)
break; break;
msg = eldbus_service_signal_new(empd_iface, EMPD_SIGNAL_QUEUE_CHANGES_META); msg = eldbus_service_signal_new(empd_iface, EMPD_SIGNAL_QUEUE_CHANGES_META);
queue_list_info_send(msg, empd->pending, 0, -1, 1); queue_list_info_send(msg, empd->pending, empd->pending_xtags, 0, -1, 1);
if (!empd->pending) if (!empd->pending)
{ {
while (eina_list_count(empd->current_queue) > empd_queue_length) while (eina_list_count(empd->current_queue) > empd_queue_length)
@ -673,25 +698,39 @@ fdh_func(void *d EINA_UNUSED, Ecore_Fd_Handler *fdh EINA_UNUSED)
mpd_song_free(eina_list_last_data_get(empd->current_queue)); mpd_song_free(eina_list_last_data_get(empd->current_queue));
empd->current_queue = eina_list_remove_list(empd->current_queue, empd->current_queue = eina_list_remove_list(empd->current_queue,
eina_list_last(empd->current_queue)); eina_list_last(empd->current_queue));
eina_hash_free(eina_list_last_data_get(empd->current_queue_xtags));
empd->current_queue_xtags = eina_list_remove_list(empd->current_queue_xtags,
eina_list_last(empd->current_queue_xtags));
} }
break; break;
} }
so = eina_list_data_get(empd->pending); so = eina_list_data_get(empd->pending);
EINA_LIST_FOREACH_SAFE(eina_list_nth_list(empd->current_queue, mpd_song_get_pos(so)), l, ll, so) n = mpd_song_get_pos(so);
EINA_LIST_FOREACH_SAFE(eina_list_nth_list(empd->current_queue, n), l, ll, so)
{ {
mpd_song_free(so); mpd_song_free(so);
empd->current_queue = eina_list_remove_list(empd->current_queue, l); empd->current_queue = eina_list_remove_list(empd->current_queue, l);
} }
EINA_LIST_FOREACH_SAFE(eina_list_nth_list(empd->current_queue_xtags, n), l, ll, h)
{
eina_hash_free(h);
empd->current_queue_xtags = eina_list_remove_list(empd->current_queue_xtags, l);
}
empd->current_queue = eina_list_merge(empd->current_queue, empd->pending); empd->current_queue = eina_list_merge(empd->current_queue, empd->pending);
empd->current_queue_xtags = eina_list_merge(empd->current_queue_xtags, empd->pending_xtags);
empd->pending = NULL; empd->pending = NULL;
empd->pending_xtags = NULL;
} }
else if (cmd_get() == EMPD_COMMAND_QUEUE_LIST) else if (cmd_get() == EMPD_COMMAND_QUEUE_LIST)
{ {
if (res != MPD_PARSER_SUCCESS) if (res != MPD_PARSER_SUCCESS)
break; break;
E_FREE_LIST(empd->current_queue, mpd_song_free); E_FREE_LIST(empd->current_queue, mpd_song_free);
E_FREE_LIST(empd->current_queue_xtags, eina_hash_free);
empd->current_queue = empd->pending; empd->current_queue = empd->pending;
empd->current_queue_xtags = empd->pending_xtags;
empd->pending = NULL; empd->pending = NULL;
empd->pending_xtags = NULL;
if (empd->current_queue) if (empd->current_queue)
queue_list_send(NULL, 0, -1); queue_list_send(NULL, 0, -1);
} }

View File

@ -62,12 +62,12 @@
<annotation name="org.freedesktop.DBus.Method.NoReply" value="true" /> <annotation name="org.freedesktop.DBus.Method.NoReply" value="true" />
</method> </method>
<method name="QueueListCached"> <method name="QueueListCached">
<arg type="a(stusssisssii)" name="array_of_songs" direction="out" /> <arg type="a(stusssisssiis)" name="array_of_songs" direction="out" />
</method> </method>
<method name="QueueListCachedRange"> <method name="QueueListCachedRange">
<arg type="i" name="start" direction="in" /> <arg type="i" name="start" direction="in" />
<arg type="i" name="num" direction="in" /> <arg type="i" name="num" direction="in" />
<arg type="a(stusssisssii)" name="array_of_songs" direction="out" /> <arg type="a(stusssisssiis)" name="array_of_songs" direction="out" />
</method> </method>
<method name="ClearList"> <method name="ClearList">
<annotation name="org.freedesktop.DBus.Method.NoReply" value="true" /> <annotation name="org.freedesktop.DBus.Method.NoReply" value="true" />
@ -171,12 +171,13 @@
<arg type="s" name="genre" direction="out" /> <arg type="s" name="genre" direction="out" />
<arg type="i" name="song_pos" direction="out" /> <arg type="i" name="song_pos" direction="out" />
<arg type="i" name="songid" direction="out" /> <arg type="i" name="songid" direction="out" />
<arg type="s" name="albumimage" direction="out" />
</signal> </signal>
<signal name="QueueList"> <signal name="QueueList">
<arg type="a(stusssisssii)" name="array_of_songs" direction="out" /> <arg type="a(stusssisssiis)" name="array_of_songs" direction="out" />
</signal> </signal>
<signal name="QueueChangesMeta"> <signal name="QueueChangesMeta">
<arg type="a(stusssisssii)" name="array_of_songs" direction="out" /> <arg type="a(stusssisssiis)" name="array_of_songs" direction="out" />
</signal> </signal>
<signal name="LoginFailed"> <signal name="LoginFailed">
<arg type="s" name="host" direction="out" /> <arg type="s" name="host" direction="out" />