From 0c2494595db708b668c49536445e112237c33714 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Sat, 7 Dec 2013 18:04:31 +0100 Subject: [PATCH 01/13] detect VST >= 2.4 plugins. --- libs/ardour/linux_vst_support.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libs/ardour/linux_vst_support.cc b/libs/ardour/linux_vst_support.cc index 1fccf79968..e141717f3e 100644 --- a/libs/ardour/linux_vst_support.cc +++ b/libs/ardour/linux_vst_support.cc @@ -242,7 +242,9 @@ vstfx_load (const char *path) /*Find the main entry point into the plugin*/ - if ((fhandle->main_entry = (main_entry_t) dlsym(fhandle->dll, "main")) == 0) + if ((fhandle->main_entry = (main_entry_t) dlsym(fhandle->dll, "main")) == 0 && + (fhandle->main_entry = (main_entry_t) dlsym(fhandle->dll, "VSTPluginMain")) == 0 + ) { /*If it can't be found, unload the plugin and return a 0 handle*/ From bbd79b6792cb6113eac417a4c8a099fa32bc2788 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Sat, 7 Dec 2013 18:45:40 +0100 Subject: [PATCH 02/13] print a warning for every VST >=2.4 plugin 17:29 < rgareus> las: ok. I'll make this translatable, but this warning will show up every time ardour starts (and scans for plugins) which can be annoying. 17:30 < las> rgareus: yeah, well we need to do black/whitelisting of plugins anyway so ... --- libs/ardour/linux_vst_support.cc | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/libs/ardour/linux_vst_support.cc b/libs/ardour/linux_vst_support.cc index e141717f3e..9d36905f48 100644 --- a/libs/ardour/linux_vst_support.cc +++ b/libs/ardour/linux_vst_support.cc @@ -242,9 +242,15 @@ vstfx_load (const char *path) /*Find the main entry point into the plugin*/ - if ((fhandle->main_entry = (main_entry_t) dlsym(fhandle->dll, "main")) == 0 && - (fhandle->main_entry = (main_entry_t) dlsym(fhandle->dll, "VSTPluginMain")) == 0 - ) + fhandle->main_entry = (main_entry_t) dlsym(fhandle->dll, "main"); + + if (fhandle->main_entry == 0) { + if ((fhandle->main_entry = (main_entry_t) dlsym(fhandle->dll, "VSTPluginMain")) != 0) { + PBD::warning << path << _(": is a VST >= 2.4 - this plugin may or may not function correctly with this version of Ardour.") << endmsg; + } + } + + if (fhandle->main_entry == 0) { /*If it can't be found, unload the plugin and return a 0 handle*/ From b4cb506ceaae9254fa5e6fd25b4d936daa826712 Mon Sep 17 00:00:00 2001 From: Nils Philippsen Date: Sat, 9 Nov 2013 10:54:47 +0100 Subject: [PATCH 03/13] improve architecture detection Recognize ppc64, ppc, s390x, s390 CPUs, default to 'none' instead of i686 (which tries to build with SSE and fails on non-x86 architectures). --- wscript | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/wscript b/wscript index 99bd46ddef..13060707ea 100644 --- a/wscript +++ b/wscript @@ -182,16 +182,15 @@ def set_compiler_flags (conf,opt): else: conf.env['build_target'] = 'mountainlion' else: - if re.search ("x86_64", cpu) != None: - conf.env['build_target'] = 'x86_64' - elif re.search("i[0-5]86", cpu) != None: - conf.env['build_target'] = 'i386' - elif re.search("powerpc", cpu) != None: - conf.env['build_target'] = 'powerpc' - elif re.search("arm", cpu) != None: - conf.env['build_target'] = 'arm' + match = re.search( + "(?Pi[0-6]86|x86_64|powerpc|ppc|ppc64|arm|s390x?)", + cpu) + if (match): + conf.env['build_target'] = match.group("cpu") + if re.search("i[0-5]86", conf.env['build_target']): + conf.env['build_target'] = "i386" else: - conf.env['build_target'] = 'i686' + conf.env['build_target'] = 'none' else: conf.env['build_target'] = opt.dist_target From cd7072fdec5073a1b462f8fbe63b64b023333e99 Mon Sep 17 00:00:00 2001 From: Nils Philippsen Date: Mon, 9 Dec 2013 17:33:45 +0100 Subject: [PATCH 04/13] don't overwrite necessary compiler flags Distinguish flags influencing optimization (overridable) from those necessary for building (e.g. for using SSE). --- wscript | 156 +++++++++++++++++++++++++------------------------------- 1 file changed, 70 insertions(+), 86 deletions(-) diff --git a/wscript b/wscript index 13060707ea..e68780f1e0 100644 --- a/wscript +++ b/wscript @@ -132,7 +132,17 @@ def set_compiler_flags (conf,opt): # build_host_supports_sse = False + + # Flags necessary for building + compiler_flags = [] # generic + c_flags = [] # C-specific + cxx_flags = [] # C++-specific + linker_flags = [] + + # Optimization flags (overridable) optimization_flags = [] + + # Debugging flags debug_flags = [] u = os.uname () @@ -145,10 +155,10 @@ def set_compiler_flags (conf,opt): if conf.options.cxx11: conf.check_cxx(cxxflags=["-std=c++11"]) - conf.env.append_unique('CXXFLAGS', ['-std=c++11']) + cxx_flags.append('-std=c++11') if platform == "darwin": - conf.env.append_unique('CXXFLAGS', ['-stdlib=libc++']) - conf.env.append_unique('LINKFLAGS', ['-lc++']) + cxx_flags.append('-stdlib=libc++') + link_flags.append('-lc++') # Prevents visibility issues in standard headers conf.define("_DARWIN_C_SOURCE", 1) @@ -156,7 +166,7 @@ def set_compiler_flags (conf,opt): # Silence warnings about the non-existing osx clang compiler flags # -compatibility_version and -current_version. These are Waf # generated and not needed with clang - conf.env.append_unique ("CXXFLAGS", ["-Qunused-arguments"]) + cxx_flags.append("-Qunused-arguments") if opt.gprofile: debug_flags = [ '-pg' ] @@ -199,8 +209,7 @@ def set_compiler_flags (conf,opt): # stupid OS X 10.6 has a bug in math.h that prevents llrint and friends # from being visible. # - debug_flags.append ('-U__STRICT_ANSI__') - optimization_flags.append ('-U__STRICT_ANSI__') + compiler_flags.append ('-U__STRICT_ANSI__') if cpu == 'powerpc' and conf.env['build_target'] != 'none': # @@ -212,12 +221,12 @@ def set_compiler_flags (conf,opt): if platform == 'darwin': # optimization_flags.extend ([ "-mcpu=7450", "-faltivec"]) # to support g3s but still have some optimization for above - optimization_flags.extend ([ "-mcpu=G3", "-mtune=7450"]) + compiler_flags.extend ([ "-mcpu=G3", "-mtune=7450"]) else: - optimization_flags.extend ([ "-mcpu=7400", "-maltivec", "-mabi=altivec"]) + compiler_flags.extend ([ "-mcpu=7400", "-maltivec", "-mabi=altivec"]) else: - optimization_flags.extend([ "-mcpu=750", "-mmultiple" ]) - optimization_flags.extend (["-mhard-float", "-mpowerpc-gfxopt"]) + compiler_flags.extend([ "-mcpu=750", "-mmultiple" ]) + compiler_flags.extend (["-mhard-float", "-mpowerpc-gfxopt"]) optimization_flags.extend (["-Os"]) elif ((re.search ("i[0-9]86", cpu) != None) or (re.search ("x86_64", cpu) != None)) and conf.env['build_target'] != 'none': @@ -230,8 +239,7 @@ def set_compiler_flags (conf,opt): # if (re.search ("(i[0-9]86|x86_64)", cpu) != None): - debug_flags.append ("-DARCH_X86") - optimization_flags.append ("-DARCH_X86") + compiler_flags.append ("-DARCH_X86") if platform == 'linux' : @@ -245,32 +253,29 @@ def set_compiler_flags (conf,opt): x86_flags = flag_line.split (": ")[1:][0].split () if "mmx" in x86_flags: - optimization_flags.append ("-mmmx") + compiler_flags.append ("-mmmx") if "sse" in x86_flags: build_host_supports_sse = True if "3dnow" in x86_flags: - optimization_flags.append ("-m3dnow") + compiler_flags.append ("-m3dnow") if cpu == "i586": - optimization_flags.append ("-march=i586") + compiler_flags.append ("-march=i586") elif cpu == "i686": - optimization_flags.append ("-march=i686") + compiler_flags.append ("-march=i686") if not is_clang and ((conf.env['build_target'] == 'i686') or (conf.env['build_target'] == 'x86_64')) and build_host_supports_sse: - optimization_flags.extend (["-msse", "-mfpmath=sse", "-DUSE_XMMINTRIN"]) - debug_flags.extend (["-msse", "-mfpmath=sse", "-DUSE_XMMINTRIN"]) + compiler_flags.extend (["-msse", "-mfpmath=sse", "-DUSE_XMMINTRIN"]) # end of processor-specific section # optimization section if conf.env['FPU_OPTIMIZATION']: if sys.platform == 'darwin': - optimization_flags.append ("-DBUILD_VECLIB_OPTIMIZATIONS"); - debug_flags.append ("-DBUILD_VECLIB_OPTIMIZATIONS"); - conf.env.append_value('LINKFLAGS', "-framework Accelerate") + compiler_flags.append("-DBUILD_VECLIB_OPTIMIZATIONS"); + linker_flags.append("-framework Accelerate") elif conf.env['build_target'] == 'i686' or conf.env['build_target'] == 'x86_64': - optimization_flags.append ("-DBUILD_SSE_OPTIMIZATIONS") - debug_flags.append ("-DBUILD_SSE_OPTIMIZATIONS") + compiler_flags.append ("-DBUILD_SSE_OPTIMIZATIONS") if not build_host_supports_sse: print("\nWarning: you are building Ardour with SSE support even though your system does not support these instructions. (This may not be an error, especially if you are a package maintainer)") @@ -289,9 +294,9 @@ def set_compiler_flags (conf,opt): if opt.lxvst: if conf.env['build_target'] == 'x86_64': - conf.env.append_value('CXXFLAGS', "-DLXVST_64BIT") + compiler_flags.append("-DLXVST_64BIT") else: - conf.env.append_value('CXXFLAGS', "-DLXVST_32BIT") + compiler_flags.append("-DLXVST_32BIT") # # a single way to test if we're on OS X @@ -301,18 +306,15 @@ def set_compiler_flags (conf,opt): conf.define ('IS_OSX', 1) # force tiger or later, to avoid issues on PPC which defaults # back to 10.1 if we don't tell it otherwise. - - conf.env.append_value('CFLAGS', "-DMAC_OS_X_VERSION_MIN_REQUIRED=1040") - conf.env.append_value('CXXFLAGS', "-DMAC_OS_X_VERSION_MIN_REQUIRED=1040") - conf.env.append_value('CXXFLAGS', '-mmacosx-version-min=10.4') - conf.env.append_value('CFLAGS', '-mmacosx-version-min=10.4') + compiler_flags.extend( + ("-DMAC_OS_X_VERSION_MIN_REQUIRED=1040", + '-mmacosx-version-min=10.4')) elif conf.env['build_target'] in [ 'lion', 'mountainlion' ]: - conf.env.append_value('CFLAGS', "-DMAC_OS_X_VERSION_MIN_REQUIRED=1070") - conf.env.append_value('CXXFLAGS', "-DMAC_OS_X_VERSION_MIN_REQUIRED=1070") - conf.env.append_value('CXXFLAGS', '-mmacosx-version-min=10.7') - conf.env.append_value('CFLAGS', '-mmacosx-version-min=10.7') + compiler_flags.extend( + ("-DMAC_OS_X_VERSION_MIN_REQUIRED=1070", + '-mmacosx-version-min=10.7')) else: conf.define ('IS_OSX', 0) @@ -349,26 +351,15 @@ def set_compiler_flags (conf,opt): "-fstrength-reduce" ] - if opt.debug: - conf.env.append_value('CFLAGS', debug_flags) - conf.env.append_value('CXXFLAGS', debug_flags) - conf.env.append_value('LINKFLAGS', debug_flags) - else: - conf.env.append_value('CFLAGS', optimization_flags) - conf.env.append_value('CXXFLAGS', optimization_flags) - conf.env.append_value('LINKFLAGS', optimization_flags) - if opt.stl_debug: - conf.env.append_value('CXXFLAGS', "-D_GLIBCXX_DEBUG") + cxx_flags.append("-D_GLIBCXX_DEBUG") if conf.env['DEBUG_RT_ALLOC']: - conf.env.append_value('CFLAGS', '-DDEBUG_RT_ALLOC') - conf.env.append_value('CXXFLAGS', '-DDEBUG_RT_ALLOC') - conf.env.append_value('LINKFLAGS', '-ldl') + compiler_flags.append('-DDEBUG_RT_ALLOC') + linker_flags.append('-ldl') if conf.env['DEBUG_DENORMAL_EXCEPTION']: - conf.env.append_value('CFLAGS', '-DDEBUG_DENORMAL_EXCEPTION') - conf.env.append_value('CXXFLAGS', '-DDEBUG_DENORMAL_EXCEPTION') + compiler_flags.append('-DDEBUG_DENORMAL_EXCEPTION') if opt.universal: if opt.generic: @@ -376,60 +367,53 @@ def set_compiler_flags (conf,opt): sys.exit (1) else: if not Options.options.nocarbon: - conf.env.append_value('CFLAGS', ["-arch", "i386", "-arch", "ppc"]) - conf.env.append_value('CXXFLAGS', ["-arch", "i386", "-arch", "ppc"]) - conf.env.append_value('LINKFLAGS', ["-arch", "i386", "-arch", "ppc"]) + compiler_flags.extend(("-arch", "i386", "-arch", "ppc")) + linker_flags.extend(("-arch", "i386", "-arch", "ppc")) else: - conf.env.append_value('CFLAGS', ["-arch", "x86_64", "-arch", "i386", "-arch", "ppc"]) - conf.env.append_value('CXXFLAGS', ["-arch", "x86_64", "-arch", "i386", "-arch", "ppc"]) - conf.env.append_value('LINKFLAGS', ["-arch", "x86_64", "-arch", "i386", "-arch", "ppc"]) + compiler_flags.extend( + ("-arch", "x86_64", "-arch", "i386", "-arch", "ppc")) + linker_flags.extend( + ("-arch", "x86_64", "-arch", "i386", "-arch", "ppc")) else: if opt.generic: - conf.env.append_value('CFLAGS', ['-arch', 'i386']) - conf.env.append_value('CXXFLAGS', ['-arch', 'i386']) - conf.env.append_value('LINKFLAGS', ['-arch', 'i386']) + compiler_flags.extend(('-arch', 'i386')) + linker_flags.extend(('-arch', 'i386')) # # warnings flags # - conf.env.append_value('CFLAGS', [ '-Wall', - '-Wpointer-arith', - '-Wcast-qual', - '-Wcast-align', - '-Wstrict-prototypes', - '-Wmissing-prototypes' - ]) - - conf.env.append_value('CXXFLAGS', [ '-Wall', - '-Wpointer-arith', - '-Wcast-qual', - '-Wcast-align', - '-Woverloaded-virtual' - ]) + compiler_flags.extend( + ('-Wall', '-Wpointer-arith', '-Wcast-qual', '-Wcast-align')) + c_flags.extend(('-Wstrict-prototypes', '-Wmissing-prototypes')) + cxx_flags.append('-Woverloaded-virtual') # # more boilerplate # - conf.env.append_value('CFLAGS', '-DBOOST_SYSTEM_NO_DEPRECATED') - conf.env.append_value('CXXFLAGS', '-DBOOST_SYSTEM_NO_DEPRECATED') # need ISOC9X for llabs() - conf.env.append_value('CFLAGS', '-D_ISOC9X_SOURCE') - conf.env.append_value('CFLAGS', '-D_LARGEFILE64_SOURCE') - conf.env.append_value('CFLAGS', '-D_FILE_OFFSET_BITS=64') - # need ISOC9X for llabs() - conf.env.append_value('CXXFLAGS', '-D_ISOC9X_SOURCE') - conf.env.append_value('CXXFLAGS', '-D_LARGEFILE64_SOURCE') - conf.env.append_value('CXXFLAGS', '-D_FILE_OFFSET_BITS=64') - - conf.env.append_value('CXXFLAGS', '-D__STDC_LIMIT_MACROS') - conf.env.append_value('CXXFLAGS', '-D__STDC_FORMAT_MACROS') + compiler_flags.extend( + ('-DBOOST_SYSTEM_NO_DEPRECATED', '-D_ISOC9X_SOURCE', + '-D_LARGEFILE64_SOURCE', '-D_FILE_OFFSET_BITS=64')) + cxx_flags.extend(('-D__STDC_LIMIT_MACROS', '-D__STDC_FORMAT_MACROS')) if opt.nls: - conf.env.append_value('CXXFLAGS', '-DENABLE_NLS') - conf.env.append_value('CFLAGS', '-DENABLE_NLS') + compiler_flags.append('-DENABLE_NLS') + + if opt.debug: + conf.env.append_value('CFLAGS', debug_flags) + conf.env.append_value('CXXFLAGS', debug_flags) + else: + conf.env.append_value('CFLAGS', optimization_flags) + conf.env.append_value('CXXFLAGS', optimization_flags) + + conf.env.append_value('CFLAGS', compiler_flags) + conf.env.append_value('CFLAGS', c_flags) + conf.env.append_value('CXXFLAGS', compiler_flags) + conf.env.append_value('CXXFLAGS', cxx_flags) + conf.env.append_value('LINKFLAGS', linker_flags) #---------------------------------------------------------------- From a86b66181aa0b4c76216acf1a5c968d8ea9aaa02 Mon Sep 17 00:00:00 2001 From: Nils Philippsen Date: Mon, 9 Dec 2013 17:54:34 +0100 Subject: [PATCH 05/13] ignore "unofficial" states in jack_sync_callback() --- libs/backends/jack/jack_audiobackend.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/libs/backends/jack/jack_audiobackend.cc b/libs/backends/jack/jack_audiobackend.cc index 0182e4809f..5e447a6ee1 100644 --- a/libs/backends/jack/jack_audiobackend.cc +++ b/libs/backends/jack/jack_audiobackend.cc @@ -765,6 +765,7 @@ int JACKAudioBackend::jack_sync_callback (jack_transport_state_t state, jack_position_t* pos) { TransportState tstate; + bool tstate_valid = true; switch (state) { case JackTransportStopped: @@ -779,9 +780,15 @@ JACKAudioBackend::jack_sync_callback (jack_transport_state_t state, jack_positio case JackTransportStarting: tstate = TransportStarting; break; + default: + // ignore "unofficial" states like JackTransportNetStarting (jackd2) + tstate_valid = false; + break; } - return engine.sync_callback (tstate, pos->frame); + if (tstate_valid) { + return engine.sync_callback (tstate, pos->frame); + } return true; } From 27a3f2837a28862fa9fab7714a96975dc8540ac9 Mon Sep 17 00:00:00 2001 From: Nils Philippsen Date: Tue, 10 Dec 2013 16:50:35 +0100 Subject: [PATCH 06/13] use std::fill_n to fill gain buffer with samples Using memset fills the buffer with whatever 1.0 as a double or float has in its LSB. --- libs/ardour/export_channel.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/ardour/export_channel.cc b/libs/ardour/export_channel.cc index 82e5d80244..c67f33bb91 100644 --- a/libs/ardour/export_channel.cc +++ b/libs/ardour/export_channel.cc @@ -131,7 +131,7 @@ RegionExportChannelFactory::RegionExportChannelFactory (Session * session, Audio mixdown_buffer.reset (new Sample [frames_per_cycle]); gain_buffer.reset (new Sample [frames_per_cycle]); - memset (gain_buffer.get(), 1.0, sizeof (Sample) * frames_per_cycle); + std::fill_n (gain_buffer.get(), frames_per_cycle, Sample (1.0)); break; case Processed: From 71f6104340ec78170ecbb814cb05b0c589b02774 Mon Sep 17 00:00:00 2001 From: Nils Philippsen Date: Tue, 10 Dec 2013 16:52:37 +0100 Subject: [PATCH 07/13] use correct argument order with memset() --- libs/ardour/vst_plugin.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/ardour/vst_plugin.cc b/libs/ardour/vst_plugin.cc index 00cd6efaa5..cb40d6eac8 100644 --- a/libs/ardour/vst_plugin.cc +++ b/libs/ardour/vst_plugin.cc @@ -486,7 +486,7 @@ string VSTPlugin::describe_parameter (Evoral::Parameter param) { char name[64]; - memset (name, sizeof (name), 0); + memset (name, 0, sizeof (name)); /* some VST plugins expect this buffer to be zero-filled */ From 51bcb789e33e436d014ec465622c1e32528c1a9c Mon Sep 17 00:00:00 2001 From: Nils Philippsen Date: Tue, 10 Dec 2013 21:17:04 +0100 Subject: [PATCH 08/13] compare region names case-sensitively --- gtk2_ardour/editor_regions.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gtk2_ardour/editor_regions.cc b/gtk2_ardour/editor_regions.cc index 72a0da2909..bf13bd5a65 100644 --- a/gtk2_ardour/editor_regions.cc +++ b/gtk2_ardour/editor_regions.cc @@ -1115,7 +1115,7 @@ EditorRegions::sorter (TreeModel::iterator a, TreeModel::iterator b) switch (_sort_type) { case ByName: - cmp = g_strcasecmp (region1->name().c_str(), region2->name().c_str()); + cmp = region1->name().compare(region2->name()); break; case ByLength: @@ -1140,7 +1140,7 @@ EditorRegions::sorter (TreeModel::iterator a, TreeModel::iterator b) break; case BySourceFileName: - cmp = g_strcasecmp (region1->source()->name().c_str(), region2->source()->name().c_str()); + cmp = region1->source()->name().compare(region2->source()->name()); break; case BySourceFileLength: @@ -1153,9 +1153,9 @@ EditorRegions::sorter (TreeModel::iterator a, TreeModel::iterator b) case BySourceFileFS: if (region1->source()->name() == region2->source()->name()) { - cmp = g_strcasecmp (region1->name().c_str(), region2->name().c_str()); + cmp = region1->name().compare(region2->name()); } else { - cmp = g_strcasecmp (region1->source()->name().c_str(), region2->source()->name().c_str()); + cmp = region1->source()->name().compare(region2->source()->name()); } break; } From e5ae775b42ea98587603ee273ca23394a113d44c Mon Sep 17 00:00:00 2001 From: Nils Philippsen Date: Tue, 10 Dec 2013 21:20:56 +0100 Subject: [PATCH 09/13] don't use deprecated g_strcasecmp() It's dependent on the current locale and deprecated, use g_ascii_strcasecmp() instead. --- gtk2_ardour/gtk_pianokeyboard.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gtk2_ardour/gtk_pianokeyboard.c b/gtk2_ardour/gtk_pianokeyboard.c index f3897e3d44..4f1740f26a 100644 --- a/gtk2_ardour/gtk_pianokeyboard.c +++ b/gtk2_ardour/gtk_pianokeyboard.c @@ -732,13 +732,13 @@ piano_keyboard_set_keyboard_layout(PianoKeyboard *pk, const char *layout) { assert(layout); - if (!g_strcasecmp(layout, "QWERTY")) { + if (!g_ascii_strcasecmp(layout, "QWERTY")) { bind_keys_qwerty(pk); - } else if (!g_strcasecmp(layout, "QWERTZ")) { + } else if (!g_ascii_strcasecmp(layout, "QWERTZ")) { bind_keys_qwertz(pk); - } else if (!g_strcasecmp(layout, "AZERTY")) { + } else if (!g_ascii_strcasecmp(layout, "AZERTY")) { bind_keys_azerty(pk); } else { From 96947e2f3a74e5f738c763db7dfa42b1269a3903 Mon Sep 17 00:00:00 2001 From: Nils Philippsen Date: Tue, 10 Dec 2013 21:29:24 +0100 Subject: [PATCH 10/13] add cmp_nocase_utf8() This is like cmp_nocase(), only that it doesn't use toupper(), tolower() and therefore is agnostic of the current locale, and attempts to compare strings in a UTF8-aware way (or falls back to ASCII if one of the strings isn't UTF8-encoded). --- libs/ardour/ardour/utils.h | 1 + libs/ardour/utils.cc | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/libs/ardour/ardour/utils.h b/libs/ardour/ardour/utils.h index bf91d4d57e..4bf97fd2e5 100644 --- a/libs/ardour/ardour/utils.h +++ b/libs/ardour/ardour/utils.h @@ -57,6 +57,7 @@ static inline float f_max(float x, float a) { std::string bump_name_once(const std::string& s, char delimiter); int cmp_nocase (const std::string& s, const std::string& s2); +int cmp_nocase_utf8 (const std::string& s1, const std::string& s2); int touch_file(std::string path); diff --git a/libs/ardour/utils.cc b/libs/ardour/utils.cc index 0c98461974..aa06912913 100644 --- a/libs/ardour/utils.cc +++ b/libs/ardour/utils.cc @@ -232,6 +232,41 @@ cmp_nocase (const string& s, const string& s2) return (s2.size() == s.size()) ? 0 : (s.size() < s2.size()) ? -1 : 1; } +int cmp_nocase_utf8 (const string& s1, const string& s2) +{ + const char *cstr1 = s1.c_str(); + const char *cstr2 = s2.c_str(); + gchar *cstr1folded = NULL; + gchar *cstr2folded = NULL; + int retval; + + if (!g_utf8_validate (cstr1, -1, NULL) || + !g_utf8_validate (cstr2, -1, NULL)) { + // fall back to comparing ASCII + return g_ascii_strcasecmp (cstr1, cstr2); + } + + cstr1folded = g_utf8_casefold (cstr1, -1); + cstr2folded = g_utf8_casefold (cstr2, -1); + + if (cstr1folded && cstr2folded) { + retval = strcmp (cstr1folded, cstr2folded); + } else { + // this shouldn't happen, make the best of it + retval = g_ascii_strcasecmp (cstr1, cstr2); + } + + if (cstr1folded) { + g_free (cstr1folded); + } + + if (cstr2folded) { + g_free (cstr2folded); + } + + return retval; +} + int touch_file (string path) { From a01edede5e47c237d2815272cbb2443bfa1742ba Mon Sep 17 00:00:00 2001 From: Nils Philippsen Date: Tue, 10 Dec 2013 21:31:57 +0100 Subject: [PATCH 11/13] compare plugin/creator/category names UTF8-aware --- gtk2_ardour/plugin_selector.cc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/gtk2_ardour/plugin_selector.cc b/gtk2_ardour/plugin_selector.cc index ebfcc677ac..bb96c7f392 100644 --- a/gtk2_ardour/plugin_selector.cc +++ b/gtk2_ardour/plugin_selector.cc @@ -37,6 +37,7 @@ #include "ardour/plugin_manager.h" #include "ardour/plugin.h" +#include "ardour/utils.h" #include "ardour_ui.h" #include "plugin_selector.h" @@ -538,13 +539,13 @@ struct PluginMenuCompareByCreator { bool operator() (PluginInfoPtr a, PluginInfoPtr b) const { int cmp; - cmp = g_strcasecmp (a->creator.c_str(), b->creator.c_str()); + cmp = cmp_nocase_utf8 (a->creator, b->creator); if (cmp < 0) { return true; } else if (cmp == 0) { /* same creator ... compare names */ - if (g_strcasecmp (a->name.c_str(), b->name.c_str()) < 0) { + if (cmp_nocase_utf8 (a->name, b->name) < 0) { return true; } } @@ -556,7 +557,7 @@ struct PluginMenuCompareByName { bool operator() (PluginInfoPtr a, PluginInfoPtr b) const { int cmp; - cmp = g_strcasecmp (a->name.c_str(), b->name.c_str()); + cmp = cmp_nocase_utf8 (a->name, b->name); if (cmp < 0) { return true; @@ -574,13 +575,13 @@ struct PluginMenuCompareByCategory { bool operator() (PluginInfoPtr a, PluginInfoPtr b) const { int cmp; - cmp = g_strcasecmp (a->category.c_str(), b->category.c_str()); + cmp = cmp_nocase_utf8 (a->category, b->category); if (cmp < 0) { return true; } else if (cmp == 0) { /* same category ... compare names */ - if (g_strcasecmp (a->name.c_str(), b->name.c_str()) < 0) { + if (cmp_nocase_utf8 (a->name, b->name) < 0) { return true; } } From 527b0a78a182b84818fd216f941c91733cb8f229 Mon Sep 17 00:00:00 2001 From: Nils Philippsen Date: Tue, 10 Dec 2013 23:06:27 +0100 Subject: [PATCH 12/13] fix const-ness of names array --- libs/evoral/src/libsmf/smf_decode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/evoral/src/libsmf/smf_decode.c b/libs/evoral/src/libsmf/smf_decode.c index 0951a6e2f8..bfba08e9f9 100644 --- a/libs/evoral/src/libsmf/smf_decode.c +++ b/libs/evoral/src/libsmf/smf_decode.c @@ -490,7 +490,7 @@ static void note_from_int(char *buf, int note_number) { int note, octave; - char *names[] = {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"}; + const char *names[] = {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"}; octave = note_number / 12 - 1; note = note_number % 12; From fd1eb73ef21e8a938e34ca49378a866c381c48e3 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Thu, 12 Dec 2013 14:40:45 +0100 Subject: [PATCH 13/13] adjust LV2 ringbuffer size according to LV2:resize-port The message-size itself is part of the message which stored in the ringbuffer. If the rinbuffer overflows the message is misinterpreted -> segfault. Choose a more conservative ring-buffer size and take the requested LV2 size into account. --- libs/ardour/lv2_plugin.cc | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/libs/ardour/lv2_plugin.cc b/libs/ardour/lv2_plugin.cc index da514f92e4..a1d9de1e53 100644 --- a/libs/ardour/lv2_plugin.cc +++ b/libs/ardour/lv2_plugin.cc @@ -1162,10 +1162,14 @@ LV2Plugin::write_from_ui(uint32_t index, * 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). + * + * it is NOT safe to overflow (msg.size will be misinterpreted) */ - rbs = max((size_t) 32768 * 6, rbs); + uint32_t bufsiz = 32768; + if (_atom_ev_buffers && _atom_ev_buffers[0]) { + bufsiz = lv2_evbuf_get_capacity(_atom_ev_buffers[0]); + } + rbs = max((size_t) bufsiz * 8, rbs); _from_ui = new RingBuffer(rbs); } @@ -1194,8 +1198,12 @@ LV2Plugin::enable_ui_emmission() { if (!_to_ui) { /* see note in LV2Plugin::write_from_ui() */ + uint32_t bufsiz = 32768; + if (_atom_ev_buffers && _atom_ev_buffers[0]) { + bufsiz = lv2_evbuf_get_capacity(_atom_ev_buffers[0]); + } size_t rbs = _session.engine().raw_buffer_size(DataType::MIDI) * NBUFS; - rbs = max((size_t) 32768 * 8, rbs); + rbs = max((size_t) bufsiz * 8, rbs); _to_ui = new RingBuffer(rbs); } }