event_pipe: added "TAG" event
The "TAG" event is emitted by the player thread when the current song's tag has changed. Split this event from "PLAYLIST" and make it a separate callback, which is more efficient.
This commit is contained in:
parent
d10910cc90
commit
06bd9ad88f
@ -36,6 +36,9 @@ enum pipe_event {
|
|||||||
/** must call syncPlayerAndPlaylist() */
|
/** must call syncPlayerAndPlaylist() */
|
||||||
PIPE_EVENT_PLAYLIST,
|
PIPE_EVENT_PLAYLIST,
|
||||||
|
|
||||||
|
/** the current song's tag has changed */
|
||||||
|
PIPE_EVENT_TAG,
|
||||||
|
|
||||||
/** SIGHUP received: reload configuration, roll log file */
|
/** SIGHUP received: reload configuration, roll log file */
|
||||||
PIPE_EVENT_RELOAD,
|
PIPE_EVENT_RELOAD,
|
||||||
|
|
||||||
|
@ -249,7 +249,7 @@ play_chunk(struct song *song, struct music_chunk *chunk,
|
|||||||
|
|
||||||
/* the main thread will update the playlist
|
/* the main thread will update the playlist
|
||||||
version when he receives this event */
|
version when he receives this event */
|
||||||
event_pipe_emit(PIPE_EVENT_PLAYLIST);
|
event_pipe_emit(PIPE_EVENT_TAG);
|
||||||
|
|
||||||
/* notify all clients that the tag of the
|
/* notify all clients that the tag of the
|
||||||
current song has changed */
|
current song has changed */
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
#include "stored_playlist.h"
|
#include "stored_playlist.h"
|
||||||
#include "ack.h"
|
#include "ack.h"
|
||||||
#include "idle.h"
|
#include "idle.h"
|
||||||
|
#include "event_pipe.h"
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
@ -117,6 +118,21 @@ static void incrPlaylistCurrent(void)
|
|||||||
playlist.current++;
|
playlist.current++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
playlist_tag_event(void)
|
||||||
|
{
|
||||||
|
unsigned song;
|
||||||
|
|
||||||
|
if (playlist_state != PLAYLIST_STATE_PLAY)
|
||||||
|
return;
|
||||||
|
|
||||||
|
assert(playlist.current >= 0);
|
||||||
|
|
||||||
|
song = playlist.order[playlist.current];
|
||||||
|
playlist.songMod[song] = playlist.version;
|
||||||
|
incrPlaylistVersion();
|
||||||
|
}
|
||||||
|
|
||||||
void initPlaylist(void)
|
void initPlaylist(void)
|
||||||
{
|
{
|
||||||
char *test;
|
char *test;
|
||||||
@ -162,6 +178,8 @@ void initPlaylist(void)
|
|||||||
i++) {
|
i++) {
|
||||||
playlist.idToPosition[i] = -1;
|
playlist.idToPosition[i] = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
event_pipe_register(PIPE_EVENT_TAG, playlist_tag_event);
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned getNextId(void)
|
static unsigned getNextId(void)
|
||||||
@ -857,32 +875,6 @@ enum playlist_result playPlaylistById(int id, int stopOnError)
|
|||||||
return playPlaylist(song, stopOnError);
|
return playPlaylist(song, stopOnError);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void syncCurrentPlayerDecodeMetadata(void)
|
|
||||||
{
|
|
||||||
struct song *song;
|
|
||||||
int songNum;
|
|
||||||
|
|
||||||
if (playlist_state != PLAYLIST_STATE_PLAY)
|
|
||||||
return;
|
|
||||||
|
|
||||||
songNum = playlist.order[playlist.current];
|
|
||||||
song = playlist.songs[songNum];
|
|
||||||
|
|
||||||
if (song != playlist.prev_song) {
|
|
||||||
/* song change: initialize playlist.prev_{song,tag} */
|
|
||||||
|
|
||||||
playlist.prev_song = song;
|
|
||||||
playlist.prev_tag = song->tag;
|
|
||||||
} else if (song->tag != playlist.prev_tag) {
|
|
||||||
/* tag change: update playlist */
|
|
||||||
|
|
||||||
playlist.songMod[songNum] = playlist.version;
|
|
||||||
incrPlaylistVersion();
|
|
||||||
|
|
||||||
playlist.prev_tag = song->tag;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void syncPlayerAndPlaylist(void)
|
void syncPlayerAndPlaylist(void)
|
||||||
{
|
{
|
||||||
if (playlist_state != PLAYLIST_STATE_PLAY)
|
if (playlist_state != PLAYLIST_STATE_PLAY)
|
||||||
@ -895,8 +887,6 @@ void syncPlayerAndPlaylist(void)
|
|||||||
if (pc.next_song == NULL)
|
if (pc.next_song == NULL)
|
||||||
queueNextSongInPlaylist();
|
queueNextSongInPlaylist();
|
||||||
}
|
}
|
||||||
|
|
||||||
syncCurrentPlayerDecodeMetadata();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void currentSongInPlaylist(void)
|
static void currentSongInPlaylist(void)
|
||||||
|
@ -55,11 +55,6 @@ typedef struct _Playlist {
|
|||||||
bool repeat;
|
bool repeat;
|
||||||
bool random;
|
bool random;
|
||||||
uint32_t version;
|
uint32_t version;
|
||||||
|
|
||||||
/** used by syncCurrentPlayerDecodeMetadata() to detect tag changes */
|
|
||||||
const struct song *prev_song;
|
|
||||||
/** used by syncCurrentPlayerDecodeMetadata() to detect tag changes */
|
|
||||||
const struct tag *prev_tag;
|
|
||||||
} Playlist;
|
} Playlist;
|
||||||
|
|
||||||
extern bool playlist_saveAbsolutePaths;
|
extern bool playlist_saveAbsolutePaths;
|
||||||
|
Loading…
Reference in New Issue
Block a user