Skip to content

Commit

Permalink
Add range start and end in milliseconds into mpd_song
Browse files Browse the repository at this point in the history
  • Loading branch information
datasone committed Apr 11, 2023
1 parent 10b4b5b commit 5fcfccd
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
16 changes: 16 additions & 0 deletions include/mpd/song.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@ mpd_pure
unsigned
mpd_song_get_start(const struct mpd_song *song);

/**
* Returns the start of the virtual song within the physical file in
* milliseconds.
*/
mpd_pure
unsigned
mpd_song_get_start_ms(const struct mpd_song *song);

/**
* Returns the end of the virtual song within the physical file in
* seconds. 0 means that the physical song file is played to the end.
Expand All @@ -147,6 +155,14 @@ mpd_pure
unsigned
mpd_song_get_end(const struct mpd_song *song);

/**
* Returns the end of the virtual song within the physical file in
* milliseconds. 0 means that the physical song file is played to the end.
*/
mpd_pure
unsigned
mpd_song_get_end_ms(const struct mpd_song *song);

/**
* @return the POSIX UTC time stamp of the last modification, or 0 if
* that is unknown
Expand Down
2 changes: 2 additions & 0 deletions libmpdclient.ld
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,9 @@ global:
mpd_song_get_duration;
mpd_song_get_duration_ms;
mpd_song_get_start;
mpd_song_get_start_ms;
mpd_song_get_end;
mpd_song_get_end_ms;
mpd_song_get_last_modified;
mpd_song_set_pos;
mpd_song_get_pos;
Expand Down
39 changes: 38 additions & 1 deletion src/song.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,26 @@ struct mpd_song {
*/
unsigned start;

/**
* Start of the virtual song within the physical file in
* milliseconds.
*/
unsigned start_ms;

/**
* End of the virtual song within the physical file in
* seconds. Zero means that the physical song file is
* played to the end.
*/
unsigned end;

/**
* End of the virtual song within the physical file in
* milliseconds. Zero means that the physical song
* file is played to the end.
*/
unsigned end_ms;

/**
* The POSIX UTC time stamp of the last modification, or 0 if
* that is unknown.
Expand Down Expand Up @@ -147,7 +160,9 @@ mpd_song_new(const char *uri)
song->duration = 0;
song->duration_ms = 0;
song->start = 0;
song->start_ms = 0;
song->end = 0;
song->end_ms = 0;
song->last_modified = 0;
song->pos = 0;
song->id = 0;
Expand Down Expand Up @@ -230,7 +245,9 @@ mpd_song_dup(const struct mpd_song *song)
ret->duration = song->duration;
ret->duration_ms = song->duration_ms;
ret->start = song->start;
ret->start_ms = song->start_ms;
ret->end = song->end;
ret->end_ms = song->end_ms;
ret->last_modified = song->last_modified;
ret->pos = song->pos;
ret->id = song->id;
Expand Down Expand Up @@ -396,6 +413,14 @@ mpd_song_get_start(const struct mpd_song *song)
return song->start;
}

unsigned
mpd_song_get_start_ms(const struct mpd_song *song)
{
assert(song != NULL);

return song->start_ms;
}

unsigned
mpd_song_get_end(const struct mpd_song *song)
{
Expand All @@ -404,6 +429,14 @@ mpd_song_get_end(const struct mpd_song *song)
return song->end;
}

unsigned
mpd_song_get_end_ms(const struct mpd_song *song)
{
assert(song != NULL);

return song->end_ms;
}

static void
mpd_song_set_last_modified(struct mpd_song *song, time_t mtime)
{
Expand Down Expand Up @@ -508,15 +541,19 @@ mpd_song_parse_range(struct mpd_song *song, const char *value)
}

song->start = start > 0.0 ? (unsigned)start : 0;
song->start_ms = start > 0.0 ? (unsigned)(start * 1000) : 0;

if (end > 0.0) {
song->end = (unsigned)end;
song->end_ms = (unsigned)(end * 1000);
if (song->end == 0)
/* round up, because the caller must sees that
there's an upper limit */
song->end = 1;
} else
} else {
song->end = 0;
song->end_ms = 0;
}
}

static void
Expand Down

0 comments on commit 5fcfccd

Please sign in to comment.