Author: Pedro Lucas Porcellis <porcellis@eletrotupi.com>
queue: initial riggings to queue dealing
configure | 1 include/queue.h | 8 +++++ src/queue.c | 60 +++++++++++++++++++++++++++++++++++++++++ src/seamus.c | 73 ---------------------------------------------------
diff --git a/configure b/configure index a6acc3c3645795866b72eab45b4b72042756efd5..bc602f7940baa4372b23e97d44511e1992a4ec08 100755 --- a/configure +++ b/configure @@ -8,6 +8,7 @@ seamus() { genrules seamus \ src/seamus.c \ src/log.c \ + src/queue.c \ src/ui.c } diff --git a/include/queue.h b/include/queue.h new file mode 100644 index 0000000000000000000000000000000000000000..25791504a7e857c39246f1ac13cb0c7ba183f5ca --- /dev/null +++ b/include/queue.h @@ -0,0 +1,8 @@ +#ifndef SEAMUS_QUEUE +#define SEAMUS_QUEUE +#include "seamus.h" + +int fetch_mpd_from_current_queue(struct seamus_frontend *seamus, int max_count); +void print_songs_from_queue(struct seamus_frontend *seamus); + +#endif diff --git a/src/queue.c b/src/queue.c new file mode 100644 index 0000000000000000000000000000000000000000..0d843b489ece8ef012c2a0619fa49f1d797b18ef --- /dev/null +++ b/src/queue.c @@ -0,0 +1,60 @@ +#include <stdio.h> +#include <assert.h> +#include <stdbool.h> +#include "seamus.h" + +int +fetch_mpd_from_current_queue(struct seamus_frontend *seamus, int max_count) +{ + assert(seamus->conn != NULL); + + bool queue_status = mpd_send_list_queue_meta(seamus->conn); + + if (queue_status == true) { + struct mpd_entity *entity; + int index; + + seamus->queue = calloc(max_count, sizeof(struct seamus_song)); + + for (index = 0; index < max_count; index++) { + entity = mpd_recv_entity(seamus->conn); + if (entity == NULL) { + continue; + } else { + enum mpd_entity_type type = mpd_entity_get_type(entity); + + if (type == MPD_ENTITY_TYPE_SONG) { + struct mpd_song *song = mpd_entity_get_song(entity); + + enum mpd_tag_type tag_title = mpd_tag_name_iparse("Title"); + const char *stitle = mpd_song_get_tag(song, tag_title, 0); + + enum mpd_tag_type tag_artist = mpd_tag_name_iparse("AlbumArtist"); + const char *sartist = mpd_song_get_tag(song, tag_artist, 0); + + struct seamus_song *new = &seamus->queue[index]; + memset(new, 0, sizeof(*new)); + + char *title = malloc(sizeof(char) * strlen(stitle) + 1); + strcpy(title, stitle); + + char *artist = malloc(sizeof(char) * strlen(sartist) + 1); + strcpy(artist, sartist); + + new->title = title; + new->artist = artist; + seamus->queue_size++; + } + + // When freeing the entity, it'll automatically + // free the song for us + mpd_entity_free(entity); + } + } + + return 0; + } else { + log_fatal("Couldn't fetch the queue"); + return 1; + } +} diff --git a/src/seamus.c b/src/seamus.c index 325d1a724fc79f3b72bc88c69c4939925351b71d..b80b655226a9b494ab061ba67131bad5daf3bfea 100755 --- a/src/seamus.c +++ b/src/seamus.c @@ -29,75 +29,6 @@ return 0; } -int -fetch_mpd_from_current_queue(struct seamus_frontend *seamus, int max_count) -{ - assert(seamus->conn != NULL); - int queue_status = mpd_send_list_queue_meta(seamus->conn); - - if (queue_status == true) { - struct mpd_entity *entity; - int index; - - seamus->queue = calloc(max_count, sizeof(struct seamus_song)); - - for (index = 0; index < max_count; index++) { - entity = mpd_recv_entity(seamus->conn); - if (entity == NULL) { - continue; - } else { - enum mpd_entity_type type = mpd_entity_get_type(entity); - - if (type == MPD_ENTITY_TYPE_SONG) { - struct mpd_song *song = mpd_entity_get_song(entity); - - enum mpd_tag_type tag_title = mpd_tag_name_iparse("Title"); - const char *stitle = mpd_song_get_tag(song, tag_title, 0); - - enum mpd_tag_type tag_artist = mpd_tag_name_iparse("AlbumArtist"); - const char *sartist = mpd_song_get_tag(song, tag_artist, 0); - - struct seamus_song *new = &seamus->queue[index]; - memset(new, 0, sizeof(*new)); - - char *title = malloc(sizeof(char) * strlen(stitle) + 1); - strcpy(title, stitle); - - char *artist = malloc(sizeof(char) * strlen(sartist) + 1); - strcpy(artist, sartist); - - new->title = title; - new->artist = artist; - seamus->queue_size++; - } - - // When freeing the entity, it'll automatically - // free the song for us - mpd_entity_free(entity); - } - } - - return 0; - } else { - fprintf(stderr, "Could not fetch queue"); - return 1; - } -} - -void -print_songs_from_queue(struct seamus_frontend *seamus) -{ - for (size_t i = 0; i < seamus->queue_size; ++i) { - struct seamus_song *s = &seamus->queue[i]; - - if (s == NULL) { - printf("Nothing here..."); - } else { - printf("Song queued: %s - %s \n", s->artist, s->title); - } - } -} - void seamus_finish(struct seamus_frontend *seamus) { @@ -147,10 +78,6 @@ goto exit_tickit; } tickit_start(&seamus); - - //fetch_mpd_from_current_queue(&seamus, 10); - - //print_songs_from_queue(&seamus); exit_tickit: tickit_finish(&seamus);