Skip to content

Commit

Permalink
moved playtime and started_timestamp from playitem to streamer global…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
Oleksiy-Yakovenko committed May 4, 2011
1 parent 745fa29 commit 7710ed4
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 158 deletions.
6 changes: 4 additions & 2 deletions deadbeef.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
14 changes: 7 additions & 7 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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:
Expand All @@ -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 ();
Expand Down Expand Up @@ -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 ();

Expand Down
25 changes: 17 additions & 8 deletions playlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand All @@ -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]);
Expand All @@ -3681,17 +3690,17 @@ 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;
}
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;
Expand All @@ -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;
Expand All @@ -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;
}
Expand Down
2 changes: 0 additions & 2 deletions playlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
68 changes: 3 additions & 65 deletions plugins.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
}
Expand Down
18 changes: 0 additions & 18 deletions plugins.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,6 @@ plug_ev_subscribe (DB_plugin_t *plugin, int ev, DB_callback_t callback, uintptr_
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);

Expand Down
Loading

0 comments on commit 7710ed4

Please sign in to comment.