diff --git a/source/backend/plugin/CarlaPluginJack.cpp b/source/backend/plugin/CarlaPluginJack.cpp index c95892055..b4e5b2627 100644 --- a/source/backend/plugin/CarlaPluginJack.cpp +++ b/source/backend/plugin/CarlaPluginJack.cpp @@ -18,7 +18,7 @@ #include "CarlaPluginInternal.hpp" #include "CarlaEngine.hpp" -#ifdef CARLA_OS_LINUX +#if defined(CARLA_OS_LINUX) || defined(CARLA_OS_MAC) #include "CarlaLibJackHints.h" #include "CarlaBackendUtils.hpp" @@ -142,14 +142,20 @@ public: { const EngineOptions& options(kEngine->getOptions()); CarlaString binaryDir(options.binaryDir); -#ifdef HAVE_LIBLO + #ifdef HAVE_LIBLO const int sessionManager = fSetupLabel[4U] - '0'; -#endif + #endif CarlaString ret; + #ifdef CARLA_OS_MAC + ret += "export DYLD_LIBRARY_PATH=" + binaryDir + "/jack\n"; + ret += "export DYLD_INSERT_LIBRARIES=" + binaryDir + "/libcarla_interposer-jack-x11.dylib\n"; + ret += "export DYLD_FORCE_FLAT_NAMESPACE=1\n"; + #else ret += "export LD_LIBRARY_PATH=" + binaryDir + "/jack\n"; ret += "export LD_PRELOAD=" + binaryDir + "/libcarla_interposer-jack-x11.so\n"; -#ifdef HAVE_LIBLO + #endif + #ifdef HAVE_LIBLO if (sessionManager == LIBJACK_SESSION_MANAGER_NSM) { for (int i=50; fOscServer == nullptr && --i>=0;) @@ -159,7 +165,7 @@ public: ret += lo_server_get_url(fOscServer); ret += "\n"; } -#endif + #endif if (kPlugin->getHints() & PLUGIN_HAS_CUSTOM_UI) ret += "export CARLA_FRONTEND_WIN_ID=" + CarlaString(options.frontendWinId) + "\n"; @@ -362,15 +368,25 @@ protected: winIdStr[STR_MAX] = '\0'; const CarlaString libjackdir(CarlaString(options.binaryDir) + "/jack"); + #ifdef CARLA_OS_MAC + const CarlaString ldpreload(CarlaString(options.binaryDir) + "/libcarla_interposer-jack-x11.dylib"); + #else const CarlaString ldpreload(CarlaString(options.binaryDir) + "/libcarla_interposer-jack-x11.so"); + #endif const ScopedEngineEnvironmentLocker _seel(kEngine); + #ifdef CARLA_OS_MAC + const CarlaScopedEnvVar sev2("DYLD_LIBRARY_PATH", libjackdir.buffer()); + const CarlaScopedEnvVar sev1("DYLD_INSERT_LIBRARIES", ldpreload.isNotEmpty() ? ldpreload.buffer() : nullptr); + const CarlaScopedEnvVar sev0("DYLD_FORCE_FLAT_NAMESPACE", "1"); + #else const CarlaScopedEnvVar sev2("LD_LIBRARY_PATH", libjackdir.buffer()); const CarlaScopedEnvVar sev1("LD_PRELOAD", ldpreload.isNotEmpty() ? ldpreload.buffer() : nullptr); -#ifdef HAVE_LIBLO + #endif + #ifdef HAVE_LIBLO const CarlaScopedEnvVar sev3("NSM_URL", lo_server_get_url(fOscServer)); -#endif + #endif if (kPlugin->getHints() & PLUGIN_HAS_CUSTOM_UI) carla_setenv("CARLA_FRONTEND_WIN_ID", winIdStr); @@ -2048,7 +2064,7 @@ CarlaPluginPtr CarlaPlugin::newJackApp(const Initializer& init) carla_debug("CarlaPlugin::newJackApp({%p, \"%s\", \"%s\", \"%s\"})", init.engine, init.filename, init.name, init.label); -#ifdef CARLA_OS_LINUX +#if defined(CARLA_OS_LINUX) || defined(CARLA_OS_MAC) std::shared_ptr plugin(new CarlaPluginJack(init.engine, init.id)); if (! plugin->init(plugin, init.filename, init.name, init.label, init.options)) diff --git a/source/frontend/carla_settings.py b/source/frontend/carla_settings.py index 4038d3e5b..bd849a38f 100755 --- a/source/frontend/carla_settings.py +++ b/source/frontend/carla_settings.py @@ -586,13 +586,15 @@ class CarlaSettingsW(QDialog): if not LINUX: self.ui.ch_exp_wine_bridges.setVisible(False) - self.ui.ch_exp_jack_apps.setVisible(False) self.ui.ch_exp_prevent_bad_behaviour.setVisible(False) self.ui.lw_page.hideRow(self.TAB_INDEX_WINE) if not MACOS: self.ui.label_engine_ui_bridges_mac_note.setVisible(False) + if not (LINUX or MACOS): + self.ui.ch_exp_jack_apps.setVisible(False) + # FIXME, not implemented yet self.ui.ch_engine_uis_always_on_top.hide() diff --git a/source/frontend/utils/qsafesettings.cpp b/source/frontend/utils/qsafesettings.cpp index d1786fb35..04ef6f9ac 100644 --- a/source/frontend/utils/qsafesettings.cpp +++ b/source/frontend/utils/qsafesettings.cpp @@ -54,10 +54,12 @@ int QSafeSettings::valueIntPositive(const QString& key, const int defaultValue) QVariant var(value(key, defaultValue)); if (!var.isNull() && var.convert(QVariant::Int) && var.isValid()) - return defaultValue; + { + const int value = var.toInt(); + return value >= 0 ? value : defaultValue; + } - const int value = var.toInt(); - return value >= 0 ? value : defaultValue; + return defaultValue; } uint QSafeSettings::valueUInt(const QString& key, const uint defaultValue) const diff --git a/source/interposer/Makefile b/source/interposer/Makefile index e6d173ec8..d47d46d0a 100644 --- a/source/interposer/Makefile +++ b/source/interposer/Makefile @@ -31,15 +31,15 @@ INTERPOSER_X11_LIBS = $(X11_LIBS) $(LIBDL_LIBS) OBJS = TARGETS = -ifeq ($(LINUX),true) +ifeq ($(LINUX)$(MACOS),true) OBJS += $(OBJDIR)/interposer-safe.cpp.o OBJS += $(OBJDIR)/interposer-jack-x11.cpp.o -TARGETS += $(BINDIR)/libcarla_interposer-safe.so -TARGETS += $(BINDIR)/libcarla_interposer-jack-x11.so +TARGETS += $(BINDIR)/libcarla_interposer-safe$(LIB_EXT) +TARGETS += $(BINDIR)/libcarla_interposer-jack-x11$(LIB_EXT) ifeq ($(HAVE_X11),true) OBJS += $(OBJDIR)/interposer-x11.cpp.o -TARGETS += $(BINDIR)/libcarla_interposer-x11.so +TARGETS += $(BINDIR)/libcarla_interposer-x11$(LIB_EXT) endif endif @@ -57,19 +57,19 @@ debug: # --------------------------------------------------------------------------------------------------------------------- -$(BINDIR)/libcarla_interposer-safe.so: $(OBJDIR)/interposer-safe.cpp.o +$(BINDIR)/libcarla_interposer-safe$(LIB_EXT): $(OBJDIR)/interposer-safe.cpp.o -@mkdir -p $(BINDIR) - @echo "Linking libcarla_interposer-safe.so" + @echo "Linking libcarla_interposer-safe$(LIB_EXT)" $(SILENT)$(CXX) $< $(SHARED) $(LINK_FLAGS) $(INTERPOSER_SAFE_LIBS) -o $@ -$(BINDIR)/libcarla_interposer-x11.so: $(OBJDIR)/interposer-x11.cpp.o +$(BINDIR)/libcarla_interposer-x11$(LIB_EXT): $(OBJDIR)/interposer-x11.cpp.o -@mkdir -p $(BINDIR) - @echo "Linking libcarla_interposer-x11.so" + @echo "Linking libcarla_interposer-x11$(LIB_EXT)" $(SILENT)$(CXX) $< $(SHARED) $(LINK_FLAGS) $(INTERPOSER_X11_LIBS) -o $@ -$(BINDIR)/libcarla_interposer-jack-x11.so: $(OBJDIR)/interposer-jack-x11.cpp.o +$(BINDIR)/libcarla_interposer-jack-x11$(LIB_EXT): $(OBJDIR)/interposer-jack-x11.cpp.o -@mkdir -p $(BINDIR) - @echo "Linking libcarla_interposer-jack-x11.so" + @echo "Linking libcarla_interposer-jack-x11$(LIB_EXT)" $(SILENT)$(CXX) $< $(SHARED) $(LINK_FLAGS) $(INTERPOSER_X11_LIBS) -o $@ # --------------------------------------------------------------------------------------------------------------------- diff --git a/source/interposer/interposer-jack-x11.cpp b/source/interposer/interposer-jack-x11.cpp index b1b55f2e7..4ec5db6aa 100644 --- a/source/interposer/interposer-jack-x11.cpp +++ b/source/interposer/interposer-jack-x11.cpp @@ -31,7 +31,11 @@ struct ScopedLibOpen { long long winId; ScopedLibOpen() noexcept + #ifdef CARLA_OS_MAC + : handle(dlopen("libjack.dylib", RTLD_NOW|RTLD_LOCAL)), + #else : handle(dlopen("libjack.so.0", RTLD_NOW|RTLD_LOCAL)), + #endif winId(-1) { CARLA_SAFE_ASSERT_RETURN(handle != nullptr,); diff --git a/source/libjack/Makefile b/source/libjack/Makefile index ef99518a2..f6945b1de 100644 --- a/source/libjack/Makefile +++ b/source/libjack/Makefile @@ -23,11 +23,14 @@ endif BUILD_C_FLAGS += -I$(CWD) -I$(CWD)/includes BUILD_CXX_FLAGS += -I$(CWD) -I$(CWD)/backend -I$(CWD)/includes -I$(CWD)/utils -LINK_FLAGS += -pthread -lrt +LINK_FLAGS += -pthread +ifeq ($(LINUX),true) +LINK_FLAGS += -lrt +endif # --------------------------------------------------------------------------------------------------------------------- -ifeq ($(LINUX),true) +ifeq ($(LINUX)$(MACOS),true) ifneq ($(JACKBRIDGE_DIRECT),true) CAN_BUILD_LIBJACK=true endif @@ -51,7 +54,11 @@ OBJS = \ $(OBJDIR)/libjack_time.cpp.o \ $(OBJDIR)/libjack_transport.cpp.o \ $(OBJDIR)/ringbuffer.c.o +ifeq ($(MACOS),true) +TARGET = $(BINDIR)/jack/libjack.dylib +else TARGET = $(BINDIR)/jack/libjack.so.0 +endif else OBJS = TARGET = @@ -73,7 +80,7 @@ debug: $(TARGET): $(OBJS) -@mkdir -p $(BINDIR)/jack - @echo "Linking libjack.so.0" + @echo "Linking libjack" $(SILENT)$(CXX) $^ $(SHARED) $(LINK_FLAGS) $(LIBJACK_LIBS) -o $@ # --------------------------------------------------------------------------------------------------------------------- diff --git a/source/libjack/libjack.cpp b/source/libjack/libjack.cpp index c48349c07..851b7e78f 100644 --- a/source/libjack/libjack.cpp +++ b/source/libjack/libjack.cpp @@ -21,7 +21,6 @@ #include "CarlaJuceUtils.hpp" #include -#include #include // --------------------------------------------------------------------------------------------------------------------- diff --git a/source/libjack/libjack_base.cpp b/source/libjack/libjack_base.cpp index b02dfebda..62055598b 100644 --- a/source/libjack/libjack_base.cpp +++ b/source/libjack/libjack_base.cpp @@ -29,8 +29,14 @@ int jack_carla_interposed_action(uint, uint, void*) printWarning = false; carla_stderr2("Non-exported jack_carla_interposed_action called, this should not happen!!"); carla_stderr("Printing some info:"); + #ifdef CARLA_OS_MAC + carla_stderr("\tDYLD_LIBRARY_PATH: '%s'", std::getenv("DYLD_LIBRARY_PATH")); + carla_stderr("\tDYLD_INSERT_LIBRARIES: '%s'", std::getenv("DYLD_INSERT_LIBRARIES")); + carla_stderr("\tDYLD_FORCE_FLAT_NAMESPACE: '%s'", std::getenv("DYLD_FORCE_FLAT_NAMESPACE")); + #else carla_stderr("\tLD_LIBRARY_PATH: '%s'", std::getenv("LD_LIBRARY_PATH")); carla_stderr("\tLD_PRELOAD: '%s'", std::getenv("LD_PRELOAD")); + #endif std::fflush(stderr); }