summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Alexey Yakovenko <wakeroid@gmail.com>2009-11-12 21:09:26 +0100
committerGravatar Alexey Yakovenko <wakeroid@gmail.com>2009-11-12 21:09:26 +0100
commit45fd185e734b0755a843017f891b178133ae43ea (patch)
tree0b3a704daa98c06a477a5ee682f551f7018d6b12
parentebabdc99d7bcab39b80f8ac3938a477c3190fa27 (diff)
gtkui WIP
-rw-r--r--deadbeef.h9
-rw-r--r--playlist.c5
-rw-r--r--playlist.h3
-rw-r--r--plugins.c9
-rw-r--r--plugins/gtkui/Makefile.am33
-rw-r--r--plugins/gtkui/gtkplaylist.c2
-rw-r--r--plugins/gtkui/gtkplaylist.h22
-rw-r--r--plugins/gtkui/gtkui.c49
-rw-r--r--streamer.c5
-rw-r--r--streamer.h3
10 files changed, 96 insertions, 44 deletions
diff --git a/deadbeef.h b/deadbeef.h
index dfdcb9cf..34becc72 100644
--- a/deadbeef.h
+++ b/deadbeef.h
@@ -212,6 +212,14 @@ typedef struct {
void (*playback_set_pos) (float pos); // [0..100]
int (*playback_get_samplerate) (void); // output samplerate
void (*playback_update_bitrate) (float bitrate);
+ // playback status
+ int (*playback_isstopped) (void);
+ int (*playback_ispaused) (void);
+ // streamer access
+ // FIXME: needs to be thread-safe
+ DB_playItem_t *(*streamer_get_playing_track) (void);
+ DB_playItem_t *(*streamer_get_streaming_track) (void);
+ float (*streamer_get_playpos) (void);
// process control
const char *(*get_config_dir) (void);
void (*quit) (void);
@@ -233,6 +241,7 @@ typedef struct {
void (*pl_item_copy) (DB_playItem_t *out, DB_playItem_t *in);
DB_playItem_t *(*pl_insert_item) (DB_playItem_t *after, DB_playItem_t *it);
int (*pl_get_idx_of) (DB_playItem_t *it);
+ float (*pl_get_totaltime) (void);
// metainfo
void (*pl_add_meta) (DB_playItem_t *it, const char *key, const char *value);
const char *(*pl_find_meta) (DB_playItem_t *song, const char *meta);
diff --git a/playlist.c b/playlist.c
index 5e90f422..20a58bcc 100644
--- a/playlist.c
+++ b/playlist.c
@@ -1650,3 +1650,8 @@ pl_reset_cursor (void) {
playlist_current_row[i] = -1;
}
}
+
+float
+pl_get_totaltime (void) {
+ return pl_totaltime;
+}
diff --git a/playlist.h b/playlist.h
index 40a7c44a..70ed8ac5 100644
--- a/playlist.h
+++ b/playlist.h
@@ -173,4 +173,7 @@ pl_format_title (playItem_t *it, char *s, int size, const char *fmt);
void
pl_reset_cursor (void);
+float
+pl_get_totaltime (void);
+
#endif // __PLAYLIST_H
diff --git a/plugins.c b/plugins.c
index 4630abfb..5ceecd39 100644
--- a/plugins.c
+++ b/plugins.c
@@ -61,6 +61,14 @@ static DB_functions_t deadbeef_api = {
.playback_set_pos = plug_playback_set_pos,
.playback_get_samplerate = p_get_rate,
.playback_update_bitrate = streamer_update_bitrate,
+ // playback status
+ .playback_isstopped = p_isstopped,
+ .playback_ispaused = p_ispaused,
+ // streamer access
+ .streamer_get_playing_track = streamer_get_playing_track,
+ .streamer_get_streaming_track = streamer_get_streaming_track,
+ .streamer_get_playpos = streamer_get_playpos,
+ // process control
.get_config_dir = plug_get_config_dir,
.quit = plug_quit,
// threading
@@ -83,6 +91,7 @@ static DB_functions_t deadbeef_api = {
.pl_get_idx_of = (int (*) (DB_playItem_t *it))pl_get_idx_of,
.pl_set_item_duration = (void (*) (DB_playItem_t *it, float duration))pl_set_item_duration,
.pl_get_item_duration = (float (*) (DB_playItem_t *it))pl_get_item_duration,
+ .pl_get_totaltime = pl_get_totaltime,
// metainfo
.pl_add_meta = (void (*) (DB_playItem_t *, const char *, const char *))pl_add_meta,
.pl_find_meta = (const char *(*) (DB_playItem_t *, const char *))pl_find_meta,
diff --git a/plugins/gtkui/Makefile.am b/plugins/gtkui/Makefile.am
index 9eba3da8..606c01cb 100644
--- a/plugins/gtkui/Makefile.am
+++ b/plugins/gtkui/Makefile.am
@@ -1,17 +1,16 @@
-#if HAVE_GTK
-#gtkuidir = $(libdir)/$(PACKAGE)
-#pkglib_LTLIBRARIES = gtkui.la
-#gtkui_la_SOURCES = gtkui.c\
-# callbacks.c interface.c support.c callbacks.h interface.h support.h\
-# gtkplaylist.c gtkplaylist.h\
-# drawing.h gdkdrawing.c\
-# progress.c progress.h\
-# search.c search.h\
-# gtksession.c
-#
-#
-#gtkui_la_LDFLAGS = -module
-#
-#gtkui_la_LIBADD = $(LDADD) $(GTKUI_DEPS_LIBS)
-#AM_CFLAGS = -std=c99 $(GTKUI_DEPS_CFLAGS)
-#endif
+if HAVE_GTK
+gtkuidir = $(libdir)/$(PACKAGE)
+pkglib_LTLIBRARIES = gtkui.la
+gtkui_la_SOURCES = gtkui.c\
+ callbacks.c interface.c support.c callbacks.h interface.h support.h\
+ gtkplaylist.c gtkplaylist.h\
+ drawing.h gdkdrawing.c\
+ progress.c progress.h\
+ search.c search.h\
+ gtksession.c
+
+gtkui_la_LDFLAGS = -module
+
+gtkui_la_LIBADD = $(LDADD) $(GTKUI_DEPS_LIBS)
+AM_CFLAGS = -std=c99 $(GTKUI_DEPS_CFLAGS)
+endif
diff --git a/plugins/gtkui/gtkplaylist.c b/plugins/gtkui/gtkplaylist.c
index 62cfe610..266fe2c5 100644
--- a/plugins/gtkui/gtkplaylist.c
+++ b/plugins/gtkui/gtkplaylist.c
@@ -290,7 +290,7 @@ gtkpl_redraw_pl_row_novis (gtkplaylist_t *ps, int row, playItem_t *it) {
}
void
-gtkpl_redraw_pl_row (gtkplaylist_t *ps, int row, playItem_t *it) {
+gtkpl_redraw_pl_row (gtkplaylist_t *ps, int row, DB_playItem_t *it) {
int x, y, w, h;
GtkWidget *widget = ps->playlist;
x = 0;
diff --git a/plugins/gtkui/gtkplaylist.h b/plugins/gtkui/gtkplaylist.h
index 477afa60..5547fa54 100644
--- a/plugins/gtkui/gtkplaylist.h
+++ b/plugins/gtkui/gtkplaylist.h
@@ -21,7 +21,7 @@
#include <gtk/gtk.h>
#include <stdint.h>
#include <assert.h>
-#include "playlist.h"
+#include "../../deadbeef.h"
// drag and drop targets
enum {
@@ -73,9 +73,9 @@ typedef struct {
GdkPixmap *backbuf_header;
const char *title; // unique id, used for config writing, etc
// parameters
- playItem_t **pcurr; // pointer to current item
+ DB_playItem_t **pcurr; // pointer to current item
int *pcount; // pointer to count of items in list
- int iterator; // index into next array of playItem_t struct
+ int iterator; // index into next array of DB_playItem_t struct
int lastpos[2]; // last mouse position (for playlist widget)
int multisel; // if it uses multiple selection
// current state
@@ -102,19 +102,19 @@ void
gtkpl_free (gtkplaylist_t *pl);
void
-gtkpl_redraw_pl_row (gtkplaylist_t *ps, int row, playItem_t *it);
+gtkpl_redraw_pl_row (gtkplaylist_t *ps, int row, DB_playItem_t *it);
void
-gtkpl_redraw_pl_row_novis (gtkplaylist_t *ps, int row, playItem_t *it);
+gtkpl_redraw_pl_row_novis (gtkplaylist_t *ps, int row, DB_playItem_t *it);
void
gtkpl_setup_scrollbar (gtkplaylist_t *ps);
void
-gtkpl_draw_pl_row_back (gtkplaylist_t *ps, int row, playItem_t *it);
+gtkpl_draw_pl_row_back (gtkplaylist_t *ps, int row, DB_playItem_t *it);
void
-gtkpl_draw_pl_row (gtkplaylist_t *ps, int row, playItem_t *it);
+gtkpl_draw_pl_row (gtkplaylist_t *ps, int row, DB_playItem_t *it);
void
gtkpl_draw_playlist (gtkplaylist_t *ps, int x, int y, int w, int h);
@@ -165,7 +165,7 @@ void
gtkpl_header_draw (gtkplaylist_t *ps);
void
-gtkpl_add_dir (gtkplaylist_t *ps, char *folder);
+gtkpl_add_dir (gtkplaylist_t *ps, const char *folder);
void
gtkpl_add_dirs (gtkplaylist_t *ps, GSList *lst);
@@ -177,9 +177,9 @@ void
gtkpl_configure (gtkplaylist_t *ps);
int
-gtkpl_get_idx_of (gtkplaylist_t *ps, playItem_t *it);
+gtkpl_get_idx_of (gtkplaylist_t *ps, DB_playItem_t *it);
-playItem_t *
+DB_playItem_t *
gtkpl_get_for_idx (gtkplaylist_t *ps, int idx);
// this functions take value from passed playlist, that's why it's here
@@ -255,6 +255,6 @@ void
gtkpl_songchanged_wrapper (int from, int to);
void
-gtkpl_current_track_changed (playItem_t *it);
+gtkpl_current_track_changed (DB_playItem_t *it);
#endif // __GTKPLAYLIST_H
diff --git a/plugins/gtkui/gtkui.c b/plugins/gtkui/gtkui.c
index ab849882..eac8bdc9 100644
--- a/plugins/gtkui/gtkui.c
+++ b/plugins/gtkui/gtkui.c
@@ -18,6 +18,7 @@
*/
#include "../../deadbeef.h"
#include <gtk/gtk.h>
+#include <string.h>
#include "gtkplaylist.h"
#include "search.h"
#include "progress.h"
@@ -25,6 +26,12 @@
#include "callbacks.h"
#include "support.h"
+#define trace(...) { fprintf(stderr, __VA_ARGS__); }
+//#define trace(fmt,...)
+
+static DB_gui_t plugin;
+static DB_functions_t *deadbeef;
+
// main widgets
GtkWidget *mainwin;
GtkWidget *searchwin;
@@ -45,6 +52,7 @@ update_songinfo (void) {
char sbtext_new[512] = "-";
float songpos = last_songpos;
+ float pl_totaltime = deadbeef->pl_get_totaltime ();
int daystotal = (int)pl_totaltime / (3600*24);
int hourtotal = ((int)pl_totaltime / 3600) % 24;
int mintotal = ((int)pl_totaltime/60) % 60;
@@ -60,18 +68,23 @@ update_songinfo (void) {
else
snprintf (totaltime_str, sizeof (totaltime_str), "%d days %d:%02d:%02d", daystotal, hourtotal, mintotal, sectotal);
- if (p_isstopped ()) {
+
+
+ DB_playItem_t *track = deadbeef->streamer_get_playing_track ();
+ float duration = deadbeef->pl_get_item_duration (track);
+
+ if (deadbeef->playback_isstopped ()) {
snprintf (sbtext_new, sizeof (sbtext_new), "Stopped | %s total playtime", totaltime_str);
songpos = 0;
}
- else if (str_playing_song.decoder) {
+ else if (track->decoder) {
// codec_lock ();
- DB_decoder_t *c = str_playing_song.decoder;
- float playpos = streamer_get_playpos ();
+ DB_decoder_t *c = track->decoder;
+ float playpos = deadbeef->streamer_get_playpos ();
int minpos = playpos / 60;
int secpos = playpos - minpos * 60;
- int mindur = str_playing_song._duration / 60;
- int secdur = str_playing_song._duration - mindur * 60;
+ int mindur = duration / 60;
+ int secdur = duration - mindur * 60;
const char *mode = c->info.channels == 1 ? "Mono" : "Stereo";
int samplerate = c->info.samplerate;
@@ -80,7 +93,7 @@ update_songinfo (void) {
// codec_unlock ();
char t[100];
- if (str_playing_song._duration >= 0) {
+ if (duration >= 0) {
snprintf (t, sizeof (t), "%d:%02d", mindur, secdur);
}
else {
@@ -94,8 +107,8 @@ update_songinfo (void) {
snprintf (sbitrate, sizeof (sbitrate), "%d kbps ", bitrate);
}
#endif
- const char *spaused = p_ispaused () ? "Paused | " : "";
- snprintf (sbtext_new, sizeof (sbtext_new), "%s%s %s| %dHz | %d bit | %s | %d:%02d / %s | %d songs | %s total playtime", spaused, str_playing_song.filetype ? str_playing_song.filetype:"-", sbitrate, samplerate, bitspersample, mode, minpos, secpos, t, pl_getcount (), totaltime_str);
+ const char *spaused = deadbeef->playback_ispaused () ? "Paused | " : "";
+ snprintf (sbtext_new, sizeof (sbtext_new), "%s%s %s| %dHz | %d bit | %s | %d:%02d / %s | %d songs | %s total playtime", spaused, track->filetype ? track->filetype:"-", sbitrate, samplerate, bitspersample, mode, minpos, secpos, t, pl_getcount (), totaltime_str);
}
if (strcmp (sbtext_new, sb_text)) {
@@ -121,7 +134,7 @@ update_songinfo (void) {
if (mainwin) {
GtkWidget *widget = lookup_widget (mainwin, "seekbar");
// translate volume to seekbar pixels
- songpos /= str_playing_song._duration;
+ songpos /= duration;
songpos *= widget->allocation.width;
if ((int)(songpos*2) != (int)(last_songpos*2)) {
GDK_THREADS_ENTER();
@@ -139,7 +152,7 @@ on_trayicon_scroll_event (GtkWidget *widget,
GdkEventScroll *event,
gpointer user_data)
{
- float vol = volume_get_db ();
+ float vol = deadbeef->volume_get_db ();
if (event->direction == GDK_SCROLL_UP || event->direction == GDK_SCROLL_RIGHT) {
vol += 1;
}
@@ -152,7 +165,7 @@ on_trayicon_scroll_event (GtkWidget *widget,
else if (vol < -60) {
vol = -60;
}
- volume_set_db (vol);
+ deadbeef->volume_set_db (vol);
GtkWidget *volumebar = lookup_widget (mainwin, "volumebar");
volumebar_draw (volumebar);
volumebar_expose (volumebar, 0, 0, volumebar->allocation.width, volumebar->allocation.height);
@@ -286,7 +299,7 @@ guiplug_refresh_playlist (void) {
void
guiplug_add_fm_dropped_files (char *files, int p1, int p2) {
- gtkpl_add_fm_dropped_files (&main_playlist, (char *)ctx, p1, p2);
+ gtkpl_add_fm_dropped_files (&main_playlist, files, p1, p2);
}
static int
@@ -298,8 +311,8 @@ gtkui_on_activate (DB_event_t *ev, uintptr_t data) {
}
static int
-gtkui_on_songchanged (DB_event_songchange_t *ev, uintptr_t data) {
- gtkpl_songchanged_wrapper (from, to);
+gtkui_on_songchanged (DB_event_trackchange_t *ev, uintptr_t data) {
+ gtkpl_songchanged_wrapper (ev->from, ev->to);
}
static int
@@ -420,6 +433,12 @@ gtkui_stop (void) {
return 0;
}
+DB_plugin_t *
+gtkui_load (DB_functions_t *api) {
+ deadbeef = api;
+ return DB_PLUGIN (&plugin);
+}
+
// define plugin interface
static DB_gui_t plugin = {
DB_PLUGIN_SET_API_VERSION
diff --git a/streamer.c b/streamer.c
index e5ff4289..c419460d 100644
--- a/streamer.c
+++ b/streamer.c
@@ -98,6 +98,11 @@ streamer_get_streaming_track (void) {
return orig_streaming_song;
}
+playItem_t *
+streamer_get_playing_track (void) {
+ return &str_playing_song;
+}
+
// playlist must call that whenever item was removed
void
streamer_song_removed_notify (playItem_t *it) {
diff --git a/streamer.h b/streamer.h
index 9e686d79..2a74d190 100644
--- a/streamer.h
+++ b/streamer.h
@@ -75,6 +75,9 @@ streamer_song_removed_notify (playItem_t *it);
playItem_t *
streamer_get_streaming_track (void);
+playItem_t *
+streamer_get_playing_track (void);
+
void
streamer_configchanged (void);