summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--deadbeef.h7
-rw-r--r--main.c29
-rw-r--r--playlist.c7
-rw-r--r--playlist.h4
-rw-r--r--plugins.c31
-rw-r--r--plugins.h3
-rw-r--r--plugins/gtkui/gtkplaylist.c15
-rw-r--r--plugins/gtkui/gtkplaylist.h1
-rw-r--r--plugins/gtkui/gtkui.c34
-rw-r--r--streamer.c16
-rw-r--r--streamer.h3
11 files changed, 101 insertions, 49 deletions
diff --git a/deadbeef.h b/deadbeef.h
index 4c4c0fd1..355f9e48 100644
--- a/deadbeef.h
+++ b/deadbeef.h
@@ -105,6 +105,12 @@ typedef struct {
DB_playItem_t *song;
} DB_event_song_t;
+typedef struct {
+ DB_event_t ev;
+ int from;
+ int to;
+} DB_event_songchange_t;
+
typedef struct DB_conf_item_s {
char *key;
char *value;
@@ -122,6 +128,7 @@ enum {
DB_EV_SONGFINISHED = 3, // triggers when song finished playing (for scrobblers and such)
DB_EV_TRACKDELETED = 4, // triggers when track is to be deleted from playlist
DB_EV_CONFIGCHANGED = 5, // configuration option changed
+ DB_EV_ACTIVATE = 6, // will be fired every time player is activated
DB_EV_MAX
};
diff --git a/main.c b/main.c
index 8b0d0ce7..c2c608d5 100644
--- a/main.c
+++ b/main.c
@@ -20,6 +20,7 @@
#include <string.h>
#include <stdlib.h>
#include <time.h>
+#include <limits.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/types.h>
@@ -119,9 +120,7 @@ exec_command_line (const char *cmdline, int len, int filter) {
// add files
if (!queue) {
pl_free ();
- // <placeholder>
- // reset selection in playlist
- guiplug_reset_selection ();
+ pl_reset_cursor ();
}
while (parg < pend) {
char resolved[PATH_MAX];
@@ -201,17 +200,13 @@ server_update (void) {
int size;
if ((size = recv (s2, str, 2048, 0)) >= 0) {
if (size == 1 && str[0] == 0) {
- // <placeholder>
- // should notify gui plugin that user tried to run
- // application while already running
- guiplug_showwindow ();
+ // FIXME: that should be called right after activation of gui plugin
+ plug_trigger_event (DB_EV_ACTIVATE, 0);
}
else {
int res = exec_command_line (str, size, 0);
if (res == 2) {
- // <placeholder>
- // play a song, notify gui plugin
- guiplug_play_current_song ();
+ streamer_play_current_track ();
}
}
}
@@ -254,21 +249,17 @@ player_thread (uintptr_t ctx) {
}
break;
case M_TERMINATE:
+ // FIXME: should signal main thread about termination
+ // or will that be new main thread?
+#if 0
// <placeholder>
// tell gui plugin to shut down
// FIXME: cleanup properly on main thread
guiplug_shutdown ();
+#endif
return;
case M_SONGCHANGED:
- {
- int from = p1;
- int to = p2;
- // <placeholder>
- // notify gui that song was changed
- // probably using DB_EV_SONGCHANGED
- guiplug_songchanged (from, to);
- plug_trigger_event (DB_EV_SONGCHANGED, 0);
- }
+ plug_trigger_event_songchanged (p1, p2);
break;
case M_PLAYSONG:
// <placeholder>
diff --git a/playlist.c b/playlist.c
index dfbd7ef1..fbc85a53 100644
--- a/playlist.c
+++ b/playlist.c
@@ -1641,3 +1641,10 @@ void
pl_sort (const char *meta) {
}
+void
+pl_reset_cursor (void) {
+ int i;
+ for (i = 0; i < PL_MAX_ITERATORS; i++) {
+ playlist_current_row[i] = -1;
+ }
+}
diff --git a/playlist.h b/playlist.h
index e7498599..40a7c44a 100644
--- a/playlist.h
+++ b/playlist.h
@@ -56,6 +56,7 @@ typedef struct playItem_s {
extern playItem_t *playlist_head[PL_MAX_ITERATORS]; // head of linked list
extern playItem_t *playlist_tail[PL_MAX_ITERATORS]; // tail of linked list
+extern int playlist_current_row[PL_MAX_ITERATORS]; // current row (cursor)
extern playItem_t *playlist_current_ptr; // pointer to a real current playlist item (or NULL)
extern int pl_count;
@@ -169,4 +170,7 @@ pl_get_item_duration (playItem_t *it);
int
pl_format_title (playItem_t *it, char *s, int size, const char *fmt);
+void
+pl_reset_cursor (void);
+
#endif // __PLAYLIST_H
diff --git a/plugins.c b/plugins.c
index 72f6df3c..c568fa15 100644
--- a/plugins.c
+++ b/plugins.c
@@ -283,6 +283,15 @@ plug_quit (void) {
/////// non-api functions (plugin support)
void
+plug_event_call (DB_event_t *ev) {
+ for (int i = 0; i < MAX_HANDLERS; i++) {
+ if (handlers[ev->event][i].plugin && !handlers[ev][i].plugin->inactive) {
+ handlers[ev->event][i].callback (event, handlers[ev->event][i].data);
+ }
+ }
+}
+
+void
plug_trigger_event (int ev, uintptr_t param) {
mutex_lock (mutex);
DB_event_t *event;
@@ -290,32 +299,44 @@ plug_trigger_event (int ev, uintptr_t param) {
case DB_EV_SONGSTARTED:
case DB_EV_SONGFINISHED:
{
- DB_event_song_t *pev = malloc (sizeof (DB_event_song_t));
+ DB_event_song_t *pev = _alloca (sizeof (DB_event_song_t));
pev->song = DB_PLAYITEM (&str_playing_song);
event = DB_EVENT (pev);
}
break;
case DB_EV_TRACKDELETED:
{
- DB_event_song_t *pev = malloc (sizeof (DB_event_song_t));
+ DB_event_song_t *pev = _alloca (sizeof (DB_event_song_t));
pev->song = DB_PLAYITEM (param);
event = DB_EVENT (pev);
}
break;
default:
- event = malloc (sizeof (DB_event_t));
+ event = _alloca (sizeof (DB_event_t));
}
event->event = ev;
event->time = (double)clock () / CLOCKS_PER_SEC;
+ plug_event_call (event);
+ mutex_unlock (mutex);
+}
+
+void
+plug_trigger_event_songchanged (int from, int to) {
+ mutex_lock (mutex);
+ DB_event_songchange_t event;
+ event.ev.event = DB_EV_SONGCHANGED;
+ event.ev.time = (double)clock () / CLOCKS_PER_SEC;
+ event.from = from;
+ event.to = to;
+
for (int i = 0; i < MAX_HANDLERS; i++) {
if (handlers[ev][i].plugin && !handlers[ev][i].plugin->inactive) {
- handlers[ev][i].callback (event, handlers[ev][i].data);
+ handlers[ev][i].callback (event.ev.event, handlers[ev][i].data);
}
}
free (event);
mutex_unlock (mutex);
}
-
int
plug_init_plugin (DB_plugin_t* (*loadfunc)(DB_functions_t *), void *handle) {
DB_plugin_t *plugin_api = loadfunc (&deadbeef_api);
diff --git a/plugins.h b/plugins.h
index 671da5f8..533058c6 100644
--- a/plugins.h
+++ b/plugins.h
@@ -38,6 +38,9 @@ void
plug_trigger_event (int ev, uintptr_t param);
void
+plug_trigger_event_songchanged (int from, int to);
+
+void
plug_md5 (uint8_t sig[16], const char *in, int len);
void
diff --git a/plugins/gtkui/gtkplaylist.c b/plugins/gtkui/gtkplaylist.c
index cef45ea4..65334248 100644
--- a/plugins/gtkui/gtkplaylist.c
+++ b/plugins/gtkui/gtkplaylist.c
@@ -1740,21 +1740,6 @@ gtkpl_add_files (gtkplaylist_t *ps, GSList *lst) {
GDK_THREADS_LEAVE();
}
-void
-gtkpl_playsong (gtkplaylist_t *ps) {
- if (p_ispaused ()) {
- p_unpause ();
- }
- else if (ps->row != -1) {
- p_stop ();
- streamer_set_nextsong (ps->row, 1);
- }
- else {
- p_stop ();
- streamer_set_nextsong (0, 1);
- }
-}
-
int
gtkpl_get_idx_of (gtkplaylist_t *ps, playItem_t *it) {
playItem_t *c = playlist_head[ps->iterator];
diff --git a/plugins/gtkui/gtkplaylist.h b/plugins/gtkui/gtkplaylist.h
index 2e827839..477afa60 100644
--- a/plugins/gtkui/gtkplaylist.h
+++ b/plugins/gtkui/gtkplaylist.h
@@ -81,7 +81,6 @@ typedef struct {
// current state
int scrollpos;
int hscrollpos;
- int row;
double clicktime; // for doubleclick detection
int nvisiblerows;
int nvisiblefullrows;
diff --git a/plugins/gtkui/gtkui.c b/plugins/gtkui/gtkui.c
index c5a87056..32c58e95 100644
--- a/plugins/gtkui/gtkui.c
+++ b/plugins/gtkui/gtkui.c
@@ -227,11 +227,6 @@ guiplug_shutdown (void) {
}
void
-guiplug_songchanged (int from, int to) {
- gtkpl_songchanged_wrapper (from, to);
-}
-
-void
guiplug_start_current_track (void) {
gtkpl_playsong (&main_playlist);
if (playlist_current_ptr) {
@@ -321,10 +316,31 @@ guiplug_frameupdate (void) {
update_songinfo ();
}
-void
-guiplug_reset_selection (void) {
- search_playlist.row = -1;
- main_playlist.row = -1;
+static int
+gtkui_on_activate (DB_event_t *ev, uintptr_t data) {
+ GDK_THREADS_ENTER();
+ gtk_widget_show (mainwin);
+ gtk_window_present (GTK_WINDOW (mainwin));
+ GDK_THREADS_LEAVE();
+}
+
+static int
+gtkui_on_songchanged (DB_event_song_t *ev, uintptr_t data) {
+ gtkpl_songchanged_wrapper (from, to);
+}
+
+static int
+gtkui_start (void) {
+ deadbeef->ev_subscribe (DB_PLUGIN (&plugin), DB_EV_ACTIVATE, DB_CALLBACK (gtkui_on_activate), 0);
+ deadbeef->ev_subscribe (DB_PLUGIN (&plugin), DB_EV_SONGCHANGED, DB_CALLBACK (gtkui_on_songchanged), 0);
+ return 0;
+}
+
+static int
+gtkui_stop (void) {
+ deadbeef->ev_unsubscribe (DB_PLUGIN (&plugin), DB_EV_ACTIVATE, DB_CALLBACK (gtkui_on_activate), 0);
+ deadbeef->ev_unsubscribe (DB_PLUGIN (&plugin), DB_EV_SONGCHANGED, DB_CALLBACK (gtkui_on_songchanged), 0);
+ return 0;
}
// define plugin interface
diff --git a/streamer.c b/streamer.c
index ebc17c87..6717ca18 100644
--- a/streamer.c
+++ b/streamer.c
@@ -884,3 +884,19 @@ streamer_configchanged (void) {
mutex_unlock (decodemutex);
}
}
+
+void
+streamer_play_current_track (void) {
+ if (p_ispaused ()) {
+ p_unpause ();
+ }
+ else if (ps->row != -1) {
+ p_stop ();
+ streamer_set_nextsong (ps->row, 1);
+ }
+ else {
+ p_stop ();
+ streamer_set_nextsong (0, 1);
+ }
+}
+
diff --git a/streamer.h b/streamer.h
index 9544c755..9e686d79 100644
--- a/streamer.h
+++ b/streamer.h
@@ -78,4 +78,7 @@ streamer_get_streaming_track (void);
void
streamer_configchanged (void);
+void
+streamer_play_current_track (void);
+
#endif // __STREAMER_H