aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/eg-sampler.lv2/sampler_ui.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2016-10-05 05:31:38 -0400
committerDavid Robillard <d@drobilla.net>2016-10-05 05:31:38 -0400
commitc938afee2c84c02d6a5b9c799363441cff20ebf0 (patch)
tree22c6d51cec8a2c1f53ca9cf2e8af9e827c079516 /plugins/eg-sampler.lv2/sampler_ui.c
parentcc2fdc67444a031a90606ba42e5ebd3f957d3313 (diff)
downloadlv2-c938afee2c84c02d6a5b9c799363441cff20ebf0.tar.xz
Add play button to UI
Diffstat (limited to 'plugins/eg-sampler.lv2/sampler_ui.c')
-rw-r--r--plugins/eg-sampler.lv2/sampler_ui.c58
1 files changed, 46 insertions, 12 deletions
diff --git a/plugins/eg-sampler.lv2/sampler_ui.c b/plugins/eg-sampler.lv2/sampler_ui.c
index 5723223..9ea662c 100644
--- a/plugins/eg-sampler.lv2/sampler_ui.c
+++ b/plugins/eg-sampler.lv2/sampler_ui.c
@@ -47,7 +47,9 @@ typedef struct {
LV2UI_Controller controller;
GtkWidget* box;
- GtkWidget* button;
+ GtkWidget* play_button;
+ GtkWidget* file_button;
+ GtkWidget* button_box;
GtkWidget* canvas;
GtkWidget* window; /* For optional show interface. */
@@ -79,6 +81,25 @@ on_file_set(GtkFileChooserButton* widget, void* handle)
}
static void
+on_play_clicked(GtkFileChooserButton* widget, void* handle)
+{
+ SamplerUI* ui = (SamplerUI*)handle;
+ struct {
+ LV2_Atom atom;
+ uint8_t msg[3];
+ } note_on;
+
+ note_on.atom.type = ui->uris.midi_Event;
+ note_on.atom.size = 3;
+ note_on.msg[0] = LV2_MIDI_MSG_NOTE_ON;
+ note_on.msg[1] = 60;
+ note_on.msg[2] = 60;
+ ui->write(ui->controller, 0, sizeof(note_on),
+ ui->uris.atom_eventTransfer,
+ &note_on);
+}
+
+static void
request_peaks(SamplerUI* ui, uint32_t n_peaks)
{
lv2_atom_forge_set_buffer(&ui->forge, ui->forge_buf, sizeof(ui->forge_buf));
@@ -201,19 +222,27 @@ instantiate(const LV2UI_Descriptor* descriptor,
peaks_receiver_init(&ui->precv, ui->map);
// Construct Gtk UI
- ui->box = gtk_vbox_new(FALSE, 4);
- ui->button = gtk_file_chooser_button_new("Load Sample", GTK_FILE_CHOOSER_ACTION_OPEN);
- ui->canvas = gtk_drawing_area_new();
+ ui->box = gtk_vbox_new(FALSE, 4);
+ ui->play_button = gtk_button_new_with_label("▶");
+ ui->canvas = gtk_drawing_area_new();
+ ui->button_box = gtk_hbox_new(FALSE, 4);
+ ui->file_button = gtk_file_chooser_button_new(
+ "Load Sample", GTK_FILE_CHOOSER_ACTION_OPEN);
gtk_widget_set_size_request(ui->canvas, MIN_CANVAS_W, MIN_CANVAS_H);
gtk_container_set_border_width(GTK_CONTAINER(ui->box), 4);
gtk_box_pack_start(GTK_BOX(ui->box), ui->canvas, TRUE, TRUE, 0);
- gtk_box_pack_start(GTK_BOX(ui->box), ui->button, FALSE, TRUE, 0);
- g_signal_connect(ui->button, "file-set",
- G_CALLBACK(on_file_set),
- ui);
+ gtk_box_pack_start(GTK_BOX(ui->box), ui->button_box, FALSE, TRUE, 0);
+ gtk_box_pack_start(GTK_BOX(ui->button_box), ui->play_button, FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(ui->button_box), ui->file_button, TRUE, TRUE, 0);
+
+ g_signal_connect(ui->file_button, "file-set",
+ G_CALLBACK(on_file_set), ui);
+
+ g_signal_connect(ui->play_button, "clicked",
+ G_CALLBACK(on_play_clicked), ui);
+
g_signal_connect(G_OBJECT(ui->canvas), "expose_event",
- G_CALLBACK(on_canvas_expose),
- ui);
+ G_CALLBACK(on_canvas_expose), ui);
// Request state (filename) from plugin
lv2_atom_forge_set_buffer(&ui->forge, ui->forge_buf, sizeof(ui->forge_buf));
@@ -235,7 +264,11 @@ static void
cleanup(LV2UI_Handle handle)
{
SamplerUI* ui = (SamplerUI*)handle;
- gtk_widget_destroy(ui->button);
+ gtk_widget_destroy(ui->box);
+ gtk_widget_destroy(ui->play_button);
+ gtk_widget_destroy(ui->canvas);
+ gtk_widget_destroy(ui->button_box);
+ gtk_widget_destroy(ui->file_button);
free(ui);
}
@@ -256,7 +289,8 @@ port_event(LV2UI_Handle handle,
if (path && (!ui->filename || strcmp(path, ui->filename))) {
g_free(ui->filename);
ui->filename = g_strdup(path);
- gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(ui->button), path);
+ gtk_file_chooser_set_filename(
+ GTK_FILE_CHOOSER(ui->file_button), path);
peaks_receiver_clear(&ui->precv);
request_peaks(ui, ui->width / 2 * 2);
} else if (!path) {