From 5dee49e194b054cb04bbb8a599e436503ed98530 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Sun, 11 Aug 2013 15:10:41 +0200 Subject: [PATCH 01/12] make LV2 communication buffers independent from jack-midi buffer-size fixes issues with plugin communication that are common with jack1 use due to its very small midi-buffers. --- libs/ardour/lv2_plugin.cc | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/libs/ardour/lv2_plugin.cc b/libs/ardour/lv2_plugin.cc index bfa593aea3..0d12998e9b 100644 --- a/libs/ardour/lv2_plugin.cc +++ b/libs/ardour/lv2_plugin.cc @@ -1137,8 +1137,20 @@ LV2Plugin::write_from_ui(uint32_t index, const uint8_t* body) { if (!_from_ui) { - _from_ui = new RingBuffer( - _session.engine().raw_buffer_size(DataType::MIDI) * NBUFS); + size_t rbs = _session.engine().raw_buffer_size(DataType::MIDI) * NBUFS; + /* buffer data communication from plugin UI to plugin instance. + * this buffer needs to potentially hold + * (port's minimumSize) * (audio-periods) / (UI-periods) + * bytes. + * + * e.g 48kSPS / 128fpp -> audio-periods = 375 Hz + * ui-periods = 25 Hz (SuperRapidScreenUpdate) + * default minimumSize = 32K (see LV2Plugin::allocate_atom_event_buffers() + * -> 15 * 32K + * it is safe to overflow (but the plugin state may be inconsistent). + */ + rbs = min(32768u * 6, rbs); + _from_ui = new RingBuffer(rbs); } if (!write_to(_from_ui, index, protocol, size, body)) { @@ -1165,8 +1177,10 @@ void LV2Plugin::enable_ui_emmission() { if (!_to_ui) { - _to_ui = new RingBuffer( - _session.engine().raw_buffer_size(DataType::MIDI) * NBUFS); + /* see note in LV2Plugin::write_from_ui() */ + size_t rbs = _session.engine().raw_buffer_size(DataType::MIDI) * NBUFS; + rbs = min(32768u * 8, rbs); + _to_ui = new RingBuffer(rbs); } } @@ -1901,7 +1915,7 @@ LV2Plugin::Impl::designated_input (const char* uri, void** bufptrs[], void** buf return port; } -static bool lv2_filter (const string& str, void *arg) +static bool lv2_filter (const string& str, void * /* arg*/) { /* Not a dotfile, has a prefix before a period, suffix is "lv2" */ From 116694a2cb993c03233eea4c33d605d45b3cb891 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Sun, 11 Aug 2013 17:19:04 +0200 Subject: [PATCH 02/12] fix 5dee49e19 (32/64 bit unsigned int compatibility) --- libs/ardour/lv2_plugin.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/ardour/lv2_plugin.cc b/libs/ardour/lv2_plugin.cc index 0d12998e9b..2d9d2c6dd1 100644 --- a/libs/ardour/lv2_plugin.cc +++ b/libs/ardour/lv2_plugin.cc @@ -1149,7 +1149,7 @@ LV2Plugin::write_from_ui(uint32_t index, * -> 15 * 32K * it is safe to overflow (but the plugin state may be inconsistent). */ - rbs = min(32768u * 6, rbs); + rbs = min((size_t) 32768 * 6, rbs); _from_ui = new RingBuffer(rbs); } @@ -1179,7 +1179,7 @@ LV2Plugin::enable_ui_emmission() if (!_to_ui) { /* see note in LV2Plugin::write_from_ui() */ size_t rbs = _session.engine().raw_buffer_size(DataType::MIDI) * NBUFS; - rbs = min(32768u * 8, rbs); + rbs = min((size_t) 32768 * 8, rbs); _to_ui = new RingBuffer(rbs); } } From 4c4376d5dd9ad4569ff9421ec8c8963b2a586fbd Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Sun, 11 Aug 2013 17:26:34 +0200 Subject: [PATCH 03/12] fix thinko in 5dee49e19 --- libs/ardour/lv2_plugin.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/ardour/lv2_plugin.cc b/libs/ardour/lv2_plugin.cc index 2d9d2c6dd1..219271a7e1 100644 --- a/libs/ardour/lv2_plugin.cc +++ b/libs/ardour/lv2_plugin.cc @@ -1149,7 +1149,7 @@ LV2Plugin::write_from_ui(uint32_t index, * -> 15 * 32K * it is safe to overflow (but the plugin state may be inconsistent). */ - rbs = min((size_t) 32768 * 6, rbs); + rbs = max((size_t) 32768 * 6, rbs); _from_ui = new RingBuffer(rbs); } @@ -1179,7 +1179,7 @@ LV2Plugin::enable_ui_emmission() if (!_to_ui) { /* see note in LV2Plugin::write_from_ui() */ size_t rbs = _session.engine().raw_buffer_size(DataType::MIDI) * NBUFS; - rbs = min((size_t) 32768 * 8, rbs); + rbs = max((size_t) 32768 * 8, rbs); _to_ui = new RingBuffer(rbs); } } From d51eba1162c072760a38d00bb39ee21749d87abb Mon Sep 17 00:00:00 2001 From: Tim Mayberry Date: Fri, 9 Aug 2013 20:41:58 +1000 Subject: [PATCH 04/12] Change ARDOUR::init return type to bool type for success/failure --- gtk2_ardour/ardour_ui.cc | 2 +- libs/ardour/ardour/ardour.h | 10 +++++++++- libs/ardour/globals.cc | 10 +++++----- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/gtk2_ardour/ardour_ui.cc b/gtk2_ardour/ardour_ui.cc index 97726cd7ae..86e838d122 100644 --- a/gtk2_ardour/ardour_ui.cc +++ b/gtk2_ardour/ardour_ui.cc @@ -291,7 +291,7 @@ ARDOUR_UI::ARDOUR_UI (int *argcp, char **argvp[], const char* localedir) /* lets get this party started */ try { - if (ARDOUR::init (ARDOUR_COMMAND_LINE::use_vst, ARDOUR_COMMAND_LINE::try_hw_optimization, localedir)) { + if (!ARDOUR::init (ARDOUR_COMMAND_LINE::use_vst, ARDOUR_COMMAND_LINE::try_hw_optimization, localedir)) { throw failed_constructor (); } diff --git a/libs/ardour/ardour/ardour.h b/libs/ardour/ardour/ardour.h index 5f64c4b6a3..eaf6b572fd 100644 --- a/libs/ardour/ardour/ardour.h +++ b/libs/ardour/ardour/ardour.h @@ -50,7 +50,15 @@ namespace ARDOUR { extern PBD::Signal1 BootMessage; extern PBD::Signal0 GUIIdle; - int init (bool with_vst, bool try_optimization, const char* localedir); + /** + * @param with_vst true to enable VST Support + * @param try_optimization true to enable hardware optimized routines + * for mixing, finding peak values etc. + * @param localedir Directory to look for localisation files + * + * @return true if Ardour library was successfully initialized + */ + bool init (bool with_vst, bool try_optimization, const char* localedir); void init_post_engine (); int cleanup (); bool no_auto_connect (); diff --git a/libs/ardour/globals.cc b/libs/ardour/globals.cc index 4c91956ffd..5e3553ad8a 100644 --- a/libs/ardour/globals.cc +++ b/libs/ardour/globals.cc @@ -215,7 +215,7 @@ lotsa_files_please () } } -int +bool ARDOUR::init (bool use_windows_vst, bool try_optimization, const char* localedir) { if (!Glib::thread_supported()) { @@ -269,7 +269,7 @@ ARDOUR::init (bool use_windows_vst, bool try_optimization, const char* localedir Config = new RCConfiguration; if (Config->load_state ()) { - return -1; + return false; } Config->set_use_windows_vst (use_windows_vst); @@ -282,13 +282,13 @@ ARDOUR::init (bool use_windows_vst, bool try_optimization, const char* localedir #ifdef WINDOWS_VST_SUPPORT if (Config->get_use_windows_vst() && fst_init (0)) { - return -1; + return false; } #endif #ifdef LXVST_SUPPORT if (Config->get_use_lxvst() && vstfx_init (0)) { - return -1; + return false; } #endif @@ -331,7 +331,7 @@ ARDOUR::init (bool use_windows_vst, bool try_optimization, const char* localedir EventTypeMap::instance().new_parameter(EnvelopeAutomation); EventTypeMap::instance().new_parameter(MidiCCAutomation); - return 0; + return true; } void From 9d340af10da0bdb4e20681918dac6dde987c8e5e Mon Sep 17 00:00:00 2001 From: Tim Mayberry Date: Thu, 25 Jul 2013 21:38:59 +1000 Subject: [PATCH 05/12] Prevent libardour from being initialized more than once This is not thread safe of course, it is not intended to be. This was implemented as at one stage ARDOUR::init was being called multiple times in the testsuite which was causing a subtle bug that took some time to track down. --- libs/ardour/globals.cc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libs/ardour/globals.cc b/libs/ardour/globals.cc index 5e3553ad8a..78994c4101 100644 --- a/libs/ardour/globals.cc +++ b/libs/ardour/globals.cc @@ -107,6 +107,8 @@ using namespace ARDOUR; using namespace std; using namespace PBD; +bool libardour_initialized = false; + compute_peak_t ARDOUR::compute_peak = 0; find_peaks_t ARDOUR::find_peaks = 0; apply_gain_to_buffer_t ARDOUR::apply_gain_to_buffer = 0; @@ -218,6 +220,10 @@ lotsa_files_please () bool ARDOUR::init (bool use_windows_vst, bool try_optimization, const char* localedir) { + if (libardour_initialized) { + return true; + } + if (!Glib::thread_supported()) { Glib::thread_init(); } @@ -331,6 +337,8 @@ ARDOUR::init (bool use_windows_vst, bool try_optimization, const char* localedir EventTypeMap::instance().new_parameter(EnvelopeAutomation); EventTypeMap::instance().new_parameter(MidiCCAutomation); + libardour_initialized = true; + return true; } From de4b24b162a2fccd6049d14eb092276fd2d4f849 Mon Sep 17 00:00:00 2001 From: Tim Mayberry Date: Fri, 9 Aug 2013 21:47:16 +1000 Subject: [PATCH 06/12] Move initialization of libardour from ARDOUR_UI class into main() --- gtk2_ardour/ardour_ui.cc | 17 +++-------------- gtk2_ardour/main.cc | 5 +++++ 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/gtk2_ardour/ardour_ui.cc b/gtk2_ardour/ardour_ui.cc index 86e838d122..e3e97d8d94 100644 --- a/gtk2_ardour/ardour_ui.cc +++ b/gtk2_ardour/ardour_ui.cc @@ -290,21 +290,10 @@ ARDOUR_UI::ARDOUR_UI (int *argcp, char **argvp[], const char* localedir) /* lets get this party started */ - try { - if (!ARDOUR::init (ARDOUR_COMMAND_LINE::use_vst, ARDOUR_COMMAND_LINE::try_hw_optimization, localedir)) { - throw failed_constructor (); - } + setup_gtk_ardour_enums (); + setup_profile (); - setup_gtk_ardour_enums (); - setup_profile (); - - SessionEvent::create_per_thread_pool ("GUI", 512); - - } catch (failed_constructor& err) { - error << string_compose (_("could not initialize %1."), PROGRAM_NAME) << endmsg; - // pass it on up - throw; - } + SessionEvent::create_per_thread_pool ("GUI", 512); /* we like keyboards */ diff --git a/gtk2_ardour/main.cc b/gtk2_ardour/main.cc index 21e5343979..2e5d87b598 100644 --- a/gtk2_ardour/main.cc +++ b/gtk2_ardour/main.cc @@ -515,6 +515,11 @@ int main (int argc, char *argv[]) PBD::ID::init (); + if (!ARDOUR::init (ARDOUR_COMMAND_LINE::use_vst, ARDOUR_COMMAND_LINE::try_hw_optimization, localedir)) { + error << string_compose (_("could not initialize %1."), PROGRAM_NAME) << endmsg; + exit (1); + } + if (::signal (SIGPIPE, sigpipe_handler)) { cerr << _("Cannot xinstall SIGPIPE error handler") << endl; } From 29193c76ccb2cdead8ee31b753945b6080994956 Mon Sep 17 00:00:00 2001 From: Tim Mayberry Date: Fri, 9 Aug 2013 22:03:39 +1000 Subject: [PATCH 07/12] Add PBD::init and PBD::cleanup A bit of refactoring to move initialization of libpbd into libpbd rather than rely on "client" code(ui,libardour,tests etc) to do it --- libs/pbd/pbd.cc | 59 ++++++++++++++++++++++++++++++++++++++++++++++ libs/pbd/pbd/pbd.h | 30 +++++++++++++++++++++++ libs/pbd/wscript | 1 + 3 files changed, 90 insertions(+) create mode 100644 libs/pbd/pbd.cc create mode 100644 libs/pbd/pbd/pbd.h diff --git a/libs/pbd/pbd.cc b/libs/pbd/pbd.cc new file mode 100644 index 0000000000..58c8440a0f --- /dev/null +++ b/libs/pbd/pbd.cc @@ -0,0 +1,59 @@ +/* + Copyright (C) 2011 Paul Davis + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include +#include + +#include + +#include "pbd/pbd.h" +#include "pbd/debug.h" +#include "pbd/id.h" +#include "pbd/enumwriter.h" + +#include "i18n.h" + +namespace { + +static bool libpbd_initialized = false; + +} + +bool +PBD::init () +{ + if (libpbd_initialized) { + return true; + } + + if (!Glib::thread_supported()) { + Glib::thread_init(); + } + + PBD::ID::init (); + + libpbd_initialized = true; + return true; +} + +void +PBD::cleanup () +{ + EnumWriter::destroy (); +} diff --git a/libs/pbd/pbd/pbd.h b/libs/pbd/pbd/pbd.h new file mode 100644 index 0000000000..5b3745f0ed --- /dev/null +++ b/libs/pbd/pbd/pbd.h @@ -0,0 +1,30 @@ +/* + Copyright (C) 2011 Paul Davis + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#ifndef __libpbd_pbd_h__ +#define __libpbd_pbd_h__ + +namespace PBD { + + bool init (); + void cleanup (); + +} // namespace PBD + +#endif diff --git a/libs/pbd/wscript b/libs/pbd/wscript index 0655e1ca48..ffbe0e0d19 100644 --- a/libs/pbd/wscript +++ b/libs/pbd/wscript @@ -56,6 +56,7 @@ libpbd_sources = [ 'openuri.cc', 'pathexpand.cc', 'pathscanner.cc', + 'pbd.cc', 'pool.cc', 'property_list.cc', 'pthread_utils.cc', From 55c6d4f2be0335a5be7d2773924fade7aaee39b4 Mon Sep 17 00:00:00 2001 From: Tim Mayberry Date: Fri, 9 Aug 2013 22:11:44 +1000 Subject: [PATCH 08/12] Call PBD::init in ARDOUR::init and PBD::cleanup in ARDOUR::cleanup --- libs/ardour/globals.cc | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/libs/ardour/globals.cc b/libs/ardour/globals.cc index 78994c4101..0941b72de8 100644 --- a/libs/ardour/globals.cc +++ b/libs/ardour/globals.cc @@ -60,6 +60,7 @@ #include "pbd/cpus.h" #include "pbd/error.h" #include "pbd/id.h" +#include "pbd/pbd.h" #include "pbd/strsplit.h" #include "pbd/fpu.h" #include "pbd/file_utils.h" @@ -224,9 +225,7 @@ ARDOUR::init (bool use_windows_vst, bool try_optimization, const char* localedir return true; } - if (!Glib::thread_supported()) { - Glib::thread_init(); - } + if (!PBD::init()) return false; // this really should be in PBD::init..if there was one Gio::init (); @@ -235,7 +234,6 @@ ARDOUR::init (bool use_windows_vst, bool try_optimization, const char* localedir (void) bindtextdomain(PACKAGE, localedir); #endif - PBD::ID::init (); SessionEvent::init_event_pool (); SessionObject::make_property_quarks (); @@ -373,7 +371,7 @@ ARDOUR::cleanup () #ifdef LXVST_SUPPORT vstfx_exit(); #endif - EnumWriter::destroy (); + PBD::cleanup (); return 0; } From 1db894f8865bfc8eacfccf623f8d8c458bf87fd8 Mon Sep 17 00:00:00 2001 From: Tim Mayberry Date: Fri, 9 Aug 2013 22:13:50 +1000 Subject: [PATCH 09/12] Call Gio::init from PBD::init instead of ARDOUR::init PBD needs Gio for PBD::copy_file and perhaps others --- libs/ardour/globals.cc | 5 ----- libs/pbd/pbd.cc | 4 ++++ 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/libs/ardour/globals.cc b/libs/ardour/globals.cc index 0941b72de8..986d320aef 100644 --- a/libs/ardour/globals.cc +++ b/libs/ardour/globals.cc @@ -50,8 +50,6 @@ #undef check /* stupid Apple and their un-namespaced, generic Carbon macros */ #endif -#include - #include #include @@ -227,9 +225,6 @@ ARDOUR::init (bool use_windows_vst, bool try_optimization, const char* localedir if (!PBD::init()) return false; - // this really should be in PBD::init..if there was one - Gio::init (); - #ifdef ENABLE_NLS (void) bindtextdomain(PACKAGE, localedir); #endif diff --git a/libs/pbd/pbd.cc b/libs/pbd/pbd.cc index 58c8440a0f..dd33f3103b 100644 --- a/libs/pbd/pbd.cc +++ b/libs/pbd/pbd.cc @@ -20,6 +20,8 @@ #include #include +#include + #include #include "pbd/pbd.h" @@ -46,6 +48,8 @@ PBD::init () Glib::thread_init(); } + Gio::init (); + PBD::ID::init (); libpbd_initialized = true; From 63745512bc720ae7c4146b031ec02e2b3fafc86f Mon Sep 17 00:00:00 2001 From: Tim Mayberry Date: Fri, 26 Jul 2013 12:04:40 +1000 Subject: [PATCH 10/12] Call setup_libpbd_enums in PBD::init for portability --- libs/pbd/enums.cc | 2 -- libs/pbd/pbd.cc | 4 ++++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/libs/pbd/enums.cc b/libs/pbd/enums.cc index 7081503cb1..87e8da4b71 100644 --- a/libs/pbd/enums.cc +++ b/libs/pbd/enums.cc @@ -20,8 +20,6 @@ #include "pbd/controllable.h" #include "pbd/enumwriter.h" -void setup_libpbd_enums () __attribute__ ((constructor)); - using namespace PBD; using namespace std; diff --git a/libs/pbd/pbd.cc b/libs/pbd/pbd.cc index dd33f3103b..1bf977c90a 100644 --- a/libs/pbd/pbd.cc +++ b/libs/pbd/pbd.cc @@ -31,6 +31,8 @@ #include "i18n.h" +extern void setup_libpbd_enums (); + namespace { static bool libpbd_initialized = false; @@ -52,6 +54,8 @@ PBD::init () PBD::ID::init (); + setup_libpbd_enums (); + libpbd_initialized = true; return true; } From 611058bf5863fd0d34362a20a9ce997092aeed23 Mon Sep 17 00:00:00 2001 From: Tim Mayberry Date: Sat, 10 Aug 2013 12:07:39 +1000 Subject: [PATCH 11/12] Remove call to PBD::ID::init as it is now done via ARDOUR::init --- gtk2_ardour/main.cc | 2 -- 1 file changed, 2 deletions(-) diff --git a/gtk2_ardour/main.cc b/gtk2_ardour/main.cc index 2e5d87b598..84cd696af1 100644 --- a/gtk2_ardour/main.cc +++ b/gtk2_ardour/main.cc @@ -513,8 +513,6 @@ int main (int argc, char *argv[]) /* some GUI objects need this */ - PBD::ID::init (); - if (!ARDOUR::init (ARDOUR_COMMAND_LINE::use_vst, ARDOUR_COMMAND_LINE::try_hw_optimization, localedir)) { error << string_compose (_("could not initialize %1."), PROGRAM_NAME) << endmsg; exit (1); From 7a431f892ec6e7e2283885c474b680081c983762 Mon Sep 17 00:00:00 2001 From: Tim Mayberry Date: Sat, 10 Aug 2013 12:08:45 +1000 Subject: [PATCH 12/12] Move curve test file handling in main() until after ARDOUR::init is called This means it doesn't need to call PBD::ID::init directly, which it now shouldn't be doing --- gtk2_ardour/curvetest.cc | 5 ----- gtk2_ardour/main.cc | 8 ++++---- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/gtk2_ardour/curvetest.cc b/gtk2_ardour/curvetest.cc index b3431e3f39..818a010f1d 100644 --- a/gtk2_ardour/curvetest.cc +++ b/gtk2_ardour/curvetest.cc @@ -32,11 +32,6 @@ using namespace PBD; int curvetest (string filename) { - // needed to initialize ID objects/counter used - // by Curve et al. - - PBD::ID::init (); - ifstream in (filename.c_str()); stringstream line; //Evoral::Parameter param(GainAutomation, -1.0, +1.0, 0.0); diff --git a/gtk2_ardour/main.cc b/gtk2_ardour/main.cc index 84cd696af1..e619c9d83b 100644 --- a/gtk2_ardour/main.cc +++ b/gtk2_ardour/main.cc @@ -482,10 +482,6 @@ int main (int argc, char *argv[]) exit (1); } - if (curvetest_file) { - return curvetest (curvetest_file); - } - cout << PROGRAM_NAME << VERSIONSTRING << _(" (built using ") @@ -518,6 +514,10 @@ int main (int argc, char *argv[]) exit (1); } + if (curvetest_file) { + return curvetest (curvetest_file); + } + if (::signal (SIGPIPE, sigpipe_handler)) { cerr << _("Cannot xinstall SIGPIPE error handler") << endl; }