summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar waker <waker@xps.localdomain>2009-07-04 20:08:10 +0200
committerGravatar waker <waker@xps.localdomain>2009-07-04 20:08:10 +0200
commit033c0a7c702e709ba0ddac5406712c403dd0440b (patch)
treeb76d7981b088466295f9409246d33567637a6022
parent9107b42c99d6226c2f7dcfb63ba4a7d99036de26 (diff)
fixed mp3 playback
-rw-r--r--Jamfile2
-rw-r--r--callbacks.c202
-rw-r--r--callbacks.h5
-rw-r--r--cmp3.c25
-rw-r--r--deadbeef.glade1
-rw-r--r--interface.c3
-rw-r--r--psdl.c2
7 files changed, 140 insertions, 100 deletions
diff --git a/Jamfile b/Jamfile
index d4026852..005baef7 100644
--- a/Jamfile
+++ b/Jamfile
@@ -1,6 +1,8 @@
SubDir ROOT ;
CCFLAGS += -D_GNU_SOURCE ;
CCFLAGS += -std=c99 ;
+OPTIM += -O0 ;
+OPTIM += -g ;
HDRS += /usr/include/gtk-2.0 ;
HDRS += /usr/lib/gtk-2.0/include ;
diff --git a/callbacks.c b/callbacks.c
index 766887d7..244701fa 100644
--- a/callbacks.c
+++ b/callbacks.c
@@ -38,53 +38,12 @@ setup_ps_scrollbar (void) {
size = 0;
}
GtkWidget *scroll = lookup_widget (mainwin, "playscroll");
- printf ("%d\n", size);
// gtk_range_set_range (GTK_RANGE (scroll), 0, size);
// gtk_range_set_increments (GTK_RANGE (scroll), 1, h);
GtkAdjustment *adj = (GtkAdjustment*)gtk_adjustment_new (gtk_range_get_value (GTK_RANGE (scroll)), 0, size, 1, h, h);
gtk_range_set_adjustment (GTK_RANGE (scroll), adj);
}
-
-void
-on_playbtn_clicked (GtkButton *button,
- gpointer user_data)
-{
-
-}
-
-
-void
-on_volume_value_changed (GtkRange *range,
- gpointer user_data)
-{
- psdl_set_volume (gtk_range_get_value (range) / 100);
-}
-
-
-void
-on_playpos_value_changed (GtkRange *range,
- gpointer user_data)
-{
-
-}
-
-
-// change properties
-gboolean
-on_playlist_configure_event (GtkWidget *widget,
- GdkEventConfigure *event,
- gpointer user_data)
-{
- setup_ps_scrollbar ();
- if (backbuf) {
- g_object_unref (backbuf);
- }
- backbuf = gdk_pixmap_new (widget->window, widget->allocation.width, widget->allocation.height, -1);
-
- return FALSE;
-}
-
void
draw_ps_row_back (GdkDrawable *drawable, cairo_t *cr, int row) {
// draw background
@@ -95,12 +54,12 @@ draw_ps_row_back (GdkDrawable *drawable, cairo_t *cr, int row) {
gdk_drawable_get_size (drawable, &width, &height);
w = width;
if (row == playlist_row) {
+ cairo_set_source_rgb (cr, 0x7f/255.f, 0x7f/255.f, 0x7f/255.f);
+ cairo_rectangle (cr, 0, row * rowheight - trackerscroll * rowheight, width, rowheight);
+ cairo_fill (cr);
cairo_set_source_rgb (cr, 0xae/255.f, 0xa6/255.f, 0x9d/255.f);
cairo_rectangle (cr, 1, row * rowheight - trackerscroll * rowheight+1, width-2, rowheight-2);
cairo_fill (cr);
- cairo_set_source_rgb (cr, 0x7f/255.f, 0x7f/255.f, 0x7f/255.f);
- cairo_rectangle (cr, 0, row * rowheight - trackerscroll * rowheight, width, rowheight);
- cairo_stroke (cr);
}
else {
if (row % 2) {
@@ -133,6 +92,8 @@ text_draw (cairo_t *cr, int x, int y, const char *text) {
void
draw_ps_row (GdkDrawable *drawable, cairo_t *cr, int row, playItem_t *it) {
+ int width, height;
+ gdk_drawable_get_size (drawable, &width, &height);
if (row == playlist_row) {
cairo_set_source_rgb (cr, 0, 0, 0);
}
@@ -156,6 +117,7 @@ redraw_ps_row (GtkWidget *widget, int row) {
if (!cr) {
return;
}
+ //cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE);
// cairo_select_font_face (cr, "fixed", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
// cairo_set_font_size (cr, rowheight);
@@ -169,12 +131,14 @@ redraw_ps_row (GtkWidget *widget, int row) {
gdk_draw_drawable (widget->window, widget->style->black_gc, backbuf, x, y, x, y, w, h);
}
+
void draw_playlist (GtkWidget *widget, int x, int y, int w, int h) {
cairo_t *cr;
cr = gdk_cairo_create (backbuf);
if (!cr) {
return;
}
+ //cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE);
// cairo_select_font_face (cr, "fixed", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
// cairo_set_font_size (cr, rowheight);
@@ -196,10 +160,49 @@ void draw_playlist (GtkWidget *widget, int x, int y, int w, int h) {
}
cairo_destroy (cr);
- gdk_draw_drawable (widget->window, widget->style->black_gc, backbuf, x, y, x, y, w, h);
}
+void
+on_playbtn_clicked (GtkButton *button,
+ gpointer user_data)
+{
+
+}
+
+
+void
+on_volume_value_changed (GtkRange *range,
+ gpointer user_data)
+{
+ psdl_set_volume (gtk_range_get_value (range) / 100);
+}
+
+
+void
+on_playpos_value_changed (GtkRange *range,
+ gpointer user_data)
+{
+
+}
+
+
+// change properties
+gboolean
+on_playlist_configure_event (GtkWidget *widget,
+ GdkEventConfigure *event,
+ gpointer user_data)
+{
+ setup_ps_scrollbar ();
+ if (backbuf) {
+ g_object_unref (backbuf);
+ }
+ backbuf = gdk_pixmap_new (widget->window, widget->allocation.width, widget->allocation.height, -1);
+ draw_playlist (widget, 0, 0, widget->allocation.width, widget->allocation.height);
+
+ return FALSE;
+}
+
// redraw
gboolean
on_playlist_expose_event (GtkWidget *widget,
@@ -207,7 +210,7 @@ on_playlist_expose_event (GtkWidget *widget,
gpointer user_data)
{
// draw visible area of playlist
- draw_playlist (widget, event->area.x, event->area.y, event->area.width, event->area.height);
+ gdk_draw_drawable (widget->window, widget->style->black_gc, backbuf, event->area.x, event->area.y, event->area.x, event->area.y, event->area.width, event->area.height);
return FALSE;
}
@@ -226,44 +229,46 @@ on_playlist_button_press_event (GtkWidget *widget,
GdkEventButton *event,
gpointer user_data)
{
- // remember mouse coords for doubleclick detection
- ps_lastpos[0] = event->x;
- ps_lastpos[1] = event->y;
- // select item
- int y = event->y/rowheight + trackerscroll;
- if (y < 0 || y >= ps_getcount ()) {
- y = -1;
- }
-
- if (playlist_row != y) {
- int old = playlist_row;
- playlist_row = y;
- if (old != -1) {
- redraw_ps_row (widget, old);
- }
- if (playlist_row != -1) {
- redraw_ps_row (widget, playlist_row);
+ if (event->button == 1) {
+ // remember mouse coords for doubleclick detection
+ ps_lastpos[0] = event->x;
+ ps_lastpos[1] = event->y;
+ // select item
+ int y = event->y/rowheight + trackerscroll;
+ if (y < 0 || y >= ps_getcount ()) {
+ y = -1;
}
- }
- if (event->time - playlist_clicktime < 0.5
- && fabs(ps_lastpos[0] - event->x) < 3
- && fabs(ps_lastpos[1] - event->y) < 3) {
- // doubleclick - play this item
- if (playlist_row != -1) {
- playItem_t *it = ps_get_for_idx (playlist_row);
- if (it) {
- psdl_stop ();
- psdl_play (it);
+ if (playlist_row != y) {
+ int old = playlist_row;
+ playlist_row = y;
+ if (old != -1) {
+ redraw_ps_row (widget, old);
+ }
+ if (playlist_row != -1) {
+ redraw_ps_row (widget, playlist_row);
}
}
+ if (event->time - playlist_clicktime < 0.5
+ && fabs(ps_lastpos[0] - event->x) < 3
+ && fabs(ps_lastpos[1] - event->y) < 3) {
+ // doubleclick - play this item
+ if (playlist_row != -1) {
+ playItem_t *it = ps_get_for_idx (playlist_row);
+ if (it) {
+ psdl_stop ();
+ psdl_play (it);
+ }
+ }
- // prevent next click to trigger doubleclick
- playlist_clicktime = event->time-1;
- }
- else {
- playlist_clicktime = event->time;
+
+ // prevent next click to trigger doubleclick
+ playlist_clicktime = event->time-1;
+ }
+ else {
+ playlist_clicktime = event->time;
+ }
}
return FALSE;
}
@@ -273,9 +278,13 @@ void
on_playscroll_value_changed (GtkRange *range,
gpointer user_data)
{
- trackerscroll = gtk_range_get_value (GTK_RANGE (range));
- GtkWidget *playlist = lookup_widget (mainwin, "playlist");
- draw_playlist (playlist, 0, 0, playlist->allocation.width, playlist->allocation.height);
+ int newscroll = gtk_range_get_value (GTK_RANGE (range));
+ if (newscroll != trackerscroll) {
+ trackerscroll = newscroll;
+ GtkWidget *widget = lookup_widget (mainwin, "playlist");
+ draw_playlist (widget, 0, 0, widget->allocation.width, widget->allocation.height);
+ gdk_draw_drawable (widget->window, widget->style->black_gc, backbuf, 0, 0, 0, 0, widget->allocation.width, widget->allocation.height);
+ }
}
@@ -315,8 +324,9 @@ on_add_files_activate (GtkMenuItem *menuitem,
}
gtk_widget_destroy (dlg);
setup_ps_scrollbar ();
- GtkWidget *playlist = lookup_widget (mainwin, "playlist");
- draw_playlist (playlist, 0, 0, playlist->allocation.width, playlist->allocation.height);
+ GtkWidget *widget = lookup_widget (mainwin, "playlist");
+ draw_playlist (widget, 0, 0, widget->allocation.width, widget->allocation.height);
+ gdk_draw_drawable (widget->window, widget->style->black_gc, backbuf, 0, 0, 0, 0, widget->allocation.width, widget->allocation.height);
}
@@ -337,8 +347,9 @@ on_add_folder1_activate (GtkMenuItem *menuitem,
}
gtk_widget_destroy (dlg);
setup_ps_scrollbar ();
- GtkWidget *playlist = lookup_widget (mainwin, "playlist");
- draw_playlist (playlist, 0, 0, playlist->allocation.width, playlist->allocation.height);
+ GtkWidget *widget = lookup_widget (mainwin, "playlist");
+ draw_playlist (widget, 0, 0, widget->allocation.width, widget->allocation.height);
+ gdk_draw_drawable (widget->window, widget->style->black_gc, backbuf, 0, 0, 0, 0, widget->allocation.width, widget->allocation.height);
}
@@ -397,3 +408,24 @@ on_about1_activate (GtkMenuItem *menuitem,
}
+
+gboolean
+on_playlist_scroll_event (GtkWidget *widget,
+ GdkEvent *event,
+ gpointer user_data)
+{
+ // pass event to scrollbar
+ GtkWidget *range = lookup_widget (mainwin, "playscroll");
+ GdkEventScroll *ev = (GdkEventScroll*)event;
+ GtkAdjustment* adj = gtk_range_get_adjustment (GTK_RANGE (range));
+ int newscroll = gtk_range_get_value (GTK_RANGE (range));
+ if (ev->direction == GDK_SCROLL_UP) {
+ newscroll -= gtk_adjustment_get_page_increment (adj);
+ }
+ else if (ev->direction == GDK_SCROLL_DOWN) {
+ newscroll += gtk_adjustment_get_page_increment (adj);
+ }
+ gtk_range_set_value (GTK_RANGE (range), newscroll);
+ return FALSE;
+}
+
diff --git a/callbacks.h b/callbacks.h
index d1e51964..4f9e6ee1 100644
--- a/callbacks.h
+++ b/callbacks.h
@@ -79,3 +79,8 @@ on_crop1_activate (GtkMenuItem *menuitem,
void
on_about1_activate (GtkMenuItem *menuitem,
gpointer user_data);
+
+gboolean
+on_playlist_scroll_event (GtkWidget *widget,
+ GdkEvent *event,
+ gpointer user_data);
diff --git a/cmp3.c b/cmp3.c
index 359f9eb3..f8b1b966 100644
--- a/cmp3.c
+++ b/cmp3.c
@@ -5,8 +5,6 @@
#include "codec.h"
#include "cmp3.h"
-FILE *outf;
-
#define min(x,y) ((x)<(y)?(x):(y))
#define max(x,y) ((x)>(y)?(x):(y))
@@ -36,6 +34,8 @@ static mad_timer_t timer;
static int frame_count;
unsigned char *GuardPtr = NULL;
+static void cmp3_decode (void);
+
int
cmp3_init (const char *fname) {
buffer.file = fopen (fname, "rb");
@@ -58,7 +58,7 @@ cmp3_init (const char *fname) {
mad_synth_init(&synth);
mad_timer_reset(&timer);
- outf = fopen ("out.raw", "w+b");
+ cmp3_decode ();
return 0;
}
@@ -102,7 +102,7 @@ static signed short MadFixedToSshort(mad_fixed_t Fixed)
#define MadErrorString(x) mad_stream_errorstr(x)
-void
+static void
cmp3_decode (void) {
for (;;) {
// read more MPEG data if needed
@@ -136,9 +136,9 @@ cmp3_decode (void) {
if(stream.error!=MAD_ERROR_LOSTSYNC ||
stream.this_frame!=GuardPtr)
{
- fprintf(stderr,"recoverable frame level error (%s)\n",
- MadErrorString(&stream));
- fflush(stderr);
+// fprintf(stderr,"recoverable frame level error (%s)\n",
+// MadErrorString(&stream));
+// fflush(stderr);
}
continue;
}
@@ -147,8 +147,8 @@ cmp3_decode (void) {
continue;
else
{
- fprintf(stderr,"unrecoverable frame level error (%s).\n",
- MadErrorString(&stream));
+// fprintf(stderr,"unrecoverable frame level error (%s).\n",
+// MadErrorString(&stream));
break;
}
}
@@ -160,7 +160,8 @@ cmp3_decode (void) {
cmp3.info.dataSize = -1;
cmp3.info.channels = MAD_NCHANNELS(&frame.header);
cmp3.info.samplesPerSecond = frame.header.samplerate;
-// break;
+ frame_count++;
+ break;
}
frame_count++;
@@ -215,10 +216,6 @@ cmp3_free (void) {
mad_frame_finish (&frame);
mad_stream_finish (&stream);
}
- if (outf) {
- fclose (outf);
- outf = NULL;
- }
}
int
diff --git a/deadbeef.glade b/deadbeef.glade
index b7d8b5dd..79c2e166 100644
--- a/deadbeef.glade
+++ b/deadbeef.glade
@@ -525,6 +525,7 @@
<signal name="expose_event" handler="on_playlist_expose_event" last_modification_time="Sat, 04 Jul 2009 00:03:29 GMT"/>
<signal name="realize" handler="on_playlist_realize" last_modification_time="Sat, 04 Jul 2009 00:03:36 GMT"/>
<signal name="button_press_event" handler="on_playlist_button_press_event" last_modification_time="Sat, 04 Jul 2009 00:41:38 GMT"/>
+ <signal name="scroll_event" handler="on_playlist_scroll_event" last_modification_time="Sat, 04 Jul 2009 17:16:21 GMT"/>
</widget>
<packing>
<property name="padding">0</property>
diff --git a/interface.c b/interface.c
index b86a8825..1e853ac0 100644
--- a/interface.c
+++ b/interface.c
@@ -353,6 +353,9 @@ create_mainwin (void)
g_signal_connect ((gpointer) playlist, "button_press_event",
G_CALLBACK (on_playlist_button_press_event),
NULL);
+ g_signal_connect ((gpointer) playlist, "scroll_event",
+ G_CALLBACK (on_playlist_scroll_event),
+ NULL);
g_signal_connect ((gpointer) playscroll, "value_changed",
G_CALLBACK (on_playscroll_value_changed),
NULL);
diff --git a/psdl.c b/psdl.c
index 1e822022..386dee5c 100644
--- a/psdl.c
+++ b/psdl.c
@@ -76,7 +76,7 @@ psdl_free (void) {
int
psdl_play (struct playItem_s *it) {
- printf ("psdl_play\n");
+// printf ("psdl_play\n");
if (!it) {
return -1;
}