From 5ed281c6a420fc3d1765ee49faa3baf8db6b1116 Mon Sep 17 00:00:00 2001 From: Jean Pierre Cimalando Date: Tue, 22 Jun 2021 00:45:44 +0200 Subject: [PATCH] lv2: A6 workaround, single output atom port Previously, some `patch:Set` messages were directed to a distinct atom port, when it was for notification purposes rather than automation. Ardour does not support this, and the ports get assigned the same buffer, producing corruption. This commit returns to single-port behavior, and instead replaces `patch:Set` notification messages with `sfizz:Notify` custom objects; the UI processes these messages all the same, and they does not trigger automation in the host. --- plugins/lv2/sfizz.cpp | 44 +++++++++++++----------------- plugins/lv2/sfizz.ttl.in | 49 ++++++++++++++-------------------- plugins/lv2/sfizz_lv2.h | 40 +++++++++++++-------------- plugins/lv2/sfizz_lv2_plugin.h | 3 +-- plugins/lv2/sfizz_ui.cpp | 2 ++ 5 files changed, 62 insertions(+), 76 deletions(-) diff --git a/plugins/lv2/sfizz.cpp b/plugins/lv2/sfizz.cpp index 6c1d56a2..c29d9ebf 100644 --- a/plugins/lv2/sfizz.cpp +++ b/plugins/lv2/sfizz.cpp @@ -123,6 +123,7 @@ sfizz_lv2_map_required_uris(sfizz_plugin_t *self) self->sfizz_log_status_uri = map->map(map->handle, SFIZZ__logStatus); self->sfizz_check_modification_uri = map->map(map->handle, SFIZZ__checkModification); self->sfizz_osc_blob_uri = map->map(map->handle, SFIZZ__OSCBlob); + self->sfizz_notify_uri = map->map(map->handle, SFIZZ__Notify); self->sfizz_audio_level_uri = map->map(map->handle, SFIZZ__AudioLevel); self->time_position_uri = map->map(map->handle, LV2_TIME__Position); self->time_bar_uri = map->map(map->handle, LV2_TIME__bar); @@ -200,9 +201,6 @@ connect_port(LV2_Handle instance, case SFIZZ_CONTROL: self->control_port = (const LV2_Atom_Sequence *)data; break; - case SFIZZ_NOTIFY: - self->notify_port = (LV2_Atom_Sequence *)data; - break; case SFIZZ_AUTOMATE: self->automate_port = (LV2_Atom_Sequence *)data; break; @@ -331,7 +329,7 @@ sfizz_lv2_receive_message(void* data, int delay, const char* path, const char* s if (osc_size > OSC_TEMP_SIZE) return; - LV2_Atom_Forge* forge = &self->forge_notify; + LV2_Atom_Forge* forge = &self->forge_automate; bool write_ok = lv2_atom_forge_frame_time(forge, 0) && lv2_atom_forge_atom(forge, osc_size, self->sfizz_osc_blob_uri) && @@ -439,7 +437,6 @@ instantiate(const LV2_Descriptor *descriptor, sfizz_lv2_map_required_uris(self); // Initialize the forge - lv2_atom_forge_init(&self->forge_notify, self->map); lv2_atom_forge_init(&self->forge_automate, self->map); lv2_atom_forge_init(&self->forge_secondary, self->map); @@ -545,13 +542,14 @@ deactivate(LV2_Handle instance) } static void -sfizz_lv2_send_file_path(sfizz_plugin_t *self, LV2_Atom_Forge* forge, LV2_URID urid, const char *path) +sfizz_lv2_send_file_path(sfizz_plugin_t *self, LV2_URID verb_uri, LV2_URID urid, const char *path) { LV2_Atom_Forge_Frame frame; + LV2_Atom_Forge* forge = &self->forge_automate; bool write_ok = lv2_atom_forge_frame_time(forge, 0) && - lv2_atom_forge_object(forge, &frame, 0, self->patch_set_uri) && + lv2_atom_forge_object(forge, &frame, 0, verb_uri) && lv2_atom_forge_key(forge, self->patch_property_uri) && lv2_atom_forge_urid(forge, urid) && lv2_atom_forge_key(forge, self->patch_value_uri) && @@ -562,14 +560,15 @@ sfizz_lv2_send_file_path(sfizz_plugin_t *self, LV2_Atom_Forge* forge, LV2_URID u } static void -sfizz_lv2_send_controller(sfizz_plugin_t *self, LV2_Atom_Forge* forge, unsigned cc, float value) +sfizz_lv2_send_controller(sfizz_plugin_t *self, LV2_URID verb_uri, unsigned cc, float value) { LV2_URID urid = sfizz_lv2_ccmap_map(self->ccmap, int(cc)); LV2_Atom_Forge_Frame frame; + LV2_Atom_Forge* forge = &self->forge_automate; bool write_ok = lv2_atom_forge_frame_time(forge, 0) && - lv2_atom_forge_object(forge, &frame, 0, self->patch_set_uri) && + lv2_atom_forge_object(forge, &frame, 0, verb_uri) && lv2_atom_forge_key(forge, self->patch_property_uri) && lv2_atom_forge_urid(forge, urid) && lv2_atom_forge_key(forge, self->patch_value_uri) && @@ -581,11 +580,12 @@ sfizz_lv2_send_controller(sfizz_plugin_t *self, LV2_Atom_Forge* forge, unsigned #if defined(SFIZZ_LV2_UI) static void -sfizz_lv2_send_levels(sfizz_plugin_t *self, LV2_Atom_Forge* forge, float left, float right) +sfizz_lv2_send_levels(sfizz_plugin_t *self, float left, float right) { const float levels[] = {left, right}; uint32_t num_levels = sizeof(levels) / sizeof(levels[0]); + LV2_Atom_Forge* forge = &self->forge_automate; bool write_ok = lv2_atom_forge_frame_time(forge, 0); LV2_Atom_Vector *vector = nullptr; @@ -871,7 +871,7 @@ static void run(LV2_Handle instance, uint32_t sample_count) { sfizz_plugin_t *self = (sfizz_plugin_t *)instance; - assert(self->control_port && self->notify_port && self->automate_port); + assert(self->control_port && self->automate_port); if (!spin_mutex_trylock(self->synth_mutex)) { @@ -881,15 +881,10 @@ run(LV2_Handle instance, uint32_t sample_count) } // Set up dedicated forges to write on their respective ports. - const size_t notify_capacity = self->notify_port->atom.size; - lv2_atom_forge_set_buffer(&self->forge_notify, (uint8_t *)self->notify_port, notify_capacity); const size_t automate_capacity = self->automate_port->atom.size; lv2_atom_forge_set_buffer(&self->forge_automate, (uint8_t *)self->automate_port, automate_capacity); // Start sequences in the respective output ports. - LV2_Atom_Forge_Frame notify_frame; - if (!lv2_atom_forge_sequence_head(&self->forge_notify, ¬ify_frame, 0)) - assert(false); LV2_Atom_Forge_Frame automate_frame; if (!lv2_atom_forge_sequence_head(&self->forge_automate, &automate_frame, 0)) assert(false); @@ -913,25 +908,25 @@ run(LV2_Handle instance, uint32_t sample_count) lv2_atom_object_get(obj, self->patch_property_uri, &property, 0); if (!property) // Send the full state { - sfizz_lv2_send_file_path(self, &self->forge_notify, self->sfizz_sfz_file_uri, self->sfz_file_path); - sfizz_lv2_send_file_path(self, &self->forge_notify, self->sfizz_scala_file_uri, self->scala_file_path); + sfizz_lv2_send_file_path(self, self->sfizz_notify_uri, self->sfizz_sfz_file_uri, self->sfz_file_path); + sfizz_lv2_send_file_path(self, self->sfizz_notify_uri, self->sfizz_scala_file_uri, self->scala_file_path); for (unsigned cc = 0; cc < sfz::config::numCCs; ++cc) - sfizz_lv2_send_controller(self, &self->forge_notify, cc, self->cc_current[cc]); + sfizz_lv2_send_controller(self, self->sfizz_notify_uri, cc, self->cc_current[cc]); } else if (property->body == self->sfizz_sfz_file_uri) { - sfizz_lv2_send_file_path(self, &self->forge_notify, self->sfizz_sfz_file_uri, self->sfz_file_path); + sfizz_lv2_send_file_path(self, self->sfizz_notify_uri, self->sfizz_sfz_file_uri, self->sfz_file_path); } else if (property->body == self->sfizz_scala_file_uri) { - sfizz_lv2_send_file_path(self, &self->forge_notify, self->sfizz_scala_file_uri, self->scala_file_path); + sfizz_lv2_send_file_path(self, self->sfizz_notify_uri, self->sfizz_scala_file_uri, self->scala_file_path); } else { int cc = sfizz_lv2_ccmap_unmap(self->ccmap, property->body); if (cc != -1) - sfizz_lv2_send_controller(self, &self->forge_notify, unsigned(cc), self->cc_current[cc]); + sfizz_lv2_send_controller(self, self->sfizz_notify_uri, unsigned(cc), self->cc_current[cc]); } } else if (obj->body.otype == self->time_position_uri) @@ -1079,7 +1074,7 @@ run(LV2_Handle instance, uint32_t sample_count) for (unsigned cc = 0; cc < sfz::config::numCCs; ++cc) { absl::optional value = self->ccauto[cc]; if (value) { - sfizz_lv2_send_controller(self, &self->forge_automate, cc, *value); + sfizz_lv2_send_controller(self, self->patch_set_uri, cc, *value); self->ccauto[cc] = absl::nullopt; } } @@ -1094,7 +1089,7 @@ run(LV2_Handle instance, uint32_t sample_count) self->rms_follower.process(self->output_buffers[0], self->output_buffers[1], sample_count); const simde__m128 rms = self->rms_follower.getRMS(); const float *levels = (const float *)&rms; - sfizz_lv2_send_levels(self, &self->forge_notify, levels[0], levels[1]); + sfizz_lv2_send_levels(self, levels[0], levels[1]); } else { @@ -1102,7 +1097,6 @@ run(LV2_Handle instance, uint32_t sample_count) } #endif - lv2_atom_forge_pop(&self->forge_notify, ¬ify_frame); lv2_atom_forge_pop(&self->forge_automate, &automate_frame); } diff --git a/plugins/lv2/sfizz.ttl.in b/plugins/lv2/sfizz.ttl.in index 83bddf76..fd860990 100644 --- a/plugins/lv2/sfizz.ttl.in +++ b/plugins/lv2/sfizz.ttl.in @@ -102,7 +102,7 @@ midnam:update a lv2:Feature . lv2:port [ a lv2:InputPort, atom:AtomPort ; atom:bufferType atom:Sequence ; - atom:supports patch:Message, midi:MidiEvent, time:Position, <@LV2PLUGIN_URI@:OSCBlob> ; + atom:supports patch:Message, midi:MidiEvent, time:Position, <@LV2PLUGIN_URI@:OSCBlob>, <@LV2PLUGIN_URI@:Notify> ; lv2:designation lv2:control ; lv2:index 0 ; lv2:symbol "control" ; @@ -113,24 +113,15 @@ midnam:update a lv2:Feature . a lv2:OutputPort, atom:AtomPort ; atom:bufferType atom:Sequence ; atom:supports patch:Message, <@LV2PLUGIN_URI@:OSCBlob> ; - lv2:index 1 ; - lv2:symbol "notify" ; - lv2:name "Notify", - "Notification"@fr ; - rsz:minimumSize 524288 ; - ] , [ - a lv2:OutputPort, atom:AtomPort ; - atom:bufferType atom:Sequence ; - atom:supports patch:Message ; lv2:designation lv2:control ; - lv2:index 2 ; + lv2:index 1 ; lv2:symbol "automate" ; lv2:name "Automate", "Automatisation"@fr ; rsz:minimumSize 524288 ; ] , [ a lv2:AudioPort, lv2:OutputPort ; - lv2:index 3 ; + lv2:index 2 ; lv2:symbol "out_left" ; lv2:name "Left Output", "Sortie gauche"@fr , @@ -139,7 +130,7 @@ midnam:update a lv2:Feature . lv2:designation pg:left ] , [ a lv2:AudioPort, lv2:OutputPort ; - lv2:index 4 ; + lv2:index 3 ; lv2:symbol "out_right" ; lv2:name "Right Output", "Sortie droite"@fr , @@ -148,7 +139,7 @@ midnam:update a lv2:Feature . lv2:designation pg:right ] , [ a lv2:InputPort, lv2:ControlPort ; - lv2:index 5 ; + lv2:index 4 ; lv2:symbol "volume" ; lv2:name "Volume" ; lv2:default 0.0 ; @@ -157,7 +148,7 @@ midnam:update a lv2:Feature . units:unit units:db ] , [ a lv2:InputPort, lv2:ControlPort ; - lv2:index 6 ; + lv2:index 5 ; lv2:symbol "num_voices" ; lv2:name "Polyphony", "Polyphonie"@fr , @@ -202,7 +193,7 @@ midnam:update a lv2:Feature . ] ; ] , [ a lv2:InputPort, lv2:ControlPort ; - lv2:index 7 ; + lv2:index 6 ; lv2:symbol "oversampling" ; lv2:name "Oversampling factor", "Facteur de suréchantillonnage"@fr , @@ -237,7 +228,7 @@ midnam:update a lv2:Feature . ] ; ] , [ a lv2:InputPort, lv2:ControlPort ; - lv2:index 8 ; + lv2:index 7 ; lv2:symbol "preload_size" ; lv2:name "Preload size", "Taille préchargée"@fr , @@ -280,7 +271,7 @@ midnam:update a lv2:Feature . ] ; ] , [ a lv2:InputPort, lv2:ControlPort ; - lv2:index 9 ; + lv2:index 8 ; lv2:symbol "freewheeling" ; lv2:name "Freewheeling", "En roue libre (freewheeling)"@fr , @@ -292,7 +283,7 @@ midnam:update a lv2:Feature . lv2:maximum 1 ; ] , [ a lv2:InputPort, lv2:ControlPort ; - lv2:index 10 ; + lv2:index 9 ; lv2:symbol "scala_root_key" ; lv2:name "Scala root key", "Tonalité de base Scala"@fr , @@ -305,7 +296,7 @@ midnam:update a lv2:Feature . units:unit units:midiNote ] , [ a lv2:InputPort, lv2:ControlPort ; - lv2:index 11 ; + lv2:index 10 ; lv2:symbol "tuning_frequency" ; lv2:name "Tuning frequency", "Fréquence d'accordage"@fr , @@ -317,7 +308,7 @@ midnam:update a lv2:Feature . units:unit units:hz ] , [ a lv2:InputPort, lv2:ControlPort ; - lv2:index 12 ; + lv2:index 11 ; lv2:symbol "stretched_tuning" ; lv2:name "Stretched tuning", "Accordage étiré"@fr , @@ -329,7 +320,7 @@ midnam:update a lv2:Feature . units:unit units:coef ] , [ a lv2:InputPort, lv2:ControlPort ; - lv2:index 13 ; + lv2:index 12 ; lv2:symbol "sample_quality" ; lv2:name "Sample quality", "Qualité des échantillons"@fr , @@ -340,7 +331,7 @@ midnam:update a lv2:Feature . lv2:maximum 10.0 ] , [ a lv2:InputPort, lv2:ControlPort ; - lv2:index 14 ; + lv2:index 13 ; lv2:symbol "oscillator_quality" ; lv2:name "Oscillator quality", "Qualité des oscillateurs"@fr , @@ -351,7 +342,7 @@ midnam:update a lv2:Feature . lv2:maximum 3.0 ] , [ a lv2:OutputPort, lv2:ControlPort ; - lv2:index 15 ; + lv2:index 14 ; lv2:symbol "active_voices" ; lv2:name "Active voices", "Voix utilisées"@fr ; @@ -362,7 +353,7 @@ midnam:update a lv2:Feature . lv2:maximum 256 ; ] , [ a lv2:OutputPort, lv2:ControlPort ; - lv2:index 16 ; + lv2:index 15 ; lv2:symbol "num_curves" ; lv2:name "Number of curves", "Nombre de courbes"@fr ; @@ -373,7 +364,7 @@ midnam:update a lv2:Feature . lv2:maximum 65535 ; ] , [ a lv2:OutputPort, lv2:ControlPort ; - lv2:index 17 ; + lv2:index 16 ; lv2:symbol "num_masters" ; lv2:name "Number of masters", "Nombre de maîtres"@fr ; @@ -384,7 +375,7 @@ midnam:update a lv2:Feature . lv2:maximum 65535 ; ] , [ a lv2:OutputPort, lv2:ControlPort ; - lv2:index 18 ; + lv2:index 17 ; lv2:symbol "num_groups" ; lv2:name "Number of groups", "Nombre de groupes"@fr ; @@ -395,7 +386,7 @@ midnam:update a lv2:Feature . lv2:maximum 65535 ; ] , [ a lv2:OutputPort, lv2:ControlPort ; - lv2:index 19 ; + lv2:index 18 ; lv2:symbol "num_regions" ; lv2:name "Number of regions", "Nombre de régions"@fr ; @@ -406,7 +397,7 @@ midnam:update a lv2:Feature . lv2:maximum 65535 ; ] , [ a lv2:OutputPort, lv2:ControlPort ; - lv2:index 20 ; + lv2:index 19 ; lv2:symbol "num_samples" ; lv2:name "Number of samples", "Nombre d'échantillons"@fr ; diff --git a/plugins/lv2/sfizz_lv2.h b/plugins/lv2/sfizz_lv2.h index dfc3a116..f48f2606 100644 --- a/plugins/lv2/sfizz_lv2.h +++ b/plugins/lv2/sfizz_lv2.h @@ -44,32 +44,32 @@ #define SFIZZ__checkModification SFIZZ_URI ":" "check_modification" // OSC atoms #define SFIZZ__OSCBlob SFIZZ_URI ":" "OSCBlob" +#define SFIZZ__Notify SFIZZ_URI ":" "Notify" // Level atoms #define SFIZZ__AudioLevel SFIZZ_URI ":" "AudioLevel" enum { SFIZZ_CONTROL = 0, - SFIZZ_NOTIFY = 1, - SFIZZ_AUTOMATE = 2, - SFIZZ_LEFT = 3, - SFIZZ_RIGHT = 4, - SFIZZ_VOLUME = 5, - SFIZZ_POLYPHONY = 6, - SFIZZ_OVERSAMPLING = 7, - SFIZZ_PRELOAD = 8, - SFIZZ_FREEWHEELING = 9, - SFIZZ_SCALA_ROOT_KEY = 10, - SFIZZ_TUNING_FREQUENCY = 11, - SFIZZ_STRETCH_TUNING = 12, - SFIZZ_SAMPLE_QUALITY = 13, - SFIZZ_OSCILLATOR_QUALITY = 14, - SFIZZ_ACTIVE_VOICES = 15, - SFIZZ_NUM_CURVES = 16, - SFIZZ_NUM_MASTERS = 17, - SFIZZ_NUM_GROUPS = 18, - SFIZZ_NUM_REGIONS = 19, - SFIZZ_NUM_SAMPLES = 20, + SFIZZ_AUTOMATE = 1, + SFIZZ_LEFT = 2, + SFIZZ_RIGHT = 3, + SFIZZ_VOLUME = 4, + SFIZZ_POLYPHONY = 5, + SFIZZ_OVERSAMPLING = 6, + SFIZZ_PRELOAD = 7, + SFIZZ_FREEWHEELING = 8, + SFIZZ_SCALA_ROOT_KEY = 9, + SFIZZ_TUNING_FREQUENCY = 10, + SFIZZ_STRETCH_TUNING = 11, + SFIZZ_SAMPLE_QUALITY = 12, + SFIZZ_OSCILLATOR_QUALITY = 13, + SFIZZ_ACTIVE_VOICES = 14, + SFIZZ_NUM_CURVES = 15, + SFIZZ_NUM_MASTERS = 16, + SFIZZ_NUM_GROUPS = 17, + SFIZZ_NUM_REGIONS = 18, + SFIZZ_NUM_SAMPLES = 19, }; // For use with instance-access diff --git a/plugins/lv2/sfizz_lv2_plugin.h b/plugins/lv2/sfizz_lv2_plugin.h index d9c4fe43..90387684 100644 --- a/plugins/lv2/sfizz_lv2_plugin.h +++ b/plugins/lv2/sfizz_lv2_plugin.h @@ -34,7 +34,6 @@ struct sfizz_plugin_t // Ports const LV2_Atom_Sequence *control_port {}; - LV2_Atom_Sequence *notify_port {}; LV2_Atom_Sequence *automate_port {}; float *output_buffers[2] {}; const float *volume_port {}; @@ -55,7 +54,6 @@ struct sfizz_plugin_t float *num_samples_port {}; // Atom forge - LV2_Atom_Forge forge_notify {}; ///< Forge for writing notification atoms in run thread LV2_Atom_Forge forge_automate {}; ///< Forge for writing automation atoms in run thread LV2_Atom_Forge forge_secondary {}; ///< Forge for writing into other buffers @@ -92,6 +90,7 @@ struct sfizz_plugin_t LV2_URID sfizz_check_modification_uri {}; LV2_URID sfizz_active_voices_uri {}; LV2_URID sfizz_osc_blob_uri {}; + LV2_URID sfizz_notify_uri {}; LV2_URID sfizz_audio_level_uri {}; LV2_URID time_position_uri {}; LV2_URID time_bar_uri {}; diff --git a/plugins/lv2/sfizz_ui.cpp b/plugins/lv2/sfizz_ui.cpp index bd943833..3756c7f8 100644 --- a/plugins/lv2/sfizz_ui.cpp +++ b/plugins/lv2/sfizz_ui.cpp @@ -116,6 +116,7 @@ struct sfizz_ui_t : EditorController, VSTGUIEditorInterface { LV2_URID sfizz_sfz_file_uri; LV2_URID sfizz_scala_file_uri; LV2_URID sfizz_osc_blob_uri; + LV2_URID sfizz_notify_uri; LV2_URID sfizz_audio_level_uri; std::unique_ptr ccmap; @@ -218,6 +219,7 @@ instantiate(const LV2UI_Descriptor *descriptor, self->sfizz_sfz_file_uri = map->map(map->handle, SFIZZ__sfzFile); self->sfizz_scala_file_uri = map->map(map->handle, SFIZZ__tuningfile); self->sfizz_osc_blob_uri = map->map(map->handle, SFIZZ__OSCBlob); + self->sfizz_notify_uri = map->map(map->handle, SFIZZ__Notify); self->sfizz_audio_level_uri = map->map(map->handle, SFIZZ__AudioLevel); self->ccmap.reset(sfizz_lv2_ccmap_create(map));