diff options
author | waker <wakeroid@gmail.com> | 2011-05-04 21:36:21 +0200 |
---|---|---|
committer | waker <wakeroid@gmail.com> | 2011-05-04 21:37:58 +0200 |
commit | 7710ed414acf8ecdf1a54bd58a7a26a696ee199f (patch) | |
tree | 8bce68b491f487d6550b649b2188bb3efe6437e0 | |
parent | 745fa29c0fe4860a67da698c17057d687f1b9bc7 (diff) |
moved playtime and started_timestamp from playitem to streamer global variables;
playtime and started_timestamp are now passed in track event structures;
fixed few lastfm submission and event-handling bugs;
cleaned out old event sending helper functions
-rw-r--r-- | deadbeef.h | 6 | ||||
-rw-r--r-- | main.c | 14 | ||||
-rw-r--r-- | playlist.c | 25 | ||||
-rw-r--r-- | playlist.h | 2 | ||||
-rw-r--r-- | plugins.c | 68 | ||||
-rw-r--r-- | plugins.h | 18 | ||||
-rw-r--r-- | plugins/lastfm/lastfm.c | 65 | ||||
-rw-r--r-- | streamer.c | 102 |
8 files changed, 142 insertions, 158 deletions
@@ -120,8 +120,6 @@ typedef struct DB_playItem_s { int startsample; // start sample of track, or -1 for auto int endsample; // end sample of track, or -1 for auto int shufflerating; // sort order for shuffle mode - float playtime; // actual playback time of this track in seconds - time_t started_timestamp; // result of calling time(NULL) } ddb_playItem_t; typedef ddb_playItem_t DB_playItem_t; @@ -212,12 +210,16 @@ typedef struct { typedef struct { ddb_event_t ev; DB_playItem_t *track; + float playtime; // for SONGFINISHED event -- for how many seconds track was playing + time_t started_timestamp; // result of calling time(NULL) on playback start } ddb_event_track_t; typedef struct { ddb_event_t ev; DB_playItem_t *from; DB_playItem_t *to; + float playtime; // for SONGCHANGED event -- for how many seconds prev track was playing + time_t started_timestamp; // result of calling time(NULL) on playback start } ddb_event_trackchange_t; typedef struct { @@ -246,7 +246,7 @@ server_exec_command_line (const char *cmdline, int len, char *sendback, int sbsi playlist_t *curr_plt = plt_get_curr (); if (!queue) { pl_clear (); - plug_trigger_event_playlistchanged (); + messagepump_push (DB_EV_PLAYLISTCHANGED, 0, 0, 0); pl_reset_cursor (); } if (parg < pend) { @@ -357,7 +357,7 @@ server_update (void) { if ((size = recv (s2, str, 2048, 0)) >= 0) { if (size == 1 && str[0] == 0) { // FIXME: that should be called right after activation of gui plugin - plug_trigger_event (DB_EV_ACTIVATED, 0); + messagepump_push (DB_EV_ACTIVATED, 0, 0, 0); } else { server_exec_command_line (str, size, sendback, sizeof (sendback)); @@ -454,17 +454,17 @@ player_mainloop (void) { case DB_EV_PAUSE: if (output->state () != OUTPUT_STATE_PAUSED) { output->pause (); - plug_trigger_event_paused (1); + messagepump_push (DB_EV_PAUSED, 0, 1, 0); } break; case DB_EV_TOGGLE_PAUSE: if (output->state () == OUTPUT_STATE_PAUSED) { output->unpause (); - plug_trigger_event_paused (0); + messagepump_push (DB_EV_PAUSED, 0, 0, 0); } else { output->pause (); - plug_trigger_event_paused (1); + messagepump_push (DB_EV_PAUSED, 0, 1, 0); } break; case DB_EV_PLAY_RANDOM: @@ -473,7 +473,7 @@ player_mainloop (void) { break; case DB_EV_PLAYLIST_REFRESH: pl_save_current (); - plug_trigger_event_playlistchanged (); + messagepump_push (DB_EV_PLAYLISTCHANGED, 0, 0, 0); break; case DB_EV_CONFIGCHANGED: conf_save (); @@ -853,7 +853,7 @@ main (int argc, char *argv[]) { #endif // start all subsystems - plug_trigger_event_playlistchanged (); + messagepump_push (DB_EV_PLAYLISTCHANGED, 0, 0, 0); streamer_init (); @@ -1872,7 +1872,6 @@ pl_item_copy (playItem_t *out, playItem_t *it) { out->endsample = it->endsample; out->shufflerating = it->shufflerating; out->_duration = it->_duration; - out->started_timestamp = it->started_timestamp; out->next[PL_MAIN] = it->next[PL_MAIN]; out->prev[PL_MAIN] = it->prev[PL_MAIN]; out->next[PL_SEARCH] = it->next[PL_SEARCH]; @@ -3642,6 +3641,16 @@ pl_search_process (const char *text) { UNLOCK; } +static void +send_trackinfochanged (playItem_t *track) { + ddb_event_track_t *ev = (ddb_event_track_t *)messagepump_event_alloc (DB_EV_TRACKINFOCHANGED); + ev->track = DB_PLAYITEM (track); + if (track) { + pl_item_ref (track); + } + messagepump_push_event ((ddb_event_t*)ev, 0, 0); +} + int pl_playqueue_push (playItem_t *it) { if (playqueue_count == PLAYQUEUE_SIZE) { @@ -3652,7 +3661,7 @@ pl_playqueue_push (playItem_t *it) { pl_item_ref (it); playqueue[playqueue_count++] = it; for (int i = 0; i < playqueue_count; i++) { - plug_trigger_event_trackinfochanged (playqueue[i]); + send_trackinfochanged (playqueue[i]); } UNLOCK; return 0; @@ -3665,7 +3674,7 @@ pl_playqueue_clear (void) { playqueue_count = 0; int i; for (i = 0; i < cnt; i++) { - plug_trigger_event_trackinfochanged (playqueue[i]); + send_trackinfochanged (playqueue[i]); } for (i = 0; i < cnt; i++) { pl_item_unref (playqueue[i]); @@ -3681,7 +3690,7 @@ pl_playqueue_pop (void) { LOCK; if (playqueue_count == 1) { playqueue_count = 0; - plug_trigger_event_trackinfochanged (playqueue[0]); + send_trackinfochanged (playqueue[0]); pl_item_unref (playqueue[0]); UNLOCK; return; @@ -3689,9 +3698,9 @@ pl_playqueue_pop (void) { playItem_t *it = playqueue[0]; memmove (&playqueue[0], &playqueue[1], (playqueue_count-1) * sizeof (playItem_t*)); playqueue_count--; - plug_trigger_event_trackinfochanged (it); + send_trackinfochanged (it); for (int i = 0; i < playqueue_count; i++) { - plug_trigger_event_trackinfochanged (playqueue[i]); + send_trackinfochanged (playqueue[i]); } pl_item_unref (it); UNLOCK; @@ -3707,7 +3716,7 @@ pl_playqueue_remove (playItem_t *it) { if (i < playqueue_count-1) { memmove (&playqueue[i], &playqueue[i+1], (playqueue_count-i) * sizeof (playItem_t*)); } - plug_trigger_event_trackinfochanged (it); + send_trackinfochanged (it); pl_item_unref (it); playqueue_count--; break; @@ -3718,7 +3727,7 @@ pl_playqueue_remove (playItem_t *it) { } } for (int i = 0; i < playqueue_count; i++) { - plug_trigger_event_trackinfochanged (playqueue[i]); + send_trackinfochanged (playqueue[i]); } UNLOCK; } @@ -33,8 +33,6 @@ typedef struct playItem_s { int startsample; int endsample; int shufflerating; // sort order for shuffle mode - float playtime; // total playtime - time_t started_timestamp; // result of calling time(NULL) // private area, must not be visible to plugins float _duration; uint32_t _flags; @@ -338,13 +338,13 @@ plug_get_pixmap_dir (void) { void plug_volume_set_db (float db) { volume_set_db (db); - plug_trigger_event_volumechanged (); + messagepump_push (DB_EV_VOLUMECHANGED, 0, 0, 0); } void plug_volume_set_amp (float amp) { volume_set_amp (amp); - plug_trigger_event_volumechanged (); + messagepump_push (DB_EV_VOLUMECHANGED, 0, 0, 0); } #define MAX_PLUGINS 100 @@ -431,68 +431,6 @@ plug_playback_set_pos (float pos) { streamer_set_seek (t); } -// FIXME: this is backward-compatibility layer, should be killed -void -plug_trigger_event (int ev, uintptr_t param) { - ddb_event_t *event = NULL; - switch (ev) { - case DB_EV_SONGSTARTED: - case DB_EV_SONGFINISHED: - { - ddb_event_track_t *pev = (ddb_event_track_t *)messagepump_event_alloc (ev); - playItem_t *pltrack = streamer_get_playing_track (); - pev->track = DB_PLAYITEM (pltrack); - event = DB_EVENT (pev); - } - break; - } - if (event) { - messagepump_push_event (event, 0, 0); - } - else { - messagepump_push (ev, param, 0, 0); - } -} - -void -plug_trigger_event_trackchange (playItem_t *from, playItem_t *to) { - ddb_event_trackchange_t *event = (ddb_event_trackchange_t *)messagepump_event_alloc (DB_EV_SONGCHANGED); - if (from) { - pl_item_ref (from); - } - if (to) { - pl_item_ref (to); - } - event->from = (DB_playItem_t *)from; - event->to = (DB_playItem_t *)to; - messagepump_push_event ((ddb_event_t *)event, 0, 0); -} - -void -plug_trigger_event_trackinfochanged (playItem_t *track) { - ddb_event_track_t *ev = (ddb_event_track_t *)messagepump_event_alloc (DB_EV_TRACKINFOCHANGED); - ev->track = DB_PLAYITEM (track); - if (track) { - pl_item_ref (track); - } - messagepump_push_event ((ddb_event_t*)ev, 0, 0); -} - -void -plug_trigger_event_paused (int paused) { - messagepump_push (DB_EV_PAUSED, 0, paused, 0); -} - -void -plug_trigger_event_playlistchanged (void) { - messagepump_push (DB_EV_PLAYLISTCHANGED, 0, 0, 0); -} - -void -plug_trigger_event_volumechanged (void) { - messagepump_push (DB_EV_VOLUMECHANGED, 0, 0, 0); -} - int plug_init_plugin (DB_plugin_t* (*loadfunc)(DB_functions_t *), void *handle) { DB_plugin_t *plugin_api = loadfunc (&deadbeef_api); @@ -1124,7 +1062,7 @@ plug_select_output (void) { if (!output_plugin) { return -1; } - plug_trigger_event (DB_EV_OUTPUTCHANGED, 0); + messagepump_push (DB_EV_OUTPUTCHANGED, 0, 0, 0); return 0; #endif } @@ -46,24 +46,6 @@ void plug_ev_unsubscribe (DB_plugin_t *plugin, int ev, DB_callback_t callback, uintptr_t data); void -plug_trigger_event (int ev, uintptr_t param); - -void -plug_trigger_event_trackchange (struct playItem_s *from, struct playItem_s *to); - -void -plug_trigger_event_trackinfochanged (struct playItem_s *track); - -void -plug_trigger_event_paused (int paused); - -void -plug_trigger_event_playlistchanged (void); - -void -plug_trigger_event_volumechanged (void); - -void plug_md5 (uint8_t sig[16], const char *in, int len); void diff --git a/plugins/lastfm/lastfm.c b/plugins/lastfm/lastfm.c index 828b35db..3ea5622a 100644 --- a/plugins/lastfm/lastfm.c +++ b/plugins/lastfm/lastfm.c @@ -62,8 +62,13 @@ static char lfm_err[CURL_ERROR_SIZE]; static char lfm_nowplaying[2048]; // packet for nowplaying, or "" #define LFM_SUBMISSION_QUEUE_SIZE 50 -//static char lfm_subm_queue[LFM_SUBMISSION_QUEUE_SIZE][2048]; -static DB_playItem_t *lfm_subm_queue[LFM_SUBMISSION_QUEUE_SIZE]; + +typedef struct { + DB_playItem_t *it; + time_t started_timestamp; +} subm_item_t; + +static subm_item_t lfm_subm_queue[LFM_SUBMISSION_QUEUE_SIZE]; static void lfm_update_auth (void) { @@ -409,7 +414,7 @@ lfm_add_keyvalue_uri_encoded (char **out, int *outl, const char *key, const char // subm is submission idx, or -1 for nowplaying // returns number of bytes added, or -1 static int -lfm_format_uri (int subm, DB_playItem_t *song, char *out, int outl) { +lfm_format_uri (int subm, DB_playItem_t *song, char *out, int outl, time_t started_timestamp) { if (subm > 50) { trace ("lastfm: it's only allowed to send up to 50 submissions at once (got idx=%d)\n", subm); return -1; @@ -475,7 +480,7 @@ lfm_format_uri (int subm, DB_playItem_t *song, char *out, int outl) { out += processed; outl -= processed; if (subm >= 0) { - processed = snprintf (out, outl, "i[%d]=%d&o[%d]=P&r[%d]=&", subm, (int)song->started_timestamp, subm, subm); + processed = snprintf (out, outl, "i[%d]=%d&o[%d]=P&r[%d]=&", subm, (int)started_timestamp, subm, subm); if (processed > outl) { // trace ("failed to add i[%d]=%d&o[%d]=P&r[%d]=&\n", subm, (int)song->started_timestamp, subm, subm); return -1; @@ -494,7 +499,7 @@ lastfm_songstarted (ddb_event_track_t *ev, uintptr_t data) { return 0; } deadbeef->mutex_lock (lfm_mutex); - if (lfm_format_uri (-1, ev->track, lfm_nowplaying, sizeof (lfm_nowplaying)) < 0) { + if (lfm_format_uri (-1, ev->track, lfm_nowplaying, sizeof (lfm_nowplaying), ev->started_timestamp) < 0) { lfm_nowplaying[0] = 0; } // trace ("%s\n", lfm_nowplaying); @@ -507,44 +512,45 @@ lastfm_songstarted (ddb_event_track_t *ev, uintptr_t data) { } static int -lastfm_songfinished (ddb_event_track_t *ev, uintptr_t data) { - trace ("lfm songfinished %s\n", ev->track->fname); +lastfm_songchanged (ddb_event_trackchange_t *ev, uintptr_t data) { if (!deadbeef->conf_get_int ("lastfm.enable", 0)) { return 0; } // previous track must exist - if (!ev->track) { + if (!ev->from) { return 0; } + trace ("lfm songfinished %s\n", deadbeef->pl_find_meta (ev->from, ":URI")); #if !LFM_IGNORE_RULES // check submission rules // duration must be >= 30 sec - if (deadbeef->pl_get_item_duration (ev->track) < 30) { - trace ("track duration is %f seconds. not eligible for submission\n", deadbeef->pl_get_item_duration (ev->track)); + if (deadbeef->pl_get_item_duration (ev->from) < 30) { + trace ("track duration is %f seconds. not eligible for submission\n", deadbeef->pl_get_item_duration (ev->from)); return 0; } // must be played for >=240sec of half the total time - if (ev->track->playtime < 240 && ev->track->playtime < deadbeef->pl_get_item_duration (ev->track)/2) { - trace ("track playtime=%f seconds. not eligible for submission\n", ev->track->playtime); + if (ev->playtime < 240 && ev->playtime < deadbeef->pl_get_item_duration (ev->from)/2) { + trace ("track playtime=%f seconds. not eligible for submission\n", ev->playtime); return 0; } #endif - if (!deadbeef->pl_find_meta (ev->track, "artist") - || !deadbeef->pl_find_meta (ev->track, "title") -// || !deadbeef->pl_find_meta (ev->track, "album") + if (!deadbeef->pl_find_meta (ev->from, "artist") + || !deadbeef->pl_find_meta (ev->from, "title") +// || !deadbeef->pl_find_meta (ev->from, "album") ) { - trace ("lfm: not enough metadata for submission, artist=%s, title=%s, album=%s\n", deadbeef->pl_find_meta (ev->track, "artist"), deadbeef->pl_find_meta (ev->track, "title"), deadbeef->pl_find_meta (ev->track, "album")); + trace ("lfm: not enough metadata for submission, artist=%s, title=%s, album=%s\n", deadbeef->pl_find_meta (ev->from, "artist"), deadbeef->pl_find_meta (ev->from, "title"), deadbeef->pl_find_meta (ev->from, "album")); return 0; } deadbeef->mutex_lock (lfm_mutex); // find free place in queue for (int i = 0; i < LFM_SUBMISSION_QUEUE_SIZE; i++) { - if (!lfm_subm_queue[i]) { + if (!lfm_subm_queue[i].it) { trace ("lfm: song is now in queue for submission\n"); - lfm_subm_queue[i] = deadbeef->pl_item_alloc (); - deadbeef->pl_item_copy (lfm_subm_queue[i], ev->track); + lfm_subm_queue[i].it = ev->from; + lfm_subm_queue[i].started_timestamp = ev->started_timestamp; + deadbeef->pl_item_ref (ev->from); break; } } @@ -609,8 +615,8 @@ lfm_send_submissions (void) { int res; deadbeef->mutex_lock (lfm_mutex); for (i = 0; i < LFM_SUBMISSION_QUEUE_SIZE; i++) { - if (lfm_subm_queue[i]) { - res = lfm_format_uri (idx, lfm_subm_queue[i], r, len); + if (lfm_subm_queue[i].it) { + res = lfm_format_uri (idx, lfm_subm_queue[i].it, r, len, lfm_subm_queue[i].started_timestamp); if (res < 0) { trace ("lfm: failed to format uri\n"); return; @@ -655,9 +661,10 @@ lfm_send_submissions (void) { trace ("submission successful, response:\n%s\n", lfm_reply); deadbeef->mutex_lock (lfm_mutex); for (i = 0; i < LFM_SUBMISSION_QUEUE_SIZE; i++) { - if (lfm_subm_queue[i]) { - deadbeef->pl_item_unref (lfm_subm_queue[i]); - lfm_subm_queue[i] = NULL; + if (lfm_subm_queue[i].it) { + deadbeef->pl_item_unref (lfm_subm_queue[i].it); + lfm_subm_queue[i].it = NULL; + lfm_subm_queue[i].started_timestamp = 0; } } deadbeef->mutex_unlock (lfm_mutex); @@ -670,9 +677,11 @@ lfm_send_submissions (void) { trace ("submission successful (NOSEND=1):\n"); deadbeef->mutex_lock (lfm_mutex); for (i = 0; i < LFM_SUBMISSION_QUEUE_SIZE; i++) { - if (lfm_subm_queue[i]) { - deadbeef->pl_item_unref (lfm_subm_queue[i]); - lfm_subm_queue[i] = NULL; + if (lfm_subm_queue[i].it) { + deadbeef->pl_item_unref (lfm_subm_queue[i].it); + lfm_subm_queue[i].it = NULL; + lfm_subm_queue[i].started_timestamp = 0; + } } deadbeef->mutex_unlock (lfm_mutex); @@ -805,7 +814,7 @@ lfm_message (uint32_t id, uintptr_t ctx, uint32_t p1, uint32_t p2) { lastfm_songstarted ((ddb_event_track_t *)ctx, 0); break; case DB_EV_SONGCHANGED: - lastfm_songfinished ((ddb_event_track_t *)ctx, 0); + lastfm_songchanged ((ddb_event_trackchange_t *)ctx, 0); break; } return 0; @@ -97,6 +97,8 @@ static int last_bitrate = -1; // last bitrate of current song static playlist_t *streamer_playlist; static playItem_t *playing_track; +static float playtime; // total playtime of playing track +static time_t started_timestamp; // result of calling time(NULL) static playItem_t *streaming_track; static playItem_t *playlist_track; @@ -134,6 +136,42 @@ streamer_abort_files (void) { } } +static void +send_songstarted (playItem_t *trk) { + ddb_event_track_t *pev = (ddb_event_track_t *)messagepump_event_alloc (DB_EV_SONGSTARTED); + pev->track = DB_PLAYITEM (trk); + pl_item_ref (trk); + pev->playtime = 0; + pev->started_timestamp = time(NULL); + messagepump_push_event ((ddb_event_t*)pev, 0, 0); +} + +static void +send_songfinished (playItem_t *trk) { + ddb_event_track_t *pev = (ddb_event_track_t *)messagepump_event_alloc (DB_EV_SONGFINISHED); + pev->track = DB_PLAYITEM (trk); + pl_item_ref (trk); + pev->playtime = playtime; + pev->started_timestamp = started_timestamp; + messagepump_push_event ((ddb_event_t*)pev, 0, 0); +} + +static void +send_trackchanged (playItem_t *from, playItem_t *to) { + ddb_event_trackchange_t *event = (ddb_event_trackchange_t *)messagepump_event_alloc (DB_EV_SONGCHANGED); + event->playtime = playtime; + event->started_timestamp = started_timestamp; + if (from) { + pl_item_ref (from); + } + if (to) { + pl_item_ref (to); + } + event->from = (DB_playItem_t *)from; + event->to = (DB_playItem_t *)to; + messagepump_push_event ((ddb_event_t *)event, 0, 0); +} + void streamer_start_playback (playItem_t *from, playItem_t *it) { if (from) { @@ -169,9 +207,9 @@ streamer_start_playback (playItem_t *from, playItem_t *it) { replaygain_set_values (albumgain, albumpeak, trackgain, trackpeak); playing_track->played = 1; - playing_track->started_timestamp = time (NULL); + started_timestamp = time (NULL); trace ("from=%p (%s), to=%p (%s) [2]\n", from, from ? pl_find_meta (from, ":URI") : "null", it, it ? pl_find_meta (it, ":URI") : "null"); - plug_trigger_event_trackchange (from, it); + send_trackchanged (from, it); } if (from) { pl_item_unref (from); @@ -240,6 +278,15 @@ str_get_for_idx (int idx) { return it; } +static void +send_trackinfochanged (playItem_t *track) { + ddb_event_track_t *ev = (ddb_event_track_t *)messagepump_event_alloc (DB_EV_TRACKINFOCHANGED); + ev->track = DB_PLAYITEM (track); + if (track) { + pl_item_ref (track); + } + messagepump_push_event ((ddb_event_t*)ev, 0, 0); +} int streamer_move_to_nextsong (int reason) { @@ -372,7 +419,7 @@ streamer_move_to_nextsong (int reason) { } if (!it) { streamer_buffering = 0; - plug_trigger_event_trackinfochanged (streaming_track); + send_trackinfochanged (streaming_track); playItem_t *temp; plt_reshuffle (streamer_playlist, &temp, NULL); streamer_set_nextsong (-2, -2); @@ -400,7 +447,7 @@ streamer_move_to_nextsong (int reason) { } else { streamer_buffering = 0; - plug_trigger_event_trackinfochanged (streaming_track); + send_trackinfochanged (streaming_track); badsong = -1; streamer_set_nextsong (-2, -2); pl_unlock (); @@ -573,7 +620,7 @@ streamer_set_current (playItem_t *it) { trace ("streamer_set_current %s\n", playing_track ? pl_find_meta (playing_track, ":URI") : "null"); DB_output_t *output = plug_get_output (); int err = 0; - int send_songstarted = 0; + int do_songstarted = 0; playItem_t *from, *to; // need to add refs here, because streamer_start_playback can destroy items from = playing_track; @@ -588,7 +635,7 @@ streamer_set_current (playItem_t *it) { if (!playing_track || output->state () == OUTPUT_STATE_STOPPED) { streamer_buffering = 1; trace ("\033[0;35mstreamer_start_playback[1] from %p to %p\033[37;0m\n", from, it); - send_songstarted = 1; + do_songstarted = 1; streamer_start_playback (from, it); bytes_until_next_song = -1; } @@ -605,10 +652,10 @@ streamer_set_current (playItem_t *it) { } if (to) { trace ("draw before init: %p->%p, playing_track=%p, playlist_track=%p\n", from, to, playing_track, playlist_track); - plug_trigger_event_trackinfochanged (to); + send_trackinfochanged (to); } if (from) { - plug_trigger_event_trackinfochanged (from); + send_trackinfochanged (from); } char decoder_id[100] = ""; char filetype[100] = ""; @@ -712,7 +759,7 @@ streamer_set_current (playItem_t *it) { streamer_buffering = 0; if (playlist_track == it) { trace ("redraw track %d; playing_track=%p; playlist_track=%p\n", to, playing_track, playlist_track); - plug_trigger_event_trackinfochanged (to); + send_trackinfochanged (to); } err = -1; goto error; @@ -733,7 +780,7 @@ streamer_set_current (playItem_t *it) { it->played = 1; streamer_buffering = 0; if (playlist_track == it) { - plug_trigger_event_trackinfochanged (to); + send_trackinfochanged (to); } if (from) { pl_item_unref (from); @@ -754,11 +801,12 @@ success: new_fileinfo = NULL; } mutex_unlock (decodemutex); - if (send_songstarted && playing_track) { + if (do_songstarted && playing_track) { trace ("songstarted %s\n", playing_track ? pl_find_meta (playing_track, ":URI") : "null"); - plug_trigger_event (DB_EV_SONGSTARTED, 0); + playtime = 0; + send_songstarted (playing_track); } - plug_trigger_event_trackinfochanged (to); + send_trackinfochanged (to); trace ("\033[0;32mstr: %p (%s), ply: %p (%s)\033[37;0m\n", streaming_track, streaming_track ? pl_find_meta (streaming_track, ":URI") : "null", playing_track, playing_track ? pl_find_meta (playing_track, ":URI") : "null"); @@ -857,7 +905,7 @@ streamer_start_new_song (void) { } mutex_unlock (decodemutex); - plug_trigger_event_trackchange (NULL, NULL); + send_trackchanged (NULL, NULL); return; } int ret = streamer_set_current (try); @@ -958,7 +1006,7 @@ streamer_thread (void *ctx) { trace ("\033[0;34mnextsong=%d\033[37;0m\n", nextsong); if (playing_track) { trace ("sending songfinished to plugins [3]\n"); - plug_trigger_event (DB_EV_SONGFINISHED, 0); + send_songfinished (playing_track); } streamer_start_new_song (); // it's totally possible that song was switched @@ -975,7 +1023,7 @@ streamer_thread (void *ctx) { output->stop (); if (playing_track) { trace ("sending songfinished to plugins [1]\n"); - plug_trigger_event (DB_EV_SONGFINISHED, 0); + send_songfinished (playing_track); } if (from) { pl_item_ref (from); @@ -985,7 +1033,7 @@ streamer_thread (void *ctx) { pl_item_unref (playing_track); playing_track = NULL; } - plug_trigger_event_trackchange (from, NULL); + send_trackchanged (from, NULL); if (from) { pl_item_unref (from); } @@ -1015,13 +1063,14 @@ streamer_thread (void *ctx) { // plugin will get pointer to str_playing_song if (playing_track) { trace ("sending songfinished to plugins [2]\n"); - plug_trigger_event (DB_EV_SONGFINISHED, 0); + send_songfinished (playing_track); } // copy streaming into playing trace ("\033[0;35mstreamer_start_playback[2] from %p to %p\033[37;0m\n", playing_track, streaming_track); streamer_start_playback (playing_track, streaming_track); trace ("songstarted %s\n", playing_track ? pl_find_meta (playing_track, ":URI") : "null"); - plug_trigger_event (DB_EV_SONGSTARTED, 0); + playtime = 0; + send_songstarted (playing_track); last_bitrate = -1; avg_bitrate = -1; playlist_track = playing_track; @@ -1105,7 +1154,7 @@ streamer_thread (void *ctx) { bytes_until_next_song = -1; streamer_buffering = 1; if (streaming_track) { - plug_trigger_event_trackinfochanged (streaming_track); + send_trackinfochanged (streaming_track); } mutex_lock (decodemutex); @@ -1125,7 +1174,7 @@ streamer_thread (void *ctx) { if (!dec || !fileinfo) { if (streaming_track) { - plug_trigger_event_trackinfochanged (streaming_track); + send_trackinfochanged (streaming_track); } trace ("failed to restart prev track on seek, trying to jump to next track\n"); streamer_move_to_nextsong (0); @@ -1138,7 +1187,7 @@ streamer_thread (void *ctx) { bytes_until_next_song = -1; streamer_buffering = 1; if (streaming_track) { - plug_trigger_event_trackinfochanged (streaming_track); + send_trackinfochanged (streaming_track); } float dur = pl_get_item_duration (playing_track); if (fileinfo && playing_track && dur > 0) { @@ -1236,7 +1285,7 @@ streamer_thread (void *ctx) { if ((streamer_ringbuf.remaining > 128000 && streamer_buffering) || !streaming_track) { streamer_buffering = 0; if (streaming_track) { - plug_trigger_event_trackinfochanged (streaming_track); + send_trackinfochanged (streaming_track); } } struct timeval tm2; @@ -1721,10 +1770,7 @@ streamer_read (char *bytes, int size) { if (sz) { ringbuf_read (&streamer_ringbuf, bytes, sz); playpos += (float)sz/output->fmt.samplerate/((output->fmt.bps>>3)*output->fmt.channels) * dsp_ratio; - playing_track->playtime += (float)sz/output->fmt.samplerate/((output->fmt.bps>>3)*output->fmt.channels); - if (playlist_track) { - playlist_track->playtime = playing_track->playtime; - } + playtime += (float)sz/output->fmt.samplerate/((output->fmt.bps>>3)*output->fmt.channels); if (bytes_until_next_song > 0) { bytes_until_next_song -= sz; if (bytes_until_next_song < 0) { @@ -1854,7 +1900,7 @@ streamer_play_current_track (void) { if (output->state () == OUTPUT_STATE_PAUSED && playing_track) { // unpause currently paused track output->unpause (); - plug_trigger_event_paused (0); + messagepump_push (DB_EV_PAUSED, 0, 0, 0); } else if (plt->current_row[PL_MAIN] != -1) { // play currently selected track in current playlist |