summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Alexey Yakovenko <wakeroid@gmail.com>2010-04-19 20:27:52 +0200
committerGravatar Alexey Yakovenko <wakeroid@gmail.com>2010-04-19 20:27:52 +0200
commitd10d940aa6a9c361c61d81ed378b46b8afb17198 (patch)
treeaf7ed351df6a2c906b7086fb371b6a22f3038fd3
parent671f7f881faa64cede428431fb1d61e8fa007a26 (diff)
cleaned up some of bad/unused messages and events;
implemented new notification-daemon osd;
-rw-r--r--configure.ac31
-rw-r--r--deadbeef.h14
-rw-r--r--main.c12
-rw-r--r--plugins.c34
-rw-r--r--plugins.h6
-rw-r--r--plugins/cdda/cdda.c5
-rw-r--r--plugins/gtkui/gtkui.c96
-rw-r--r--plugins/mpgmad/mpgmad.c7
-rw-r--r--plugins/notify/Makefile.am2
-rw-r--r--plugins/notify/notify.c177
-rw-r--r--plugins/vorbis/vorbis.c5
-rw-r--r--streamer.c58
12 files changed, 297 insertions, 150 deletions
diff --git a/configure.ac b/configure.ac
index dae54f3e..eb14b0d9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -73,14 +73,8 @@ AC_ARG_ENABLE(gme, [ --disable-gme build Game Music Emu plugin f
AC_ARG_ENABLE(dumb, [ --disable-dumb build D.U.M.B. plugin for MOD, S3M and other tracker formats (default: enabled)], [enable_dumb=$enableval], [enable_dumb=yes])
AC_ARG_ENABLE(notify, [ --disable-notify build notification-daemon support plugin (default: enabled)], [enable_notify=$enableval], [enable_notify=yes])
-AC_ARG_ENABLE(libnotify, [ --enable-libnotify include support for OSD notifications into GTKUI plugin (default: no)], [enable_libnotify=$enableval], [enable_libnotify=no])
-
PKG_CHECK_MODULES(DEPS, samplerate)
-dnl if test "x$enable_libnotify" = "xyes" ; then
-dnl PKG_CHECK_MODULES(NOTIFY_DEPS, libnotify >= 0.4.4, HAVE_NOTIFY=yes, HAVE_NOTIFY=no)
-dnl fi
-
if test "x$enable_gtkui" != "xno" ; then
PKG_CHECK_MODULES(GTKUI_DEPS, gtk+-2.0 >= 2.12 gthread-2.0 glib-2.0, HAVE_GTK=yes, HAVE_GTK=no)
else
@@ -123,11 +117,7 @@ if test "x$HAVE_CURL" = "xyes"; then
AC_SUBST(CURL_LIBS)
fi
-AC_CHECK_LIB([dbus-1], [main], [HAVE_DBUS=yes])
-if test "x$HAVE_DBUS" = "xyes"; then
- DBUS_LIBS="-ldbus-1"
- AC_SUBST(DBUS_LIBS)
-fi
+PKG_CHECK_MODULES(DBUS_DEPS, dbus-1, HAVE_DBUS=yes, HAVE_DBUS=no)
dnl mpgmad plugin
if test "x$enable_mpgmad" != "xno" ; then
@@ -216,16 +206,12 @@ dnl gtkui plugin
if test "x$enable_gtkui" != "xno" ; then
if test "x$HAVE_GTK" = "xyes" ; then
HAVE_GTKUI=yes
- AC_SUBST(GTKUI_DEPS_CFLAGS)
- AC_SUBST(GTKUI_DEPS_LIBS)
fi
fi
if test "x$enable_alsa" != "xno" ; then
if test "x$HAVE_ALSA" = "xyes" ; then
HAVE_ALSAPLUGIN=yes
- AC_SUBST(ALSA_DEPS_CFLAGS)
- AC_SUBST(ALSA_DEPS_LIBS)
fi
fi
@@ -233,17 +219,9 @@ if test "x$enable_ffmpeg" != "xno" ; then
if test "x$HAVE_FFMPEG" = "xyes" ; then
HAVE_FFMPEGPLUGIN=yes
AC_CHECK_HEADER([ffmpeg/avformat.h], FFMPEG_DEPS_CFLAGS="$FFMPEG_DEPS_CFLAGS -D FFMPEG_OLD")
- AC_SUBST(FFMPEG_DEPS_CFLAGS)
- AC_SUBST(FFMPEG_DEPS_LIBS)
fi
fi
-dnl if test "x$HAVE_NOTIFY" = "xyes"; then
-dnl AC_DEFINE(HAVE_NOTIFY,1,[Use libnotify])
-dnl AC_SUBST(NOTIFY_DEPS_CFLAGS)
-dnl AC_SUBST(NOTIFY_DEPS_LIBS)
-dnl fi
-
if test "x$enable_hotkeys" != "xno" ; then
AC_CHECK_HEADER([X11/Xlib.h], HAVE_XLIB_H=yes)
if test "x$HAVE_XLIB_H" = "xyes" ; then
@@ -295,8 +273,6 @@ fi
if test "x$enable_pulseaudio" != "xno"; then
if test "x$HAVE_PULSE" = "xyes"; then
HAVE_PULSEPLUGIN=yes
- AC_SUBST(PULSE_DEPS_CFLAGS)
- AC_SUBST(PULSE_DEPS_LIBS)
fi
fi
@@ -345,8 +321,10 @@ fi
if test "x$HAVE_DBUS" = "xyes" && test "x$enable_notify" != "xno" ; then
HAVE_NOTIFY=yes
- NOTIFY_LIBS="$DBUS_LIBS"
+ NOTIFY_LIBS="$DBUS_DEPS_LIBS"
+ NOTIFY_CFLAGS="$DBUS_DEPS_CFLAGS"
AC_SUBST(NOTIFY_LIBS)
+ AC_SUBST(NOTIFY_CFLAGS)
fi
PLUGINS_DIRS="plugins/lastfm plugins/mpgmad plugins/vorbis plugins/flac plugins/wavpack plugins/sndfile plugins/vfs_curl plugins/cdda plugins/gtkui plugins/alsa plugins/ffmpeg plugins/hotkeys plugins/oss plugins/artwork plugins/adplug plugins/ffap plugins/sid plugins/nullout plugins/supereq plugins/vtx plugins/gme plugins/dumb plugins/pulse plugins/notify"
@@ -422,7 +400,6 @@ dnl PRINT_PLUGIN_INFO([faad2],[aac/mp4 player],[test $HAVE_FAAD && test $HAVE_MP
PRINT_PLUGIN_INFO([cdda],[cd audio player],[test "x$HAVE_CDDAPLUGIN" = "xyes"])
PRINT_PLUGIN_INFO([gtkui],[GTK user interface],[test "x$HAVE_GTK" = "xyes"])
PRINT_PLUGIN_INFO([hotkeys],[Global hotkeys support],[test "x$HAVE_HOTKEYS" = "xyes"])
-dnl PRINT_PLUGIN_INFO([libnotify],[Current track notification],[test "x$HAVE_NOTIFY" = "xyes"])
PRINT_PLUGIN_INFO([ffmpeg],[ffmpeg codecs],[test "x$HAVE_FFMPEGPLUGIN" = "xyes"])
PRINT_PLUGIN_INFO([oss],[oss output plugin],[test "x$HAVE_OSS" = "xyes"])
PRINT_PLUGIN_INFO([pulse],[PulseAudio output plugin],[test "x$HAVE_PULSEPLUGIN" = "xyes"])
diff --git a/deadbeef.h b/deadbeef.h
index 95ff006e..d3500f8c 100644
--- a/deadbeef.h
+++ b/deadbeef.h
@@ -193,14 +193,13 @@ typedef struct {
typedef struct {
DB_event_t ev;
- int index;
DB_playItem_t *track;
} DB_event_track_t;
typedef struct {
DB_event_t ev;
- int from;
- int to;
+ DB_playItem_t *from;
+ DB_playItem_t *to;
} DB_event_trackchange_t;
typedef struct {
@@ -223,7 +222,7 @@ enum {
DB_EV_SONGCHANGED = 1, // triggers when song was just changed
DB_EV_SONGSTARTED = 2, // triggers when song started playing (for scrobblers and such)
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_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_TRACKINFOCHANGED = 7, // notify plugins that trackinfo was changed
@@ -260,11 +259,11 @@ enum {
M_STOPSONG,
M_PAUSESONG,
M_PLAYRANDOM,
- M_SONGCHANGED, // p1=from, p2=to
+// M_SONGCHANGED, // p1=from, p2=to
M_TERMINATE, // must be sent to player thread to terminate
M_PLAYLISTREFRESH,
M_REINIT_SOUND,
- M_TRACKCHANGED, // p1=tracknumber
+// M_TRACKCHANGED, // p1=tracknumber
M_CONFIGCHANGED, // no arguments
};
@@ -515,6 +514,9 @@ typedef struct {
const char * (*plug_get_decoder_id) (const char *id);
void (*plug_remove_decoder_id) (const char *id);
struct DB_plugin_s *(*plug_get_for_id) (const char *id);
+ // plugin events
+ void (*plug_trigger_event_trackchange) (DB_playItem_t *from, DB_playItem_t *to);
+ void (*plug_trigger_event_trackinfochanged) (DB_playItem_t *track);
// misc utilities
int (*is_local_file) (const char *fname); // returns 1 for local filename, 0 otherwise
} DB_functions_t;
diff --git a/main.c b/main.c
index df957bee..a1215d97 100644
--- a/main.c
+++ b/main.c
@@ -348,15 +348,15 @@ player_mainloop (void) {
break;
case M_TERMINATE:
return;
- case M_SONGCHANGED:
- plug_trigger_event_trackchange (p1, p2);
- break;
+// case M_SONGCHANGED:
+// plug_trigger_event_trackchange (p1, p2);
+// break;
case M_PLAYSONG:
streamer_play_current_track ();
break;
- case M_TRACKCHANGED:
- plug_trigger_event_trackinfochanged (p1);
- break;
+// case M_TRACKCHANGED:
+// plug_trigger_event_trackinfochanged (p1);
+// break;
case M_PLAYSONGNUM:
p_stop ();
pl_playqueue_clear ();
diff --git a/plugins.c b/plugins.c
index 7183bd59..d0b2e4cb 100644
--- a/plugins.c
+++ b/plugins.c
@@ -245,6 +245,9 @@ static DB_functions_t deadbeef_api = {
.plug_get_decoder_id = plug_get_decoder_id,
.plug_remove_decoder_id = plug_remove_decoder_id,
.plug_get_for_id = plug_get_for_id,
+ // plugin events
+ .plug_trigger_event_trackchange = (void (*) (DB_playItem_t *from, DB_playItem_t *to))plug_trigger_event_trackchange,
+ .plug_trigger_event_trackinfochanged = (void (*) (DB_playItem_t *track))plug_trigger_event_trackinfochanged,
// misc utilities
.is_local_file = plug_is_local_file,
};
@@ -447,24 +450,17 @@ plug_event_call (DB_event_t *ev) {
void
plug_trigger_event (int ev, uintptr_t param) {
DB_event_t *event;
- playItem_t *pltrack = NULL;
switch (ev) {
case DB_EV_SONGSTARTED:
case DB_EV_SONGFINISHED:
{
DB_event_track_t *pev = alloca (sizeof (DB_event_track_t));
- pev->index = -1;
- pltrack = streamer_get_playing_track ();
+ playItem_t *pltrack = streamer_get_playing_track ();
pev->track = DB_PLAYITEM (pltrack);
- event = DB_EVENT (pev);
+ if (pltrack) {
+ pl_item_unref (pltrack);
}
- break;
- case DB_EV_TRACKDELETED:
- {
- DB_event_track_t *pev = alloca (sizeof (DB_event_track_t));
- pev->index = -1; // FIXME
- pev->track = DB_PLAYITEM (param);
- event = DB_EVENT (pev);
+ event = DB_EVENT (pev);
}
break;
default:
@@ -472,30 +468,22 @@ plug_trigger_event (int ev, uintptr_t param) {
}
event->event = ev;
plug_event_call (event);
- if (pltrack) {
- pl_item_unref (pltrack);
- }
}
void
-plug_trigger_event_trackchange (int from, int to) {
+plug_trigger_event_trackchange (playItem_t *from, playItem_t *to) {
DB_event_trackchange_t event;
event.ev.event = DB_EV_SONGCHANGED;
- event.from = from;
- event.to = to;
+ event.from = (DB_playItem_t *)from;
+ event.to = (DB_playItem_t *)to;
plug_event_call (DB_EVENT (&event));
}
void
-plug_trigger_event_trackinfochanged (int trk) {
+plug_trigger_event_trackinfochanged (playItem_t *track) {
DB_event_track_t event;
event.ev.event = DB_EV_TRACKINFOCHANGED;
- event.index = trk;
- playItem_t *track = pl_get_for_idx (trk);
event.track = DB_PLAYITEM (track);
plug_event_call (DB_EVENT (&event));
- if (track) {
- pl_item_unref (track);
- }
}
void
diff --git a/plugins.h b/plugins.h
index 70a93249..d2e2b519 100644
--- a/plugins.h
+++ b/plugins.h
@@ -22,6 +22,8 @@
extern DB_functions_t *deadbeef;
+struct playItem_s;
+
void
plug_load_all (void);
@@ -38,10 +40,10 @@ void
plug_trigger_event (int ev, uintptr_t param);
void
-plug_trigger_event_trackchange (int from, int to);
+plug_trigger_event_trackchange (struct playItem_s *from, struct playItem_s *to);
void
-plug_trigger_event_trackinfochanged (int trk);
+plug_trigger_event_trackinfochanged (struct playItem_s *track);
void
plug_trigger_event_paused (int paused);
diff --git a/plugins/cdda/cdda.c b/plugins/cdda/cdda.c
index 4632be3f..998fd277 100644
--- a/plugins/cdda/cdda.c
+++ b/plugins/cdda/cdda.c
@@ -329,10 +329,7 @@ cddb_thread (void *items_i)
{
// FIXME: problem will happen here if item(s) were deleted from playlist, and new items were added in their places
// possible solutions: catch EV_TRACKDELETED and mark item(s) in every thread as NULL
- int idx = deadbeef->pl_get_idx_of (items[i]);
trace ("track %d, artist=%s, album=%s, title=%s\n", i, artist, disc_title, cddb_track_get_title (track));
- if (idx == -1)
- continue;
deadbeef->pl_delete_all_meta (items[i]);
deadbeef->pl_add_meta (items[i], "artist", artist);
@@ -341,7 +338,7 @@ cddb_thread (void *items_i)
char tmp[5];
snprintf (tmp, sizeof (tmp), "%02d", trk);
deadbeef->pl_add_meta (items[i], "track", tmp);
- deadbeef->sendmessage (M_TRACKCHANGED, 0, idx, 0);
+ deadbeef->plug_trigger_event_trackinfochanged (items[i]);
deadbeef->pl_item_unref (items[i]);
}
cddb_disc_destroy (disc);
diff --git a/plugins/gtkui/gtkui.c b/plugins/gtkui/gtkui.c
index 359613b9..b9471b4d 100644
--- a/plugins/gtkui/gtkui.c
+++ b/plugins/gtkui/gtkui.c
@@ -93,9 +93,10 @@ gtkpl_free (DdbListview *pl) {
struct fromto_t {
- int from;
- int to;
+ DB_playItem_t *from;
+ DB_playItem_t *to;
};
+
static gboolean
update_win_title_idle (gpointer data);
static gboolean
@@ -335,12 +336,18 @@ redraw_queued_tracks_cb (gpointer nothing) {
}
void
-gtkpl_songchanged_wrapper (int from, int to) {
+gtkpl_songchanged_wrapper (DB_playItem_t *from, DB_playItem_t *to) {
struct fromto_t *ft = malloc (sizeof (struct fromto_t));
ft->from = from;
ft->to = to;
+ if (from) {
+ deadbeef->pl_item_ref (from);
+ }
+ if (to) {
+ deadbeef->pl_item_ref (to);
+ }
g_idle_add (update_win_title_idle, ft);
- if (ft->to == -1) {
+ if (to) {
// redraw seekbar
g_idle_add (redraw_seekbar_cb, NULL);
}
@@ -362,11 +369,6 @@ set_tray_tooltip (const char *text) {
#endif
}
-struct trackinfo_t {
- int index;
- DB_playItem_t *track;
-};
-
static void
current_track_changed (DB_playItem_t *it) {
char str[600];
@@ -382,26 +384,33 @@ current_track_changed (DB_playItem_t *it) {
static gboolean
trackinfochanged_cb (gpointer data) {
- struct trackinfo_t *ti = (struct trackinfo_t *)data;
+ DB_playItem_t *track = (DB_playItem_t *)data;
GtkWidget *playlist = lookup_widget (mainwin, "playlist");
- ddb_listview_draw_row (DDB_LISTVIEW (playlist), ti->index, (DdbListviewIter)ti->track);
+ if (track) {
+ int idx = deadbeef->pl_get_idx_of (track);
+ if (idx != -1) {
+ ddb_listview_draw_row (DDB_LISTVIEW (playlist), idx, (DdbListviewIter)track);
+ }
+ }
DB_playItem_t *curr = deadbeef->streamer_get_playing_track ();
- if (ti->track == curr) {
- current_track_changed (ti->track);
+ if (track == curr) {
+ current_track_changed (track);
}
if (curr) {
deadbeef->pl_item_unref (curr);
}
- free (ti);
+ if (track) {
+ deadbeef->pl_item_unref (track);
+ }
return FALSE;
}
static int
gtkui_on_trackinfochanged (DB_event_track_t *ev, uintptr_t data) {
- struct trackinfo_t *ti = malloc (sizeof (struct trackinfo_t));
- ti->index = ev->index;
- ti->track = ev->track;
- g_idle_add (trackinfochanged_cb, ti);
+ if (ev->track) {
+ deadbeef->pl_item_ref (ev->track);
+ }
+ g_idle_add (trackinfochanged_cb, ev->track);
return 0;
}
@@ -569,35 +578,34 @@ on_add_location_activate (GtkMenuItem *menuitem,
}
static void
-songchanged (DdbListview *ps, int from, int to) {
+songchanged (DdbListview *ps, DB_playItem_t *from, DB_playItem_t *to) {
int str_plt = deadbeef->streamer_get_current_playlist ();
int plt = deadbeef->plt_get_curr ();
if (plt != str_plt) {
// have nothing to do here -- active playlist is not the one with playing song
return;
}
- if (!ddb_listview_is_scrolling (ps) && to != -1) {
- if (deadbeef->conf_get_int ("playlist.scroll.followplayback", 0)) {
- ddb_listview_scroll_to (ps, to);
- }
- if (deadbeef->conf_get_int ("playlist.scroll.cursorfollowplayback", 0)) {
- ddb_listview_set_cursor (ps, to);
+ int to_idx = -1;
+ if (!ddb_listview_is_scrolling (ps) && to) {
+ to_idx = deadbeef->pl_get_idx_of (to);
+ if (to_idx != -1) {
+ if (deadbeef->conf_get_int ("playlist.scroll.followplayback", 0)) {
+ ddb_listview_scroll_to (ps, to_idx);
+ }
+ if (deadbeef->conf_get_int ("playlist.scroll.cursorfollowplayback", 0)) {
+ ddb_listview_set_cursor (ps, to_idx);
+ }
}
}
- if (from >= 0) {
- DB_playItem_t *it = deadbeef->pl_get_for_idx_and_iter (from, PL_MAIN);
- if (it) {
- ddb_listview_draw_row (ps, from, it);
- deadbeef->pl_item_unref (it);
+ if (from) {
+ int idx = deadbeef->pl_get_idx_of (from);
+ if (idx != -1) {
+ ddb_listview_draw_row (ps, idx, from);
}
}
- if (to >= 0) {
- DB_playItem_t *it = deadbeef->pl_get_for_idx_and_iter (to, PL_MAIN);
- if (it) {
- ddb_listview_draw_row (ps, to, it);
- deadbeef->pl_item_unref (it);
- }
+ if (to && to_idx != -1) {
+ ddb_listview_draw_row (ps, to_idx, to);
}
}
@@ -608,13 +616,13 @@ static NotifyNotification* notification;
static gboolean
update_win_title_idle (gpointer data) {
struct fromto_t *ft = (struct fromto_t *)data;
- int from = ft->from;
- int to = ft->to;
+ DB_playItem_t *from = ft->from;
+ DB_playItem_t *to = ft->to;
free (ft);
// show notification
#if HAVE_NOTIFY
- if (to != -1 && deadbeef->conf_get_int ("gtkui.notify.enable", 0)) {
+ if (to && deadbeef->conf_get_int ("gtkui.notify.enable", 0)) {
DB_playItem_t *track = deadbeef->streamer_get_playing_track ();//deadbeef->pl_get_for_idx (to);
if (track) {
char cmd [1024];
@@ -635,8 +643,8 @@ update_win_title_idle (gpointer data) {
#endif
// update window title
- if (from >= 0 || to >= 0) {
- if (to >= 0) {
+ if (from || to) {
+ if (to) {
DB_playItem_t *it = deadbeef->streamer_get_playing_track ();;
if (it) { // it might have been deleted after event was sent
current_track_changed (it);
@@ -650,6 +658,12 @@ update_win_title_idle (gpointer data) {
}
// update playlist view
songchanged (DDB_LISTVIEW (lookup_widget (mainwin, "playlist")), from, to);
+ if (from) {
+ deadbeef->pl_item_unref (from);
+ }
+ if (to) {
+ deadbeef->pl_item_unref (to);
+ }
return FALSE;
}
diff --git a/plugins/mpgmad/mpgmad.c b/plugins/mpgmad/mpgmad.c
index 2dc1a88d..218f32c5 100644
--- a/plugins/mpgmad/mpgmad.c
+++ b/plugins/mpgmad/mpgmad.c
@@ -875,8 +875,7 @@ cmp3_stream_frame (mpgmad_info_t *info) {
if (!eof) {
if (info->buffer.file->vfs->streaming && info->buffer.currentsample - info->buffer.last_comment_update > 5 * info->info.samplerate) {
- int idx = deadbeef->pl_get_idx_of (info->buffer.it);
- if (idx >= 0) {
+ if (info->buffer.it) {
info->buffer.last_comment_update = info->buffer.currentsample;
const char *vfs_tit = deadbeef->fget_content_name (info->buffer.file);
if (vfs_tit) {
@@ -885,11 +884,11 @@ cmp3_stream_frame (mpgmad_info_t *info) {
char out[1024];
deadbeef->junk_recode (vfs_tit, strlen (vfs_tit), out, sizeof (out), cs);
deadbeef->pl_replace_meta (info->buffer.it, "title", out);
- deadbeef->sendmessage (M_TRACKCHANGED, 0, idx, 0);
+ deadbeef->plug_trigger_event_trackinfochanged (info->buffer.it);
}
else {
deadbeef->pl_replace_meta (info->buffer.it, "title", vfs_tit);
- deadbeef->sendmessage (M_TRACKCHANGED, 0, idx, 0);
+ deadbeef->plug_trigger_event_trackinfochanged (info->buffer.it);
}
}
}
diff --git a/plugins/notify/Makefile.am b/plugins/notify/Makefile.am
index d702f215..f499458f 100644
--- a/plugins/notify/Makefile.am
+++ b/plugins/notify/Makefile.am
@@ -5,5 +5,5 @@ notify_la_SOURCES = notify.c
notify_la_LDFLAGS = -module
notify_la_LIBADD = $(LDADD) $(NOTIFY_LIBS)
-AM_CFLAGS = $(CFLAGS) -std=c99
+AM_CFLAGS = $(CFLAGS) $(NOTIFY_CFLAGS) -std=c99
endif
diff --git a/plugins/notify/notify.c b/plugins/notify/notify.c
index e69de29b..866460be 100644
--- a/plugins/notify/notify.c
+++ b/plugins/notify/notify.c
@@ -0,0 +1,177 @@
+/*
+ DeaDBeeF - ultimate music player for GNU/Linux systems with X11
+ Copyright (C) 2009-2010 Alexey Yakovenko <waker@users.sourceforge.net>
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 2
+ of the License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*/
+#include <dbus/dbus.h>
+#include "../../deadbeef.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define E_NOTIFICATION_BUS_NAME "org.freedesktop.Notifications"
+#define E_NOTIFICATION_INTERFACE "org.freedesktop.Notifications"
+#define E_NOTIFICATION_PATH "/org/freedesktop/Notifications"
+
+DB_functions_t *deadbeef;
+DB_misc_t plugin;
+
+#define NOTIFY_DEFAULT_FORMAT "%a - %t"
+
+
+static void
+notify_marshal_dict_byte(DBusMessageIter *iter, const char *key, char value)
+{
+ DBusMessageIter entry, variant;
+
+ if (!key || !value) return;
+
+ dbus_message_iter_open_container(iter, DBUS_TYPE_DICT_ENTRY, NULL, &entry);
+ dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
+ dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT, "y", &variant);
+ dbus_message_iter_append_basic(&variant, DBUS_TYPE_BYTE, &value);
+ dbus_message_iter_close_container(&entry, &variant);
+ dbus_message_iter_close_container(iter, &entry);
+}
+
+static void
+notify_marshal_dict_string(DBusMessageIter *iter, const char *key, const char *value)
+{
+ DBusMessageIter entry, variant;
+
+ dbus_message_iter_open_container(iter, DBUS_TYPE_DICT_ENTRY, "sv", &entry);
+ dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
+ dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT, "s", &variant);
+ dbus_message_iter_append_basic(&variant, DBUS_TYPE_STRING, &value);
+ dbus_message_iter_close_container(&entry, &variant);
+ dbus_message_iter_close_container(iter, &entry);
+}
+
+
+static int
+on_songchanged (DB_event_trackchange_t *ev, uintptr_t data) {
+ if (ev->to && deadbeef->conf_get_int ("notify.enable", 0)) {
+ DB_playItem_t *track = ev->to;
+ if (track) {
+ char cmd[1024];
+ deadbeef->pl_format_title (track, -1, cmd, sizeof (cmd), -1, deadbeef->conf_get_str ("notify.format", NOTIFY_DEFAULT_FORMAT));
+
+ // escape &
+ char esc[1024];
+
+ char *src = cmd;
+ char *dst = esc;
+ char *end = dst + sizeof (esc) - 1;
+ while (*src && dst < end) {
+ if (*src == '&') {
+ if (end - dst < 5) {
+ break;
+ }
+ strcpy (dst, "&amp;");
+ dst += 5;
+ src++;
+ }
+ else {
+ *dst++ = *src++;
+ }
+ }
+ *dst = 0;
+
+ DBusError error;
+ dbus_error_init (&error);
+ DBusConnection *conn = dbus_bus_get (DBUS_BUS_SESSION, &error);
+ if(conn == NULL) {
+ printf("connection failed: %s",error.message);
+ exit(1);
+ }
+ DBusMessage *msg = dbus_message_new_method_call (E_NOTIFICATION_BUS_NAME, E_NOTIFICATION_PATH, E_NOTIFICATION_INTERFACE, "Notify");
+
+ const char *v_appname = "DeaDBeeF";
+ dbus_uint32_t v_id = 0;
+ const char *v_iconname = PREFIX "/share/deadbeef/pixmaps/play_24.png";
+ const char *v_summary = "DeaDBeeF now playing";
+ const char *v_body = esc;
+ dbus_int32_t v_timeout = -1;
+
+ dbus_message_append_args (msg
+ , DBUS_TYPE_STRING, &v_appname
+ , DBUS_TYPE_UINT32, &v_id
+ , DBUS_TYPE_STRING, &v_iconname
+ , DBUS_TYPE_STRING, &v_summary
+ , DBUS_TYPE_STRING, &v_body
+ , DBUS_TYPE_INVALID
+ );
+
+ DBusMessageIter iter, sub;
+ // actions
+ dbus_message_iter_init_append(msg, &iter);
+ dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "s", &sub);
+ dbus_message_iter_close_container(&iter, &sub);
+ // hints
+ dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "{sv}", &sub);
+ dbus_message_iter_close_container(&iter, &sub);
+
+ dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &v_timeout);
+
+ int serial;
+ dbus_bool_t retval = dbus_connection_send(conn,msg,&serial);
+ printf ("retval: %d\n", retval);
+ //dbus_message_unref (msg);
+ dbus_connection_flush (conn);
+
+ }
+ }
+ return 0;
+}
+
+int
+notify_start (void) {
+ deadbeef->ev_subscribe (DB_PLUGIN (&plugin), DB_EV_SONGCHANGED, DB_CALLBACK (on_songchanged), 0);
+ return 0;
+}
+
+int
+notify_stop (void) {
+ deadbeef->ev_unsubscribe (DB_PLUGIN (&plugin), DB_EV_SONGCHANGED, DB_CALLBACK (on_songchanged), 0);
+ return 0;
+}
+
+static const char settings_dlg[] =
+ "property \"Enable\" checkbox notify.enable 0;\n"
+ "property \"Notification format\" entry notify.format \"" NOTIFY_DEFAULT_FORMAT "\";\n"
+;
+
+DB_misc_t plugin = {
+ DB_PLUGIN_SET_API_VERSION
+ .plugin.type = DB_PLUGIN_MISC,
+ .plugin.version_major = 1,
+ .plugin.version_minor = 0,
+ .plugin.id = "notify",
+ .plugin.name = "OSD Notify",
+ .plugin.descr = "notification daemon OSD",
+ .plugin.author = "Alexey Yakovenko",
+ .plugin.email = "waker@users.sourceforge.net",
+ .plugin.website = "http://deadbeef.sourceforge.net",
+ .plugin.start = notify_start,
+ .plugin.stop = notify_stop,
+ .plugin.configdialog = settings_dlg,
+};
+
+DB_plugin_t *
+notify_load (DB_functions_t *ddb) {
+ deadbeef = ddb;
+ return &plugin.plugin;
+}
diff --git a/plugins/vorbis/vorbis.c b/plugins/vorbis/vorbis.c
index a5a873ab..d31d9f35 100644
--- a/plugins/vorbis/vorbis.c
+++ b/plugins/vorbis/vorbis.c
@@ -257,12 +257,11 @@ cvorbis_read (DB_fileinfo_t *_info, char *bytes, int size) {
}
else {
if (info->ptrack && info->currentsample - info->last_comment_update > 5 * _info->samplerate) {
- int idx = deadbeef->pl_get_idx_of (info->ptrack);
- if (idx >= 0) {
+ if (info->ptrack) {
info->last_comment_update = info->currentsample;
vorbis_comment *vc = ov_comment (&info->vorbis_file, -1);
update_vorbis_comments (info->ptrack, vc);
- deadbeef->sendmessage (M_TRACKCHANGED, 0, idx, 0);
+ deadbeef->plug_trigger_event_trackinfochanged (info->ptrack);
}
else {
info->ptrack = NULL;
diff --git a/streamer.c b/streamer.c
index 2aa77725..14ba8666 100644
--- a/streamer.c
+++ b/streamer.c
@@ -407,7 +407,6 @@ streamer_song_removed_notify (playItem_t *it) {
if (!mutex) {
return; // streamer is not running
}
- plug_trigger_event (DB_EV_TRACKDELETED, (uintptr_t)it);
if (it == playlist_track) {
playlist_track = NULL;
// queue new next song for streaming
@@ -421,15 +420,13 @@ streamer_song_removed_notify (playItem_t *it) {
// that must be called after last sample from str_playing_song was done reading
static int
streamer_set_current (playItem_t *it) {
- int from, to;
- from = playing_track ? str_get_idx_of (playing_track) : -1;
- to = it ? str_get_idx_of (it) : -1;
+ playItem_t *from, *to;
+ from = playing_track;
+ to = it;
if (!playing_track || p_isstopped ()) {
trace ("buffering = on\n");
streamer_buffering = 1;
playlist_track = it;
- //trace ("from=%d, to=%d\n", from, to);
- //messagepump_push (M_SONGCHANGED, 0, from, to);
if (playing_track) {
pl_item_unref (playing_track);
}
@@ -439,7 +436,7 @@ streamer_set_current (playItem_t *it) {
playing_track->played = 1;
trace ("sending songstarted to plugins [2] current playtrack: %s\n", playing_track->fname);
plug_trigger_event (DB_EV_SONGSTARTED, 0);
- messagepump_push (M_SONGCHANGED, 0, from, to);
+ plug_trigger_event_trackchange (from, to);
}
bytes_until_next_song = -1;
}
@@ -459,12 +456,12 @@ streamer_set_current (playItem_t *it) {
if (!it) {
goto success;
}
- if (to != -1) {
- trace ("draw before init: %d->%d, playing_track=%p, playlist_track=%p\n", from, to, playing_track, playlist_track);
- messagepump_push (M_TRACKCHANGED, 0, to, 0);
+ 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);
}
- if (from != -1) {
- messagepump_push (M_TRACKCHANGED, 0, from, 0);
+ if (from) {
+ plug_trigger_event_trackinfochanged (from);
}
if (!it->decoder_id && it->filetype && !strcmp (it->filetype, "content")) {
// try to get content-type
@@ -509,7 +506,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);
- messagepump_push (M_TRACKCHANGED, 0, to, 0);
+ plug_trigger_event_trackinfochanged (to);
}
return -1;
}
@@ -533,7 +530,7 @@ streamer_set_current (playItem_t *it) {
streamer_buffering = 0;
if (playlist_track == it) {
playlist_track = NULL;
- messagepump_push (M_TRACKCHANGED, 0, to, 0);
+ plug_trigger_event_trackinfochanged (to);
}
return -1;
}
@@ -541,7 +538,7 @@ streamer_set_current (playItem_t *it) {
// bytes_until_next_song = 0;
// }
success:
- messagepump_push (M_TRACKCHANGED, 0, to, 0);
+ plug_trigger_event_trackinfochanged (to);
return 0;
}
@@ -624,7 +621,7 @@ streamer_thread (void *ctx) {
}
mutex_unlock (decodemutex);
- messagepump_push (M_SONGCHANGED, 0, -1, -1);
+ plug_trigger_event_trackchange (NULL, NULL);
continue;
}
int ret = streamer_set_current (try);
@@ -664,7 +661,7 @@ streamer_thread (void *ctx) {
}
}
else if (nextsong == -2 && (nextsong_pstate==0 || bytes_until_next_song == 0)) {
- int from = playing_track ? str_get_idx_of (playing_track) : -1;
+ playItem_t *from = playing_track;
bytes_until_next_song = -1;
trace ("nextsong=-2\n");
nextsong = -1;
@@ -678,7 +675,7 @@ streamer_thread (void *ctx) {
pl_item_unref (playing_track);
playing_track = NULL;
}
- messagepump_push (M_SONGCHANGED, 0, from, -1);
+ plug_trigger_event_trackchange (from, NULL);
continue;
}
else if (p_isstopped ()) {
@@ -695,11 +692,11 @@ streamer_thread (void *ctx) {
continue;
}
trace ("bytes_until_next_song=0, starting playback of new song\n");
- int from = playing_track ? str_get_idx_of (playing_track) : -1;
- int to = streaming_track ? str_get_idx_of (streaming_track) : -1;
+ playItem_t *from = playing_track;
+ playItem_t *to = streaming_track;
trace ("from=%d, to=%d\n", from, to);
trace ("sending songchanged\n");
- messagepump_push (M_SONGCHANGED, 0, from, to);
+ plug_trigger_event_trackchange (from, to);
bytes_until_next_song = -1;
// plugin will get pointer to str_playing_song
if (playing_track) {
@@ -795,9 +792,8 @@ streamer_thread (void *ctx) {
bytes_until_next_song = -1;
streamer_buffering = 1;
- int trk = str_get_idx_of (streaming_track);
- if (trk != -1) {
- messagepump_push (M_TRACKCHANGED, 0, trk, 0);
+ if (streaming_track) {
+ plug_trigger_event_trackinfochanged (streaming_track);
}
mutex_lock (decodemutex);
@@ -810,8 +806,8 @@ streamer_thread (void *ctx) {
mutex_unlock (decodemutex);
if (!dec || !info) {
- if (trk != -1) {
- messagepump_push (M_TRACKCHANGED, 0, trk, 0);
+ if (streaming_track) {
+ plug_trigger_event_trackinfochanged (streaming_track);
}
trace ("failed to restart prev track on seek, trying to jump to next track\n");
streamer_move_to_nextsong (0);
@@ -826,9 +822,8 @@ streamer_thread (void *ctx) {
bytes_until_next_song = -1;
streamer_buffering = 1;
- int trk = str_get_idx_of (streaming_track);
- if (trk != -1) {
- messagepump_push (M_TRACKCHANGED, 0, trk, 0);
+ if (streaming_track) {
+ plug_trigger_event_trackinfochanged (streaming_track);
}
if (fileinfo && playing_track && playing_track->_duration > 0) {
streamer_lock ();
@@ -883,10 +878,7 @@ streamer_thread (void *ctx) {
if ((streambuffer_fill > 128000 && streamer_buffering) || !streaming_track) {
streamer_buffering = 0;
if (streaming_track) {
- int trk = str_get_idx_of (streaming_track);
- if (trk != -1) {
- messagepump_push (M_TRACKCHANGED, 0, trk, 0);
- }
+ plug_trigger_event_trackinfochanged (streaming_track);
}
}
struct timeval tm2;