diff -u globals.h globals.h.patched --- globals.h 2003-07-02 09:20:18.000000000 +0200 +++ globals.h.patched 2003-08-20 20:04:58.000000000 +0200 @@ -28,6 +28,9 @@ #define TITLE "GTick" +#define MAX_FREQ 251.0 +#define MIN_FREQ 30.0 + /* GNU gettext introduction */ #include #include "gettext.h" diff -u gtick.c gtick.c.patched --- gtick.c 2003-07-27 10:25:58.000000000 +0200 +++ gtick.c.patched 2003-08-20 23:13:44.000000000 +0200 @@ -28,9 +28,12 @@ #include #include #include +#include +#include /* GTK+ headers */ #include +#include /* own headers */ #include "../config.h" @@ -45,6 +48,12 @@ #include "icon48x48.xpm" #include "icon64x64.xpm" +/* hit timing stuff */ +#define TIMING_KEY GDK_Shift_L + +static struct timeval last_time; +static int catching = 0; + metro_t* metro; int debug; @@ -141,6 +150,67 @@ g_print("new meter: %d\n", metro->meter); } +/* + * Key hit timing. The time between first and second TIMING_KEY hit + * gets set as the metro period. + */ +void keypress_handler (GtkWidget *widget, GdkEventKey *event) { + + gchar *message[100]; + struct timeval current_time; + long delta_usec; + + if (event->keyval != TIMING_KEY) { + return; + } + + if (gettimeofday(¤t_time, NULL) != 0) { + printf("hit timing: gettimeofday() failed, errno %d\n", errno); + } + + guint context_id = gtk_statusbar_get_context_id(GTK_STATUSBAR (metro->statusbar), "hit timing text"); + + if (! catching) { + last_time.tv_sec = current_time.tv_sec; + last_time.tv_usec = current_time.tv_usec; + gtk_statusbar_push(GTK_STATUSBAR (metro->statusbar), context_id, _("Hit timing: waiting for second keypress.")); + if (metro->ticking) { gtOnOff(widget, metro); } + catching = 1; + return; + } + + long delta_sec = current_time.tv_sec - last_time.tv_sec; + + if (current_time.tv_usec > last_time.tv_usec) { + delta_usec = current_time.tv_usec - last_time.tv_usec; + } else { + delta_usec = 1000000 - last_time.tv_usec + current_time.tv_usec; + delta_sec--; + } + + long delta_total = (delta_sec*1000000 + delta_usec) / 1000; + long period = (1000 / (float) delta_total) * 60; + + if ((period > MAX_FREQ) || (period < MIN_FREQ)) { + snprintf((char *) message, sizeof(message), _("Hit timing: %ld BPM is out of range (%0.2f--%0.2f)."), period, MIN_FREQ, MAX_FREQ); + gtk_statusbar_push(GTK_STATUSBAR (metro->statusbar), context_id, (const char *) message); + catching = 0; + return; + } + + snprintf((char *) message, sizeof(message), _("Hit timing: set to %ld milisec (%ld BPM)."), delta_total, period); + gtk_statusbar_push(GTK_STATUSBAR (metro->statusbar), context_id, (const char *) message); + + metro->period = delta_total; + GTK_ADJUSTMENT(metro->adjustment)->value = period; + + last_time.tv_sec = current_time.tv_sec; + last_time.tv_usec = current_time.tv_usec; + + catching = 0; + gtOnOff(widget, metro); +} + void gtInit(metro_t *metro) { GtkObject* adjustment; @@ -149,6 +219,10 @@ metro->ticking = FALSE; /* set default */ metro->window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + + gtk_signal_connect(GTK_OBJECT (metro->window), "key_press_event", + GTK_SIGNAL_FUNC (keypress_handler), + &metro->window); gtk_signal_connect(GTK_OBJECT(metro->window), "destroy", GTK_SIGNAL_FUNC (gtQuit), @@ -187,7 +261,7 @@ gtk_box_pack_start (GTK_BOX (metro->box2), metro->label, TRUE, TRUE, 0); gtk_widget_show (metro->label); - metro->adjustment = gtk_adjustment_new (75.0, 30.0, 251.0, 1.0, 1.0, 1.0); + metro->adjustment = gtk_adjustment_new (75.0, MIN_FREQ, MAX_FREQ, 1.0, 1.0, 1.0); gtk_signal_connect (GTK_OBJECT (metro->adjustment), "value_changed", GTK_SIGNAL_FUNC (gtUpdateRate), (metro_t *)metro); @@ -342,6 +416,14 @@ gtk_box_pack_start (GTK_BOX (metro->box2), metro->button, TRUE,TRUE,0); gtk_widget_show (metro->button); + metro->statusbar = gtk_statusbar_new(); + gtk_container_add (GTK_CONTAINER (metro->box1), metro->statusbar); + gtk_statusbar_set_has_resize_grip (GTK_STATUSBAR (metro->statusbar), FALSE); + guint context_id = gtk_statusbar_get_context_id(GTK_STATUSBAR (metro->statusbar), "hit timing text"); + gtk_statusbar_push(GTK_STATUSBAR (metro->statusbar), context_id, _("Hit left shift twice to set timing.")); + + gtk_widget_show (metro->statusbar); + gtk_widget_show (metro->window); /*-----------*/ diff -u metro.h metro.h.patched --- metro.h 2003-07-27 18:03:50.000000000 +0200 +++ metro.h.patched 2003-08-20 22:43:37.000000000 +0200 @@ -30,6 +30,7 @@ typedef struct metro_t { GtkWidget *window; + GtkWidget *statusbar; GtkWidget *box1; GtkWidget *box2; GtkWidget *box3;