diff --git a/src/audacious.c b/src/audacious.c index fae63a22..a601e909 100644 --- a/src/audacious.c +++ b/src/audacious.c @@ -127,79 +127,77 @@ void *audacious_thread_func(void *pvoid) /* Loop until the main thread sets the runnable signal to 0. */ while(runnable) { - for (;;) { /* convenience loop so we can break below */ - - if (!xmms_remote_is_running (session)) { - memset(&items,0,sizeof(items)); - strcpy(items[AUDACIOUS_STATUS],"Not running"); - break; - } - - /* Player status */ - if (xmms_remote_is_paused (session)) - strcpy(items[AUDACIOUS_STATUS],"Paused"); - else if (xmms_remote_is_playing (session)) - strcpy(items[AUDACIOUS_STATUS],"Playing"); - else - strcpy(items[AUDACIOUS_STATUS],"Stopped"); - - /* Current song title */ - playpos = xmms_remote_get_playlist_pos (session); - psong = xmms_remote_get_playlist_title (session, playpos); - if (psong) { - strncpy(items[AUDACIOUS_TITLE],psong,sizeof(items[AUDACIOUS_TITLE])-1); - g_free (psong); - psong=NULL; - } - - /* Current song length as MM:SS */ - frames = xmms_remote_get_playlist_time (session,playpos); - length = frames / 1000; - snprintf(items[AUDACIOUS_LENGTH],sizeof(items[AUDACIOUS_LENGTH])-1, - "%d:%.2d", length / 60, length % 60); - - /* Current song length in seconds */ - snprintf(items[AUDACIOUS_LENGTH_SECONDS],sizeof(items[AUDACIOUS_LENGTH_SECONDS])-1, - "%d", length); - - /* Current song position as MM:SS */ - frames = xmms_remote_get_output_time (session); - length = frames / 1000; - snprintf(items[AUDACIOUS_POSITION],sizeof(items[AUDACIOUS_POSITION])-1, - "%d:%.2d", length / 60, length % 60); - - /* Current song position in seconds */ - snprintf(items[AUDACIOUS_POSITION_SECONDS],sizeof(items[AUDACIOUS_POSITION_SECONDS])-1, - "%d", length); - - /* Current song bitrate */ - xmms_remote_get_info (session, &rate, &freq, &chans); - snprintf(items[AUDACIOUS_BITRATE],sizeof(items[AUDACIOUS_BITRATE])-1, "%d", rate); - - /* Current song frequency */ - snprintf(items[AUDACIOUS_FREQUENCY],sizeof(items[AUDACIOUS_FREQUENCY])-1, "%d", freq); - - /* Current song channels */ - snprintf(items[AUDACIOUS_CHANNELS],sizeof(items[AUDACIOUS_CHANNELS])-1, "%d", chans); - - /* Current song filename */ - pfilename = xmms_remote_get_playlist_file (session,playpos); - if (pfilename) { - strncpy(items[AUDACIOUS_FILENAME],pfilename,sizeof(items[AUDACIOUS_FILENAME])-1); - g_free (pfilename); - pfilename=NULL; - } - - /* Length of the Playlist (number of songs) */ - length = xmms_remote_get_playlist_length (session); - snprintf(items[AUDACIOUS_PLAYLIST_LENGTH],sizeof(items[AUDACIOUS_PLAYLIST_LENGTH])-1, "%d", length); - - /* Playlist position (index of song) */ - snprintf(items[AUDACIOUS_PLAYLIST_POSITION],sizeof(items[AUDACIOUS_PLAYLIST_POSITION])-1, "%d", playpos+1); - - break; + if (!xmms_remote_is_running (session)) { + memset(&items,0,sizeof(items)); + strcpy(items[AUDACIOUS_STATUS],"Not running"); + goto next_iter; } + /* Player status */ + if (xmms_remote_is_paused (session)) + strcpy(items[AUDACIOUS_STATUS],"Paused"); + else if (xmms_remote_is_playing (session)) + strcpy(items[AUDACIOUS_STATUS],"Playing"); + else + strcpy(items[AUDACIOUS_STATUS],"Stopped"); + + /* Current song title */ + playpos = xmms_remote_get_playlist_pos (session); + psong = xmms_remote_get_playlist_title (session, playpos); + if (psong) { + strncpy(items[AUDACIOUS_TITLE],psong,sizeof(items[AUDACIOUS_TITLE])-1); + g_free (psong); + psong=NULL; + } + + /* Current song length as MM:SS */ + frames = xmms_remote_get_playlist_time (session,playpos); + length = frames / 1000; + snprintf(items[AUDACIOUS_LENGTH],sizeof(items[AUDACIOUS_LENGTH])-1, + "%d:%.2d", length / 60, length % 60); + + /* Current song length in seconds */ + snprintf(items[AUDACIOUS_LENGTH_SECONDS],sizeof(items[AUDACIOUS_LENGTH_SECONDS])-1, + "%d", length); + + /* Current song position as MM:SS */ + frames = xmms_remote_get_output_time (session); + length = frames / 1000; + snprintf(items[AUDACIOUS_POSITION],sizeof(items[AUDACIOUS_POSITION])-1, + "%d:%.2d", length / 60, length % 60); + + /* Current song position in seconds */ + snprintf(items[AUDACIOUS_POSITION_SECONDS],sizeof(items[AUDACIOUS_POSITION_SECONDS])-1, + "%d", length); + + /* Current song bitrate */ + xmms_remote_get_info (session, &rate, &freq, &chans); + snprintf(items[AUDACIOUS_BITRATE],sizeof(items[AUDACIOUS_BITRATE])-1, "%d", rate); + + /* Current song frequency */ + snprintf(items[AUDACIOUS_FREQUENCY],sizeof(items[AUDACIOUS_FREQUENCY])-1, "%d", freq); + + /* Current song channels */ + snprintf(items[AUDACIOUS_CHANNELS],sizeof(items[AUDACIOUS_CHANNELS])-1, "%d", chans); + + /* Current song filename */ + pfilename = xmms_remote_get_playlist_file (session,playpos); + if (pfilename) { + strncpy(items[AUDACIOUS_FILENAME],pfilename,sizeof(items[AUDACIOUS_FILENAME])-1); + g_free (pfilename); + pfilename=NULL; + } + + /* Length of the Playlist (number of songs) */ + length = xmms_remote_get_playlist_length (session); + snprintf(items[AUDACIOUS_PLAYLIST_LENGTH],sizeof(items[AUDACIOUS_PLAYLIST_LENGTH])-1, "%d", length); + + /* Playlist position (index of song) */ + snprintf(items[AUDACIOUS_PLAYLIST_POSITION],sizeof(items[AUDACIOUS_PLAYLIST_POSITION])-1, + "%d", playpos+1); + +next_iter: + /* Deliver the refreshed items array to audacious_items. */ pthread_mutex_lock(&info.audacious.item_mutex); memcpy(&audacious_items,items,sizeof(items)); @@ -215,7 +213,7 @@ void *audacious_thread_func(void *pvoid) &abstime) != ETIMEDOUT) { runnable=0; - (void) pthread_mutex_unlock (&info.audacious.runnable_mutex); + pthread_mutex_unlock (&info.audacious.runnable_mutex); } }