From d0b752f49f0af4aa64c92d49d8e6ec1e6b545c5b Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 18 Feb 2012 06:55:00 +0000 Subject: Make forge API more fool-proof and automatically update container sizes to any depth. --- plugins/eg-sampler.lv2/sampler.c | 42 +++++++++++++++++++++---------------- plugins/eg-sampler.lv2/sampler_ui.c | 17 ++++++++------- 2 files changed, 34 insertions(+), 25 deletions(-) (limited to 'plugins/eg-sampler.lv2') diff --git a/plugins/eg-sampler.lv2/sampler.c b/plugins/eg-sampler.lv2/sampler.c index 8ef7bf9..904f026 100644 --- a/plugins/eg-sampler.lv2/sampler.c +++ b/plugins/eg-sampler.lv2/sampler.c @@ -354,24 +354,25 @@ static void run(LV2_Handle instance, uint32_t sample_count) { - Sampler* plugin = (Sampler*)instance; - sf_count_t start_frame = 0; - sf_count_t pos = 0; - float* output = plugin->output_port; + Sampler* plugin = (Sampler*)instance; + SamplerURIs* uris = &plugin->uris; + sf_count_t start_frame = 0; + sf_count_t pos = 0; + float* output = plugin->output_port; /* Read incoming events */ LV2_SEQUENCE_FOREACH((LV2_Atom_Sequence*)plugin->control_port->data, i) { LV2_Atom_Event* const ev = lv2_sequence_iter_get(i); - if (ev->body.type == plugin->uris.midi_Event) { + if (ev->body.type == uris->midi_Event) { uint8_t* const data = (uint8_t* const)(ev + 1); if ((data[0] & 0xF0) == 0x90) { start_frame = ev->time.audio.frames; plugin->frame = 0; plugin->play = true; } - } else if (is_object_type(&plugin->uris, ev->body.type)) { + } else if (is_object_type(uris, ev->body.type)) { const LV2_Atom_Object* obj = (LV2_Atom_Object*)&ev->body; - if (obj->type == plugin->uris.msg_Set) { + if (obj->type == uris->msg_Set) { /* Received a set message, send it to the worker thread. */ fprintf(stderr, "Queueing set message\n"); zix_ring_write(plugin->to_worker, @@ -414,6 +415,8 @@ run(LV2_Handle instance, /* Set up forge to write directly to notify output port buffer */ LV2_Atom* seq = plugin->notify_port->data; + LV2_Atom_Forge_Frame seq_frame; + lv2_atom_forge_push(&plugin->forge, &seq_frame, seq); lv2_atom_forge_set_buffer( &plugin->forge, LV2_ATOM_CONTENTS(LV2_Atom_Sequence, seq), @@ -423,10 +426,10 @@ run(LV2_Handle instance, SampleMessage m; const uint32_t msize = lv2_atom_pad_size(sizeof(m)); while (zix_ring_read(plugin->from_worker, &m, msize) == msize) { - if (m.atom.type == plugin->uris.eg_applySample) { + if (m.atom.type == uris->eg_applySample) { /* Send a message to the worker to free the current sample */ SampleMessage free_msg = { - { plugin->uris.eg_freeSample, sizeof(plugin->sample) }, + { uris->eg_freeSample, sizeof(plugin->sample) }, plugin->sample }; zix_ring_write(plugin->to_worker, @@ -439,26 +442,29 @@ run(LV2_Handle instance, /* Send a notification that we're using a new sample. */ - lv2_atom_forge_audio_time(&plugin->forge, seq, 0, 0); + lv2_atom_forge_audio_time(&plugin->forge, 0, 0); - LV2_Atom* set = (LV2_Atom*)lv2_atom_forge_blank( - &plugin->forge, NULL, 1, plugin->uris.msg_Set); + LV2_Atom_Forge_Frame set_frame; + lv2_atom_forge_blank(&plugin->forge, &set_frame, 1, uris->msg_Set); - lv2_atom_forge_property_head(&plugin->forge, set, plugin->uris.msg_body, 0); - LV2_Atom* body = (LV2_Atom*)lv2_atom_forge_blank(&plugin->forge, NULL, 2, 0); + lv2_atom_forge_property_head(&plugin->forge, uris->msg_body, 0); + LV2_Atom_Forge_Frame body_frame; + lv2_atom_forge_blank(&plugin->forge, &body_frame, 2, 0); - lv2_atom_forge_property_head(&plugin->forge, body, plugin->uris.eg_file, 0); - lv2_atom_forge_uri(&plugin->forge, body, + lv2_atom_forge_property_head(&plugin->forge, uris->eg_file, 0); + lv2_atom_forge_uri(&plugin->forge, (const uint8_t*)plugin->sample->uri, plugin->sample->uri_len); + lv2_atom_forge_pop(&plugin->forge, &body_frame); + lv2_atom_forge_pop(&plugin->forge, &set_frame); - set->size += lv2_atom_total_size(body); - seq->size += lv2_atom_total_size(set); } else { fprintf(stderr, "Unknown message from worker\n"); } } + + lv2_atom_forge_pop(&plugin->forge, &seq_frame); } static void diff --git a/plugins/eg-sampler.lv2/sampler_ui.c b/plugins/eg-sampler.lv2/sampler_ui.c index e21a8a9..056f0bb 100644 --- a/plugins/eg-sampler.lv2/sampler_ui.c +++ b/plugins/eg-sampler.lv2/sampler_ui.c @@ -95,21 +95,24 @@ on_load_clicked(GtkWidget* widget, * ] ; * ] */ + LV2_Atom_Forge_Frame set_frame; LV2_Atom* set = (LV2_Atom*)lv2_atom_forge_blank( - &ui->forge, NULL, 1, ui->uris.msg_Set); + &ui->forge, &set_frame, 1, ui->uris.msg_Set); - lv2_atom_forge_property_head(&ui->forge, set, ui->uris.msg_body, 0); - LV2_Atom* body = (LV2_Atom*)lv2_atom_forge_blank(&ui->forge, NULL, 2, 0); + lv2_atom_forge_property_head(&ui->forge, ui->uris.msg_body, 0); + LV2_Atom_Forge_Frame body_frame; + lv2_atom_forge_blank(&ui->forge, &body_frame, 2, 0); - lv2_atom_forge_property_head(&ui->forge, body, ui->uris.eg_file, 0); - lv2_atom_forge_uri(&ui->forge, body, (const uint8_t*)file_uri, file_uri_len); - - set->size += lv2_atom_total_size(body); + lv2_atom_forge_property_head(&ui->forge, ui->uris.eg_file, 0); + lv2_atom_forge_uri(&ui->forge, (const uint8_t*)file_uri, file_uri_len); ui->write(ui->controller, 0, lv2_atom_total_size(set), ui->uris.atom_eventTransfer, set); + lv2_atom_forge_pop(&ui->forge, &body_frame); + lv2_atom_forge_pop(&ui->forge, &set_frame); + g_free(filename); g_free(file_uri); } -- cgit v1.2.1