Commit a038bca7 authored by Max Kellermann's avatar Max Kellermann

song: added support for selecting a time range

Added attributes start_ms, end_ms. This allows us to address a portion of a song file (important for CUE support). There is no support yet for storing these attributes in the state file.
parent cf38505d
...@@ -42,6 +42,7 @@ song_alloc(const char *uri, struct directory *parent) ...@@ -42,6 +42,7 @@ song_alloc(const char *uri, struct directory *parent)
memcpy(song->uri, uri, uri_length + 1); memcpy(song->uri, uri, uri_length + 1);
song->parent = parent; song->parent = parent;
song->mtime = 0; song->mtime = 0;
song->start_ms = song->end_ms = 0;
return song; return song;
} }
...@@ -84,8 +85,11 @@ song_get_uri(const struct song *song) ...@@ -84,8 +85,11 @@ song_get_uri(const struct song *song)
double double
song_get_duration(const struct song *song) song_get_duration(const struct song *song)
{ {
if (song->end_ms > 0)
return (song->end_ms - song->start_ms) / 1000.0;
if (song->tag == NULL) if (song->tag == NULL)
return 0; return 0;
return song->tag->time; return song->tag->time - song->start_ms / 1000.0;
} }
...@@ -31,6 +31,18 @@ struct song { ...@@ -31,6 +31,18 @@ struct song {
struct tag *tag; struct tag *tag;
struct directory *parent; struct directory *parent;
time_t mtime; time_t mtime;
/**
* Start of this sub-song within the file in milliseconds.
*/
unsigned start_ms;
/**
* End of this sub-song within the file in milliseconds.
* Unused if zero.
*/
unsigned end_ms;
char uri[sizeof(int)]; char uri[sizeof(int)];
}; };
......
...@@ -51,6 +51,19 @@ song_print_info(struct client *client, struct song *song) ...@@ -51,6 +51,19 @@ song_print_info(struct client *client, struct song *song)
{ {
song_print_uri(client, song); song_print_uri(client, song);
if (song->start_ms > 0 || song->end_ms > 0) {
if (song->end_ms > 0)
client_printf(client, "Range: %u.%03u-%u.%03u\n",
song->start_ms / 1000,
song->start_ms % 1000,
song->end_ms / 1000,
song->end_ms % 1000);
else
client_printf(client, "Range: %u.%03u-\n",
song->start_ms / 1000,
song->start_ms % 1000);
}
if (song->mtime > 0) { if (song->mtime > 0) {
#ifndef G_OS_WIN32 #ifndef G_OS_WIN32
struct tm tm; struct tm tm;
......
...@@ -128,6 +128,14 @@ int main(int argc, char **argv) ...@@ -128,6 +128,14 @@ int main(int argc, char **argv)
while ((song = playlist_plugin_read(playlist)) != NULL) { while ((song = playlist_plugin_read(playlist)) != NULL) {
g_print("%s\n", song->uri); g_print("%s\n", song->uri);
if (song->start_ms > 0 || song->end_ms > 0)
g_print("range: %u:%02u..%u:%02u\n",
song->start_ms / 60000,
(song->start_ms / 1000) % 60,
song->end_ms / 60000,
(song->end_ms / 1000) % 60);
if (song->tag != NULL) if (song->tag != NULL)
tag_save(stdout, song->tag); tag_save(stdout, song->tag);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment