summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile7
-rw-r--r--gbeat.c101
-rw-r--r--gbeat.glade7
3 files changed, 68 insertions, 47 deletions
diff --git a/Makefile b/Makefile
index 8a4edfd..926c883 100644
--- a/Makefile
+++ b/Makefile
@@ -1,8 +1,8 @@
-love: gbeat
+love: gbeat gbeat.xml
.PHONY: love clean
CC=gcc
-PKGS=glib-2.0 gtk+-2.0 libglade-2.0 gthread-2.0 fftw3 alsa
+PKGS=glib-2.0 gtk+-3.0 gladeui-2.0 gthread-2.0 fftw3 alsa cairo
CFLAGS=-std=gnu99 -Wall -Wextra -pedantic -Wno-unused-parameter -g -O0 \
`pkg-config --cflags $(PKGS)`
LDFLAGS=-g -lm `pkg-config --libs $(PKGS)` -rdynamic
@@ -10,6 +10,9 @@ LDFLAGS=-g -lm `pkg-config --libs $(PKGS)` -rdynamic
clean:
rm -f *.o gbeat
+gbeat.xml: gbeat.glade
+ gtk-builder-convert $^ $@
+
gbeat: galsa.o gfft.o gbeat.o
$(CC) $(LDFLAGS) -o $@ $^
diff --git a/gbeat.c b/gbeat.c
index 8fedf2c..1cce8c4 100644
--- a/gbeat.c
+++ b/gbeat.c
@@ -1,5 +1,5 @@
#include <gtk/gtk.h>
-#include <glade/glade.h>
+#include <gladeui/glade.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
@@ -9,21 +9,31 @@
#include "galsa.h"
#include "gfft.h"
-#define gladewidget(x) GtkWidget *x = glade_xml_get_widget(xml, #x);
-GladeXML *xml;
+GtkBuilder *builder;
+#define gladewidget(x) GtkWidget *x = \
+ GTK_WIDGET(gtk_builder_get_object(builder, #x));
-static GdkPixmap *pxm;
-//static GdkImage *img_buffer;
-//static GdkPixbuf *pxb;
-double ofac_s = 110./64000.; // 1./(perpixel);
+static cairo_surface_t *cs_scroll;
+static cairo_t *c_scroll;
+
+gboolean on_draw(GtkWidget *drawer, cairo_t *cr, gpointer data)
+{
+ cairo_rectangle(cr, 0, 0, 300, 400);
+ cairo_set_source_surface(cr, cs_scroll, 0, 0);
+ cairo_fill(cr);
+
+ return FALSE;
+}
static gboolean bother(gpointer param)
{
- gladewidget(img)
+ gladewidget(drawer)
gladewidget(status)
char buf[256];
- gtk_widget_queue_draw(img);
- snprintf(buf, sizeof(buf), "scaling: %lf", ofac_s);
+
+ gtk_widget_queue_draw(drawer);
+
+ snprintf(buf, sizeof(buf), "blah");
gtk_label_set_text(GTK_LABEL(status), buf);
return FALSE;
}
@@ -191,23 +201,15 @@ static gpointer renderf(gpointer param)
{
struct renderargs *arg = param;
struct fe *fe;
+ double c = 0.0;
size_t logsz = 400;
fftw_complex *pos, *logsc;
- GdkDrawable *drawto = GDK_DRAWABLE(pxm);
- GdkGC *gc = gdk_gc_new(drawto);
-
- gint w, h, y;
+ gint w = 300, h = 400, y;
GdkColor col;
logsc = fftw_malloc(sizeof(fftw_complex) * logsz);
-
- gdk_drawable_get_size(drawto, &w, &h);
-#if 0
- if (h > (gint)arg->fftr->dev->pktsize)
- h = arg->fftr->dev->pktsize;
-#endif
if (h > (gint)logsz)
h = logsz;
@@ -233,8 +235,9 @@ static gpointer renderf(gpointer param)
fclose(f);
}
- gdk_threads_enter();
- gdk_draw_drawable(drawto, gc, drawto, 1, 0, 0, 0, w - 1, h);
+ cairo_rectangle(c_scroll, 0, 0, 300, 400);
+ cairo_set_source_surface(c_scroll, cs_scroll, -1, 0);
+ cairo_fill(c_scroll);
pos = logsc; // fe->data;
for (y = h - 1; y >= 0; y--) {
@@ -260,10 +263,22 @@ static gpointer renderf(gpointer param)
arg->bdctx.beats[(pos - logsc) / (logsz / EVALBANDS)] ?
(beat ? 65535 : 32768) : 0;
- gdk_gc_set_rgb_fg_color(gc, &col);
- gdk_draw_point(drawto, gc, w - 1, y);
+ cairo_rectangle(c_scroll, w - 2, y, 1, 1);
+ cairo_set_source_rgb(c_scroll,
+ col.red / 65535.,
+ col.green / 65535.,
+ col.blue / 65535.);
+ cairo_fill(c_scroll);
}
- gdk_threads_leave();
+
+ cairo_rectangle(c_scroll, 5, 5, 5, 5);
+ cairo_set_source_rgb(c_scroll, 0.0, 0.0, c);
+ cairo_fill(c_scroll);
+ c += 0.05;
+ if (c > 1.0)
+ c = 0.0;
+
+ cairo_surface_flush(cs_scroll);
g_idle_add(bother, NULL);
fftw_free(fe->data);
@@ -368,21 +383,27 @@ int main(int argc, char **argv)
g_thread_init(NULL);
gtk_init(&argc, &argv);
gdk_threads_init();
- xml = glade_xml_new("gbeat.glade", NULL, NULL);
- glade_xml_signal_autoconnect(xml);
- {
- gladewidget(edev)
- gladewidget(erate)
- gladewidget(img)
- gtk_entry_set_text(GTK_ENTRY(edev), "hw:0,0");
- gtk_entry_set_text(GTK_ENTRY(erate), "48000");
- //pxb = gdk_pixbuf_new(GDK_COLORSPACE_RGB, 0, 8, 300, 720);
- //gtk_image_set_from_pixbuf(GTK_IMAGE(img), pxb);
- //img_buffer = gdk_image_new(GDK_IMAGE_FASTEST, gdk_visual_get_system(), 300, 740);
- //gtk_image_set_from_image(GTK_IMAGE(img), img_buffer, NULL);
- pxm = gdk_pixmap_new(NULL, 300, 400, 24);
- gtk_image_set_from_pixmap(GTK_IMAGE(img), pxm, NULL);
- }
+ builder = gtk_builder_new();
+ gtk_builder_add_from_file(builder, "gbeat.xml", NULL);
+ gtk_builder_connect_signals(builder, NULL);
+
+ gladewidget(edev)
+ gtk_entry_set_text(GTK_ENTRY(edev), "hw:0,0");
+ gladewidget(erate)
+ gtk_entry_set_text(GTK_ENTRY(erate), "48000");
+ gladewidget(drawer);
+ gtk_widget_set_size_request(drawer, 300, 400);
+
+ cs_scroll = cairo_image_surface_create(CAIRO_FORMAT_RGB24, 300, 400);
+ c_scroll = cairo_create(cs_scroll);
+ cairo_rectangle(c_scroll, 0, 0, 300, 400);
+ cairo_set_source_rgb(c_scroll, 0.0, 0.0, 0.0);
+ cairo_fill(c_scroll);
+
+ cairo_rectangle(c_scroll, 5, 5, 5, 5);
+ cairo_set_source_rgb(c_scroll, 0.0, 0.0, 1.0);
+ cairo_fill(c_scroll);
+
on_bdapply(NULL, NULL);
gtk_main ();
return 0;
diff --git a/gbeat.glade b/gbeat.glade
index c43794b..f2f1ba3 100644
--- a/gbeat.glade
+++ b/gbeat.glade
@@ -333,12 +333,9 @@
</child>
<child>
- <widget class="GtkImage" id="img">
+ <widget class="GtkDrawingArea" id="drawer">
<property name="visible">True</property>
- <property name="xalign">0.5</property>
- <property name="yalign">0.5</property>
- <property name="xpad">0</property>
- <property name="ypad">0</property>
+ <signal name="draw" handler="on_draw" last_modification_time="Mon, 04 Dec 2006 16:49:00 GMT"/>
</widget>
<packing>
<property name="padding">0</property>