From cb5b955a742f1842d075868e50d1d526f700382d Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Sat, 20 Jul 2024 17:36:02 +0200 Subject: [PATCH 1/6] Use C++ for LV2 event buffer This will allow to throw fatal exceptions when malloc fails. --- libs/ardour/ardour/buffer_set.h | 3 +- libs/ardour/{ => ardour}/lv2_evbuf.h | 15 ++----- libs/ardour/ardour/lv2_plugin.h | 2 +- libs/ardour/buffer_set.cc | 2 +- libs/ardour/{lv2_evbuf.c => lv2_evbuf.cc} | 54 ++++++++++++----------- libs/ardour/lv2_plugin.cc | 3 +- libs/ardour/wscript | 2 +- 7 files changed, 37 insertions(+), 44 deletions(-) rename libs/ardour/{ => ardour}/lv2_evbuf.h (94%) rename libs/ardour/{lv2_evbuf.c => lv2_evbuf.cc} (75%) diff --git a/libs/ardour/ardour/buffer_set.h b/libs/ardour/ardour/buffer_set.h index a791ad2406..95b40958f5 100644 --- a/libs/ardour/ardour/buffer_set.h +++ b/libs/ardour/ardour/buffer_set.h @@ -41,7 +41,6 @@ struct _VstMidiEvent; typedef struct _VstMidiEvent VstMidiEvent; #endif -typedef struct LV2_Evbuf_Impl LV2_Evbuf; namespace ARDOUR { @@ -50,6 +49,8 @@ class AudioBuffer; class MidiBuffer; class PortSet; +struct LV2_Evbuf; + /** A set of buffers of various types. * * These are mainly accessed from Session and passed around as scratch buffers diff --git a/libs/ardour/lv2_evbuf.h b/libs/ardour/ardour/lv2_evbuf.h similarity index 94% rename from libs/ardour/lv2_evbuf.h rename to libs/ardour/ardour/lv2_evbuf.h index 61f6b88909..d86f1c274f 100644 --- a/libs/ardour/lv2_evbuf.h +++ b/libs/ardour/ardour/lv2_evbuf.h @@ -14,21 +14,16 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifndef LV2_EVBUF_H -#define LV2_EVBUF_H +#pragma once #include -#ifdef __cplusplus -extern "C" { -#else -#include -#endif +namespace ARDOUR { /** An abstract/opaque LV2 event buffer. */ -typedef struct LV2_Evbuf_Impl LV2_Evbuf; +struct LV2_Evbuf; /** An iterator over an LV2_Evbuf. @@ -140,8 +135,4 @@ lv2_evbuf_write(LV2_Evbuf_Iterator* iter, uint32_t size, const uint8_t* data); -#ifdef __cplusplus } -#endif - -#endif /* LV2_EVBUF_H */ diff --git a/libs/ardour/ardour/lv2_plugin.h b/libs/ardour/ardour/lv2_plugin.h index c437ac79e8..0c006787dd 100644 --- a/libs/ardour/ardour/lv2_plugin.h +++ b/libs/ardour/ardour/lv2_plugin.h @@ -46,7 +46,6 @@ #define PATH_MAX 1024 #endif -typedef struct LV2_Evbuf_Impl LV2_Evbuf; namespace ARDOUR { @@ -59,6 +58,7 @@ const void* lv2plugin_get_port_value(const char* port_symbol, class AudioEngine; class Session; +struct LV2_Evbuf; class LIBARDOUR_API LV2Plugin : public ARDOUR::Plugin, public ARDOUR::Workee { diff --git a/libs/ardour/buffer_set.cc b/libs/ardour/buffer_set.cc index 3aa3a7333c..9f5a5a12bf 100644 --- a/libs/ardour/buffer_set.cc +++ b/libs/ardour/buffer_set.cc @@ -38,7 +38,7 @@ #include "ardour/port.h" #include "ardour/port_set.h" #include "ardour/lv2_plugin.h" -#include "lv2_evbuf.h" +#include "ardour/lv2_evbuf.h" #include "ardour/uri_map.h" #if defined WINDOWS_VST_SUPPORT || defined LXVST_SUPPORT || defined MACVST_SUPPORT #include "ardour/vestige/vestige.h" diff --git a/libs/ardour/lv2_evbuf.c b/libs/ardour/lv2_evbuf.cc similarity index 75% rename from libs/ardour/lv2_evbuf.c rename to libs/ardour/lv2_evbuf.cc index 337a18e4a2..8681ec7e60 100644 --- a/libs/ardour/lv2_evbuf.c +++ b/libs/ardour/lv2_evbuf.cc @@ -26,9 +26,11 @@ #include #endif -#include "lv2_evbuf.h" +#include "ardour/lv2_evbuf.h" -struct LV2_Evbuf_Impl { +using namespace ARDOUR; + +struct ARDOUR::LV2_Evbuf { uint32_t capacity; uint32_t atom_Chunk; uint32_t atom_Sequence; @@ -42,9 +44,9 @@ lv2_evbuf_pad_size(uint32_t size) } LV2_Evbuf* -lv2_evbuf_new(uint32_t capacity, - uint32_t atom_Chunk, - uint32_t atom_Sequence) +ARDOUR::lv2_evbuf_new (uint32_t capacity, + uint32_t atom_Chunk, + uint32_t atom_Sequence) { // FIXME: memory must be 64-bit aligned LV2_Evbuf* evbuf = (LV2_Evbuf*)malloc( @@ -57,13 +59,13 @@ lv2_evbuf_new(uint32_t capacity, } void -lv2_evbuf_free(LV2_Evbuf* evbuf) +ARDOUR::lv2_evbuf_free (LV2_Evbuf* evbuf) { free(evbuf); } void -lv2_evbuf_reset(LV2_Evbuf* evbuf, bool input) +ARDOUR::lv2_evbuf_reset (LV2_Evbuf* evbuf, bool input) { if (input) { evbuf->atom.atom.size = sizeof(LV2_Atom_Sequence_Body); @@ -75,7 +77,7 @@ lv2_evbuf_reset(LV2_Evbuf* evbuf, bool input) } uint32_t -lv2_evbuf_get_size(LV2_Evbuf* evbuf) +ARDOUR::lv2_evbuf_get_size (LV2_Evbuf* evbuf) { assert(evbuf->atom.atom.type != evbuf->atom_Sequence || evbuf->atom.atom.size >= sizeof(LV2_Atom_Sequence_Body)); @@ -86,26 +88,26 @@ lv2_evbuf_get_size(LV2_Evbuf* evbuf) } uint32_t -lv2_evbuf_get_capacity(LV2_Evbuf* evbuf) +ARDOUR::lv2_evbuf_get_capacity (LV2_Evbuf* evbuf) { return evbuf->capacity; } void* -lv2_evbuf_get_buffer(LV2_Evbuf* evbuf) +ARDOUR::lv2_evbuf_get_buffer (LV2_Evbuf* evbuf) { return &evbuf->atom; } LV2_Evbuf_Iterator -lv2_evbuf_begin(LV2_Evbuf* evbuf) +ARDOUR::lv2_evbuf_begin (LV2_Evbuf* evbuf) { LV2_Evbuf_Iterator iter = { evbuf, 0 }; return iter; } LV2_Evbuf_Iterator -lv2_evbuf_end(LV2_Evbuf* evbuf) +ARDOUR::lv2_evbuf_end (LV2_Evbuf* evbuf) { const uint32_t size = lv2_evbuf_get_size(evbuf); const LV2_Evbuf_Iterator iter = { evbuf, lv2_evbuf_pad_size(size) }; @@ -113,13 +115,13 @@ lv2_evbuf_end(LV2_Evbuf* evbuf) } bool -lv2_evbuf_is_valid(LV2_Evbuf_Iterator iter) +ARDOUR::lv2_evbuf_is_valid(LV2_Evbuf_Iterator iter) { return iter.offset < lv2_evbuf_get_size(iter.evbuf); } LV2_Evbuf_Iterator -lv2_evbuf_next(LV2_Evbuf_Iterator iter) +ARDOUR::lv2_evbuf_next (LV2_Evbuf_Iterator iter) { if (!lv2_evbuf_is_valid(iter)) { return iter; @@ -140,12 +142,12 @@ lv2_evbuf_next(LV2_Evbuf_Iterator iter) } bool -lv2_evbuf_get(LV2_Evbuf_Iterator iter, - uint32_t* samples, - uint32_t* subframes, - uint32_t* type, - uint32_t* size, - uint8_t** data) +ARDOUR::lv2_evbuf_get (LV2_Evbuf_Iterator iter, + uint32_t* samples, + uint32_t* subframes, + uint32_t* type, + uint32_t* size, + uint8_t** data) { *samples = *subframes = *type = *size = 0; *data = NULL; @@ -168,12 +170,12 @@ lv2_evbuf_get(LV2_Evbuf_Iterator iter, } bool -lv2_evbuf_write(LV2_Evbuf_Iterator* iter, - uint32_t samples, - uint32_t subframes, - uint32_t type, - uint32_t size, - const uint8_t* data) +ARDOUR::lv2_evbuf_write (LV2_Evbuf_Iterator* iter, + uint32_t samples, + uint32_t subframes, + uint32_t type, + uint32_t size, + const uint8_t* data) { LV2_Atom_Sequence* aseq = (LV2_Atom_Sequence*)&iter->evbuf->atom; diff --git a/libs/ardour/lv2_plugin.cc b/libs/ardour/lv2_plugin.cc index 489604ed4d..f332c70c5b 100644 --- a/libs/ardour/lv2_plugin.cc +++ b/libs/ardour/lv2_plugin.cc @@ -64,6 +64,7 @@ #include "ardour/audioengine.h" #include "ardour/directory_names.h" #include "ardour/debug.h" +#include "ardour/lv2_evbuf.h" #include "ardour/lv2_plugin.h" #include "ardour/midi_patch_manager.h" #include "ardour/session.h" @@ -116,8 +117,6 @@ #include #endif -#include "lv2_evbuf.h" - #ifdef HAVE_SUIL #include #endif diff --git a/libs/ardour/wscript b/libs/ardour/wscript index bb52ce4379..1ca9653a6a 100644 --- a/libs/ardour/wscript +++ b/libs/ardour/wscript @@ -435,7 +435,7 @@ def build(bld): #obj.add_objects = 'default/libs/surfaces/control_protocol/smpte_1.o' if bld.is_defined('HAVE_LILV') : - obj.source += ['lv2_plugin.cc', 'lv2_evbuf.c', 'uri_map.cc'] + obj.source += ['lv2_plugin.cc', 'lv2_evbuf.cc', 'uri_map.cc'] obj.uselib += ['LILV'] if bld.is_defined('HAVE_SUIL'): if bld.is_defined('YTK'): From 8c583f8e20c6a050055154231f4280b007528b85 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Sat, 20 Jul 2024 16:41:41 +0200 Subject: [PATCH 2/6] Use 64bit alignment for LV2 event buffer #9748 --- libs/ardour/lv2_evbuf.cc | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/libs/ardour/lv2_evbuf.cc b/libs/ardour/lv2_evbuf.cc index 8681ec7e60..816f383963 100644 --- a/libs/ardour/lv2_evbuf.cc +++ b/libs/ardour/lv2_evbuf.cc @@ -26,6 +26,7 @@ #include #endif +#include "pbd/malign.h" #include "ardour/lv2_evbuf.h" using namespace ARDOUR; @@ -48,9 +49,16 @@ ARDOUR::lv2_evbuf_new (uint32_t capacity, uint32_t atom_Chunk, uint32_t atom_Sequence) { - // FIXME: memory must be 64-bit aligned - LV2_Evbuf* evbuf = (LV2_Evbuf*)malloc( - sizeof(LV2_Evbuf) + sizeof(LV2_Atom_Sequence) + capacity); + LV2_Evbuf* evbuf; + + int err = cache_aligned_malloc ((void**) &evbuf, sizeof(LV2_Evbuf) + sizeof(LV2_Atom_Sequence) + capacity); + + if (err) { + //fatal << string_compose (_("Memory allocation error: (%1)"), strerror (err)) << endmsg; + abort (); + return 0; + } + evbuf->capacity = capacity; evbuf->atom_Chunk = atom_Chunk; evbuf->atom_Sequence = atom_Sequence; @@ -61,7 +69,7 @@ ARDOUR::lv2_evbuf_new (uint32_t capacity, void ARDOUR::lv2_evbuf_free (LV2_Evbuf* evbuf) { - free(evbuf); + cache_aligned_free (evbuf); } void From 75678841117b39b267fbe8680ce1c2bc0518fc3a Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Sat, 20 Jul 2024 21:39:45 +0200 Subject: [PATCH 3/6] Fix LV2 Atom sequence alignment #9750 --- libs/ardour/lv2_evbuf.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/ardour/lv2_evbuf.cc b/libs/ardour/lv2_evbuf.cc index 816f383963..3d609d57e7 100644 --- a/libs/ardour/lv2_evbuf.cc +++ b/libs/ardour/lv2_evbuf.cc @@ -35,6 +35,7 @@ struct ARDOUR::LV2_Evbuf { uint32_t capacity; uint32_t atom_Chunk; uint32_t atom_Sequence; + uint32_t pad; // for 8byte alignment LV2_Atom_Sequence atom; }; From bb8f6a3d669aaf2eddd47a06074aecfe54f3c186 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Mon, 22 Jul 2024 20:28:45 +0200 Subject: [PATCH 4/6] Remove debug output --- libs/ardour/session.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc index 06ef96cfbd..fb838e483d 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -4923,7 +4923,6 @@ Session::remove_source (std::weak_ptr src, bool drop_references) SourceRemoved (src); /* EMIT SIGNAL */ if (drop_references) { - printf ("Source->drop_references!\n"); source->drop_references (); /* Removing a Source cannot be undone. * We need to clear all undo commands that reference the From 181ba4db54142da65e5b500ff8763b788d109f3a Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Mon, 22 Jul 2024 15:36:45 -0600 Subject: [PATCH 5/6] ytk: do not show filter combo box in filechooser if there is only 1 filter --- libs/tk/ytk/gtkfilechooserdefault.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/tk/ytk/gtkfilechooserdefault.c b/libs/tk/ytk/gtkfilechooserdefault.c index cf86b6ab86..ce9802cf62 100644 --- a/libs/tk/ytk/gtkfilechooserdefault.c +++ b/libs/tk/ytk/gtkfilechooserdefault.c @@ -7744,7 +7744,7 @@ static void show_filters (GtkFileChooserDefault *impl, gboolean show) { - if (show) + if (show && impl->filters && g_slist_length (impl->filters) > 1) gtk_widget_show (impl->filter_combo_hbox); else gtk_widget_hide (impl->filter_combo_hbox); From 607301ad5b0d114472aca2a407326776fb5ab7e7 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Mon, 22 Jul 2024 15:37:07 -0600 Subject: [PATCH 6/6] LT: remove many elements from import dialog that are not appropriate for livetrax --- gtk2_ardour/sfdb_ui.cc | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/gtk2_ardour/sfdb_ui.cc b/gtk2_ardour/sfdb_ui.cc index c9a9c8757c..52731fc6d9 100644 --- a/gtk2_ardour/sfdb_ui.cc +++ b/gtk2_ardour/sfdb_ui.cc @@ -696,11 +696,13 @@ SoundFileBrowser::SoundFileBrowser (string title, ARDOUR::Session* s, bool persi chooser.set_border_width (12); - audio_and_midi_filter.add_custom (FILE_FILTER_FILENAME, sigc::mem_fun (*this, &SoundFileBrowser::on_audio_and_midi_filter)); - audio_and_midi_filter.set_name (_("Audio and MIDI files")); - audio_filter.add_custom (FILE_FILTER_FILENAME, sigc::mem_fun(*this, &SoundFileBrowser::on_audio_filter)); audio_filter.set_name (_("Audio files")); + chooser.add_filter (audio_filter); + +#ifndef LIVETRAX + audio_and_midi_filter.add_custom (FILE_FILTER_FILENAME, sigc::mem_fun (*this, &SoundFileBrowser::on_audio_and_midi_filter)); + audio_and_midi_filter.set_name (_("Audio and MIDI files")); midi_filter.add_custom (FILE_FILTER_FILENAME, sigc::mem_fun(*this, &SoundFileBrowser::on_midi_filter)); midi_filter.set_name (_("MIDI files")); @@ -709,9 +711,9 @@ SoundFileBrowser::SoundFileBrowser (string title, ARDOUR::Session* s, bool persi matchall_filter.set_name (_("All files")); chooser.add_filter (audio_and_midi_filter); - chooser.add_filter (audio_filter); chooser.add_filter (midi_filter); chooser.add_filter (matchall_filter); +#endif chooser.set_select_multiple (true); chooser.signal_update_preview().connect(sigc::mem_fun(*this, &SoundFileBrowser::update_preview)); chooser.signal_file_activated().connect (sigc::mem_fun (*this, &SoundFileBrowser::chooser_file_activated)); @@ -736,6 +738,7 @@ SoundFileBrowser::SoundFileBrowser (string title, ARDOUR::Session* s, bool persi add (vpacker); +#ifndef LIVETRAX //add tag search VBox* vbox; @@ -870,6 +873,7 @@ SoundFileBrowser::SoundFileBrowser (string title, ARDOUR::Session* s, bool persi freesound_more_btn.signal_clicked().connect(sigc::mem_fun(*this, &SoundFileBrowser::freesound_more_clicked)); freesound_similar_btn.signal_clicked().connect(sigc::mem_fun(*this, &SoundFileBrowser::freesound_similar_clicked)); notebook.append_page (*vbox, _("Search Freesound")); +#endif notebook.set_size_request (500, -1); notebook.signal_switch_page().connect (sigc::hide_return (sigc::hide (sigc::hide (sigc::mem_fun (*this, &SoundFileBrowser::reset_options))))); @@ -1945,6 +1949,7 @@ SoundFileOmega::SoundFileOmega (string title, ARDOUR::Session* s, vspace->set_size_request (16, 2); options.attach (*vspace, 2, 3, 6, 7, SHRINK, SHRINK, 0, 0); +#ifndef LIVETRAX l = manage (new Label); l->set_markup (_("MIDI Instrument:")); l->set_alignment(Gtk::ALIGN_END, Gtk::ALIGN_CENTER); @@ -1956,7 +1961,7 @@ SoundFileOmega::SoundFileOmega (string title, ARDOUR::Session* s, l->set_alignment(Gtk::ALIGN_END, Gtk::ALIGN_CENTER); options.attach (*l, 3, 4, 1, 2, FILL, SHRINK, 4, 0); options.attach (midi_track_name_combo, 4, 5, 1, 2, FILL, SHRINK, 2, 0); - +#endif options.attach (smf_tempo_btn, 4, 5, 2, 3, FILL, SHRINK, 2, 0); options.attach (smf_marker_btn, 4, 5, 3, 4, FILL, SHRINK, 2, 0);