-
Notifications
You must be signed in to change notification settings - Fork 24
Introduction to libglyr
bugdone edited this page Sep 24, 2016
·
4 revisions
Probably you expect phrases like “It’s so easy!”
Yupp, it is easy.
This guide describes the API for C.
If you ever had to do with libcurl you might notice there are some very similar things here.
First of all we have a thing called a query, you set options in this query, like the Artist, Album, or the singers hair colour, and also the type of Metadata you want, like ‘coverart’. Then you give this query to glyr_get() and after some time you get back a list of caches.
Those caches are the resulting items you use in your application. Yupp, that easy.
- We should init the library first.
glyr_init();
- Make sure we destroy it later.
atexit(glyr_cleanup);
- Let’s make a new
query
:
GlyrQuery my_query;
- Set it to sane defaults:
glyr_query_init(&my_query);
- Say we want coverart.
glyr_opt_type(&my_query,GLYR_GET_COVERART);
- Set the artist.
glyr_opt_artist(&my_query,"Excrementory Grindfuckers");
- Set the album.
glyr_opt_album(&my_query,"Guts, Gore & Grind");
- Now order your items.
GlyrMemCache * list = glyr_get(&my_query,NULL,NULL);
-
list is the head of a doubly linked list of caches
Each cache has a data field, containing the data (here some unprintable image)
Also, it has a pointer next, which (surprise) points to the next item in the list.
We then can iterate over the results like this.
GlyrMemCache * it = list; while(it != NULL) { printf("Image with size %d\n",it->size); it = it->next; }
- This will get you 0 or 1 image. Why? Because glyr_opt_number() was set to 1.
Try to change it and run again. - When done we should free the thing:
glyr_free_list(list);
- And this query isn’t needed anymore. Free it:
glyr_query_destroy(&my_query);
- Most of the time you will just use the
glyr_opt
methods. - All default values for
glyr_opt
are #defined intypes.h
; Example:GLYR_DEFAULT_QSRATIO
- If you use libglyr in a musicplayer you want to run it in an own thread. Read on to see an example.
- Most of the default settings are sane. You’re only required to set artist/album/title and the type.