diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/jalv.c | 39 | ||||
-rw-r--r-- | src/jalv_console.c | 9 | ||||
-rw-r--r-- | src/jalv_gtk2.c | 43 | ||||
-rw-r--r-- | src/jalv_gtkmm2.cpp | 9 | ||||
-rw-r--r-- | src/jalv_internal.h | 27 | ||||
-rw-r--r-- | src/jalv_qt4.cpp | 9 | ||||
-rw-r--r-- | src/state.c | 2 |
7 files changed, 101 insertions, 37 deletions
@@ -403,7 +403,7 @@ jack_process_cb(jack_nframes_t nframes, void* data) } /* Read and apply control change events from UI */ - if (host->ui) { + if (host->has_ui) { ControlChange ev; const size_t space = jack_ringbuffer_read_space(host->ui_events); for (size_t i = 0; i < space; i += sizeof(ev) + ev.size) { @@ -445,7 +445,7 @@ jack_process_cb(jack_nframes_t nframes, void* data) host->event_delta_t += nframes; bool send_ui_updates = false; jack_nframes_t update_frames = host->sample_rate / JALV_UI_UPDATE_HZ; - if (host->ui && (host->event_delta_t > update_frames)) { + if (host->has_ui && (host->event_delta_t > update_frames)) { send_ui_updates = true; host->event_delta_t = 0; } @@ -564,8 +564,7 @@ jalv_ui_write(SuilController controller, const void* buffer) { Jalv* host = (Jalv*)controller; - - if (!host->ui) { + if (!host->has_ui) { return; } @@ -623,8 +622,12 @@ jalv_emit_ui_events(Jalv* host) free(str); } - suil_instance_port_event(host->ui_instance, ev.index, - ev.size, ev.protocol, buf); + if (host->ui_instance) { + suil_instance_port_event(host->ui_instance, ev.index, + ev.size, ev.protocol, buf); + } else { + jalv_ui_port_event(host, ev.index, ev.size, ev.protocol, buf); + } } return true; @@ -770,10 +773,8 @@ main(int argc, char** argv) LilvUIs* uis = lilv_plugin_get_uis(host.plugin); // FIXME: leak LILV_FOREACH(uis, u, uis) { const LilvUI* this_ui = lilv_uis_get(uis, u); - if (lilv_ui_is_supported(this_ui, - suil_ui_supported, - native_ui_type, - &ui_type)) { + if (lilv_ui_is_supported( + this_ui, suil_ui_supported, native_ui_type, &ui_type)) { // TODO: Multiple UI support host.ui = this_ui; break; @@ -785,15 +786,15 @@ main(int argc, char** argv) if (host.ui) { fprintf(stderr, "UI: %s\n", lilv_node_as_uri(lilv_ui_get_uri(host.ui))); - - host.ui_events = jack_ringbuffer_create(4096); - host.plugin_events = jack_ringbuffer_create(4096); - jack_ringbuffer_mlock(host.ui_events); - jack_ringbuffer_mlock(host.plugin_events); } else { fprintf(stderr, "No appropriate UI found\n"); } + host.ui_events = jack_ringbuffer_create(4096); + host.plugin_events = jack_ringbuffer_create(4096); + jack_ringbuffer_mlock(host.ui_events); + jack_ringbuffer_mlock(host.plugin_events); + /* Create port structures (host.ports) */ jalv_create_ports(&host); @@ -895,6 +896,7 @@ main(int argc, char** argv) /* Instantiate UI */ ui_host = suil_host_new(jalv_ui_write, NULL, NULL, NULL); + host.has_ui = true; host.ui_instance = suil_instance_new( ui_host, &host, @@ -948,16 +950,15 @@ main(int argc, char** argv) /* Clean up */ free(host.ports); - if (host.ui) { - jack_ringbuffer_free(host.ui_events); - jack_ringbuffer_free(host.plugin_events); - } + jack_ringbuffer_free(host.ui_events); + jack_ringbuffer_free(host.plugin_events); lilv_node_free(native_ui_type); for (LilvNode** n = (LilvNode**)&host.nodes; *n; ++n) { lilv_node_free(*n); } symap_free(host.symap); suil_host_free(ui_host); + sratom_free(host.sratom); lilv_world_free(world); zix_sem_destroy(&exit_sem); diff --git a/src/jalv_console.c b/src/jalv_console.c index ae5c30f..65708d0 100644 --- a/src/jalv_console.c +++ b/src/jalv_console.c @@ -40,6 +40,15 @@ jalv_ui_resize(Jalv* jalv, int width, int height) return 0; } +void +jalv_ui_port_event(Jalv* jalv, + uint32_t port_index, + uint32_t buffer_size, + uint32_t protocol, + const void* buffer) +{ +} + int jalv_init(int* argc, char*** argv, JalvOptions* opts) { diff --git a/src/jalv_gtk2.c b/src/jalv_gtk2.c index 155f890..7023c9f 100644 --- a/src/jalv_gtk2.c +++ b/src/jalv_gtk2.c @@ -191,6 +191,30 @@ add_preset_to_menu(Jalv* jalv, return 0; } +void +jalv_ui_port_event(Jalv* jalv, + uint32_t port_index, + uint32_t buffer_size, + uint32_t protocol, + const void* buffer) +{ + GtkWidget* widget = jalv->ports[port_index].widget; + if (!widget) { + return; + } + + if (GTK_IS_COMBO_BOX(widget)) { + fprintf(stderr, "TODO: Combo box value change\n"); + } else if (GTK_IS_TOGGLE_BUTTON(widget)) { + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), + *(float*)buffer > 0.0f); + } else if (GTK_IS_RANGE(widget)) { + gtk_range_set_value(GTK_RANGE(widget), *(float*)buffer); + } else { + fprintf(stderr, "Unknown widget type for port %d\n", port_index); + } +} + static gboolean slider_changed(GtkRange* range, gpointer data) { @@ -317,10 +341,11 @@ build_control_widget(Jalv* jalv, GtkWidget* window) int idx = 0; LILV_FOREACH(scale_points, i, sp) { const LilvScalePoint* p = lilv_scale_points_get(sp, i); - values[idx++] = lilv_node_as_float(lilv_scale_point_get_value(p)); + values[idx] = lilv_node_as_float(lilv_scale_point_get_value(p)); char* label = g_strdup( lilv_node_as_string(lilv_scale_point_get_label(p))); g_hash_table_insert(points, values + idx, label); + ++idx; } lilv_scale_points_free(sp); } @@ -339,6 +364,7 @@ build_control_widget(Jalv* jalv, GtkWidget* window) lilv_port_has_property(jalv->plugin, port, lv2_integer), mins[i], maxs[i], defaults[i]); } + jalv->ports[i].widget = control; /* Set tooltip text */ LilvNodes* comments = lilv_port_get_value( @@ -347,6 +373,7 @@ build_control_widget(Jalv* jalv, GtkWidget* window) gtk_widget_set_tooltip_text( control, lilv_node_as_string(lilv_nodes_get_first(comments))); } + lilv_nodes_free(comments); /* Add control table row */ GtkWidget* label = gtk_label_new(NULL); @@ -400,9 +427,9 @@ jalv_open_ui(Jalv* jalv, g_signal_connect(window, "destroy", G_CALLBACK(on_window_destroy), jalv); - gtk_window_set_title( - GTK_WINDOW(window), - lilv_node_as_string(lilv_plugin_get_name(jalv->plugin))); + LilvNode* name = lilv_plugin_get_name(jalv->plugin); + gtk_window_set_title(GTK_WINDOW(window), lilv_node_as_string(name)); + lilv_node_free(name); GtkWidget* vbox = gtk_vbox_new(FALSE, 0); GtkWidget* menu_bar = gtk_menu_bar_new(); @@ -444,16 +471,12 @@ jalv_open_ui(Jalv* jalv, g_signal_connect(G_OBJECT(save_preset), "activate", G_CALLBACK(on_save_preset_activate), jalv); - if (instance && !jalv->opts.generic_ui) { GtkWidget* alignment = gtk_alignment_new(0.5, 0.5, 1.0, 1.0); GtkWidget* widget = (GtkWidget*)suil_instance_get_widget(instance); gtk_box_pack_start(GTK_BOX(vbox), alignment, TRUE, TRUE, 0); gtk_container_add(GTK_CONTAINER(alignment), widget); - - g_timeout_add(1000 / JALV_UI_UPDATE_HZ, - (GSourceFunc)jalv_emit_ui_events, jalv); gtk_window_set_resizable(GTK_WINDOW(window), jalv_ui_is_resizable(jalv)); gtk_widget_show_all(vbox); } else { @@ -477,6 +500,10 @@ jalv_open_ui(Jalv* jalv, box_size.height + controls_size.height); } + g_timeout_add(1000 / JALV_UI_UPDATE_HZ, + (GSourceFunc)jalv_emit_ui_events, jalv); + + jalv->has_ui = TRUE; gtk_window_present(GTK_WINDOW(window)); gtk_main(); diff --git a/src/jalv_gtkmm2.cpp b/src/jalv_gtkmm2.cpp index e846f1b..e24bf40 100644 --- a/src/jalv_gtkmm2.cpp +++ b/src/jalv_gtkmm2.cpp @@ -47,6 +47,15 @@ jalv_ui_resize(Jalv* jalv, int width, int height) return 0; } +void +jalv_ui_port_event(Jalv* jalv, + uint32_t port_index, + uint32_t buffer_size, + uint32_t protocol, + const void* buffer) +{ +} + int jalv_open_ui(Jalv* jalv, SuilInstance* instance) diff --git a/src/jalv_internal.h b/src/jalv_internal.h index f2b1b95..50587a6 100644 --- a/src/jalv_internal.h +++ b/src/jalv_internal.h @@ -63,14 +63,15 @@ enum PortType { }; struct Port { - const LilvPort* lilv_port; - enum PortType type; - enum PortFlow flow; - jack_port_t* jack_port; ///< For audio/MIDI ports, otherwise NULL - LV2_Evbuf* evbuf; ///< For MIDI ports, otherwise NULL - uint32_t index; ///< Port index - float control; ///< For control ports, otherwise 0.0f - bool old_api; ///< True for event, false for atom + const LilvPort* lilv_port; + enum PortType type; + enum PortFlow flow; + jack_port_t* jack_port; ///< For audio/MIDI ports, otherwise NULL + LV2_Evbuf* evbuf; ///< For MIDI ports, otherwise NULL + void* widget; ///< Control widget, if applicable + uint32_t index; ///< Port index + float control; ///< For control ports, otherwise 0.0f + bool old_api; ///< True for event, false for atom }; /** @@ -168,7 +169,8 @@ typedef struct { jack_nframes_t event_delta_t; ///< Frames since last update sent to UI uint32_t midi_event_id; ///< MIDI event class ID in event context bool buf_size_set; ///< True iff buffer size callback fired - bool exit; ///< True if execution is finished + bool exit; ///< True iff execution is finished + bool has_ui; ///< True iff a control UI is present } Jalv; int @@ -197,6 +199,13 @@ jalv_ui_write(SuilController controller, uint32_t protocol, const void* buffer); +void +jalv_ui_port_event(Jalv* jalv, + uint32_t port_index, + uint32_t buffer_size, + uint32_t protocol, + const void* buffer); + bool jalv_emit_ui_events(Jalv* jalv); diff --git a/src/jalv_qt4.cpp b/src/jalv_qt4.cpp index 8111c34..3aa7e88 100644 --- a/src/jalv_qt4.cpp +++ b/src/jalv_qt4.cpp @@ -51,6 +51,15 @@ jalv_ui_resize(Jalv* jalv, int width, int height) return 0; } +void +jalv_ui_port_event(Jalv* jalv, + uint32_t port_index, + uint32_t buffer_size, + uint32_t protocol, + const void* buffer) +{ +} + class Timer : public QTimer { public: explicit Timer(Jalv* j) : jalv(j) {} diff --git a/src/state.c b/src/state.c index 8c60776..a75ef3b 100644 --- a/src/state.c +++ b/src/state.c @@ -148,7 +148,7 @@ set_port_value(const char* port_symbol, jalv_ui_write(jalv, port->index, sizeof(fvalue), 0, &fvalue); // Update UI - if (jalv->ui) { + if (jalv->has_ui) { char buf[sizeof(ControlChange) + sizeof(fvalue)]; ControlChange* ev = (ControlChange*)buf; ev->index = port->index; |