From 7fd006e946e38bae4212b8d4e3ce4093207d0aee Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 12 Mar 2012 00:24:11 +0000 Subject: Make port controls actually do something. git-svn-id: http://svn.drobilla.net/lad/trunk/ganv@4051 a436a847-0d15-0410-975c-d299462d15a1 --- src/Canvas.cpp | 7 ++++++- src/Port.cpp | 8 ++++++++ src/ganv-marshal.list | 2 +- src/ganv_test.c | 12 +++++++++++- src/port.c | 30 ++++++++++++++++++++++++------ 5 files changed, 50 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/Canvas.cpp b/src/Canvas.cpp index e353945..56e64f5 100644 --- a/src/Canvas.cpp +++ b/src/Canvas.cpp @@ -1131,7 +1131,12 @@ GanvCanvasImpl::port_event(GdkEvent* event, GanvPort* port) const double sens = fmaxf(1.0 - fabs(dy), value_range / range_x); const double dvalue = (dx * value_range) * sens; - const double value = control_start_value + dvalue; + double value = control_start_value + dvalue; + if (value < port->impl->control->min) { + value = port->impl->control->min; + } else if (value > port->impl->control->max) { + value = port->impl->control->max; + } ganv_port_set_control_value(port, value); return true; } diff --git a/src/Port.cpp b/src/Port.cpp index 36c556a..902087e 100644 --- a/src/Port.cpp +++ b/src/Port.cpp @@ -25,6 +25,12 @@ namespace Ganv { +static void +on_value_changed(GanvPort* port, GVariant* value, void* portmm) +{ + ((Port*)portmm)->signal_value_changed.emit(Glib::VariantBase(value)); +} + /** Contruct a Port on an existing module. */ Port::Port(Module& module, @@ -39,6 +45,8 @@ Port::Port(Module& module, "label", name.c_str(), NULL))) { + g_signal_connect(gobj(), "value-changed", + G_CALLBACK(on_value_changed), this); } Module* diff --git a/src/ganv-marshal.list b/src/ganv-marshal.list index ba6ef33..64e6c6b 100644 --- a/src/ganv-marshal.list +++ b/src/ganv-marshal.list @@ -1,4 +1,4 @@ -VOID:OBJECT,INT,INT,INT,INT BOOLEAN:BOXED VOID:DOUBLE,DOUBLE +VOID:OBJECT,INT,INT,INT,INT VOID:OBJECT,OBJECT diff --git a/src/ganv_test.c b/src/ganv_test.c index fce3ede..971b3e1 100644 --- a/src/ganv_test.c +++ b/src/ganv_test.c @@ -18,7 +18,7 @@ #include "ganv/ganv.h" static void -on_window_destroy(GtkWidget* widget, gpointer data) +on_window_destroy(GtkWidget* widget, void* data) { gtk_main_quit(); } @@ -35,6 +35,14 @@ on_disconnect(GanvCanvas* canvas, GanvNode* tail, GanvNode* head, void* data) ganv_canvas_remove_edge_between(canvas, tail, head); } +static void +on_value_changed(GanvPort* port, GVariant* value, void* data) +{ + char* str = g_variant_print(value, TRUE); + fprintf(stderr, "Value changed: port %p = %s\n", (void*)port, str); + g_free(str); +} + int main(int argc, char** argv) { @@ -63,6 +71,8 @@ main(int argc, char** argv) "label", "Control", NULL); ganv_port_show_control(cport); + g_signal_connect(cport, "value-changed", + G_CALLBACK(on_value_changed), NULL); //GtkWidget* entry = gtk_entry_new(); //ganv_module_embed(module, entry); diff --git a/src/port.c b/src/port.c index e8e6754..58e7629 100644 --- a/src/port.c +++ b/src/port.c @@ -36,6 +36,13 @@ enum { PROP_IS_INPUT }; +enum { + PORT_VALUE_CHANGED, + PORT_LAST_SIGNAL +}; + +static guint port_signals[PORT_LAST_SIGNAL]; + static void ganv_port_init(GanvPort* port) { @@ -252,6 +259,16 @@ ganv_port_class_init(GanvPortClass* class) 0, G_PARAM_READWRITE)); + port_signals[PORT_VALUE_CHANGED] + = g_signal_new("value-changed", + G_TYPE_FROM_CLASS(class), + G_SIGNAL_RUN_LAST, + 0, + NULL, NULL, + NULL, + G_TYPE_NONE, 1, + G_TYPE_VARIANT); + object_class->destroy = ganv_port_destroy; item_class->event = event; @@ -270,8 +287,7 @@ ganv_port_new(GanvModule* module, gboolean is_input, const char* first_prop_name, ...) { - GanvPort* port = GANV_PORT( - g_object_new(ganv_port_get_type(), NULL)); + GanvPort* port = GANV_PORT(g_object_new(ganv_port_get_type(), NULL)); port->impl->is_input = is_input; @@ -397,10 +413,12 @@ ganv_port_set_control_value(GanvPort* port, } ganv_box_set_width(impl->control->rect, MAX(0.0, w - 1.0)); -#if 0 - if (signal && _control->value == value) - signal = false; -#endif + + if (impl->control->value != value) { + GVariant* gvar = g_variant_new_double(value); + g_signal_emit(port, port_signals[PORT_VALUE_CHANGED], 0, gvar, NULL); + g_variant_unref(gvar); + } impl->control->value = value; -- cgit v1.2.1