Skip to content

Commit

Permalink
Add Carla support for MacOS (LMMS#4558)
Browse files Browse the repository at this point in the history
Add Carla support for MacOS
  • Loading branch information
tresf authored Sep 15, 2018
1 parent 8eb4405 commit f3d4019
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 37 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/build
/target
.*.sw?
.DS_Store
*~
/CMakeLists.txt.user
/plugins/zynaddsubfx/zynaddsubfx/ExternalPrograms/Controller/Makefile
Expand Down
2 changes: 1 addition & 1 deletion .travis/osx..install.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

PACKAGES="cmake pkgconfig fftw libogg libvorbis lame libsndfile libsamplerate jack sdl libgig libsoundio stk fluid-synth portaudio node fltk"
PACKAGES="cmake pkgconfig fftw libogg libvorbis lame libsndfile libsamplerate jack sdl libgig libsoundio stk fluid-synth portaudio node fltk carla"

if [ $QT5 ]; then
PACKAGES="$PACKAGES qt5"
Expand Down
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,11 @@ ENDIF(WANT_TAP)

# check for CARLA
IF(WANT_CARLA)
PKG_CHECK_MODULES(CARLA carla-standalone>=1.9.5)
PKG_CHECK_MODULES(CARLA carla-native-plugin)
# look for carla under old name
IF(NOT CARLA_FOUND)
PKG_CHECK_MODULES(CARLA carla-standalone>=1.9.5)
ENDIF()
IF(CARLA_FOUND)
SET(LMMS_HAVE_CARLA TRUE)
SET(STATUS_CARLA "OK")
Expand Down
41 changes: 33 additions & 8 deletions cmake/apple/install_apple.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,7 @@ echo -e "$MSG_COLOR\n\nCreating App Bundle \"$APP\"...$COLOR_RESET"
# Locate macdeployqt, assume homebrew & Qt5
which macdeployqt > /dev/null 2>&1
if [ $? -ne 0 ]; then
brew --prefix qt55 > /dev/null 2>&1
if [ $? -eq 0 ]; then
# Prefer Qt 5.5 (QTBUG-53533)
export PATH=$PATH:$(brew --prefix qt55)/bin
else
# Fallback Qt 5.6+
export PATH=$PATH:$(brew --prefix qt5)/bin
fi
export PATH=$PATH:$(brew --prefix qt)/bin
fi

# Remove any old .app bundles
Expand Down Expand Up @@ -71,6 +64,17 @@ install_name_tool -change @rpath/libZynAddSubFxCore.dylib \
@loader_path/../../$zynfmk \
"$APP/Contents/$zynlib"

# Replace @rpath with @loader_path for Carla
# See also plugins/carlabase/CMakeLists.txt
# This MUST be done BEFORE calling macdeployqt
install_name_tool -change @rpath/libcarlabase.dylib \
@loader_path/libcarlabase.dylib \
"$APP/Contents/lib/lmms/libcarlapatchbay.so"

install_name_tool -change @rpath/libcarlabase.dylib \
@loader_path/libcarlabase.dylib \
"$APP/Contents/lib/lmms/libcarlarack.so"

# Link lmms binary
_executables="${_executables} -executable=$APP/Contents/$zynbin"
_executables="${_executables} -executable=$APP/Contents/$zynfmk"
Expand All @@ -90,6 +94,27 @@ done
# Finalize .app
macdeployqt "$APP" $_executables

# Carla is a standalone plugin. Remove library, look for it side-by-side LMMS.app
# This MUST be done AFTER calling macdeployqt
#
# For example:
# /Applications/LMMS.app
# /Applications/Carla.app
carlalibs=$(echo "@CARLA_LIBRARIES@"|tr ";" "\n")

# Loop over all libcarlas, fix linking
for file in "$APP/Contents/lib/lmms/"libcarla*; do
_thisfile="$APP/Contents/lib/lmms/${file##*/}"
for lib in $carlalibs; do
_oldpath="../../Frameworks/lib${lib}.dylib"
_newpath="Carla.app/Contents/MacOS/lib${lib}.dylib"
install_name_tool -change @loader_path/$_oldpath \
@executable_path/../../../$_newpath \
"$_thisfile"
rm -f "$APP/Contents/Frameworks/lib${lib}.dylib"
done
done

# Cleanup
rm -rf "$APP/Contents/bin"
echo -e "\nFinished.\n\n"
6 changes: 5 additions & 1 deletion cmake/modules/BuildPlugin.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ MACRO(BUILD_PLUGIN PLUGIN_NAME)
INSTALL(TARGETS ${PLUGIN_NAME} LIBRARY DESTINATION "${PLUGIN_DIR}")

IF(LMMS_BUILD_APPLE)
SET_TARGET_PROPERTIES(${PLUGIN_NAME} PROPERTIES LINK_FLAGS "-bundle_loader \"${CMAKE_BINARY_DIR}/lmms\"")
IF ("${PLUGIN_LINK}" STREQUAL "SHARED")
SET_TARGET_PROPERTIES(${PLUGIN_NAME} PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
ELSE()
SET_TARGET_PROPERTIES(${PLUGIN_NAME} PROPERTIES LINK_FLAGS "-bundle_loader \"${CMAKE_BINARY_DIR}/lmms\"")
ENDIF()
ADD_DEPENDENCIES(${PLUGIN_NAME} lmms)
ENDIF(LMMS_BUILD_APPLE)
IF(LMMS_BUILD_WIN32)
Expand Down
8 changes: 8 additions & 0 deletions plugins/carlabase/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# For MacOS, use "OLD" RPATH install_name behavior
# This can be changed to "NEW" safely if install_apple.sh.in
# is updated to relink libcarlabase.dylib. MacOS 10.8 uses
# cmake 3.9.6, so this can be done at any time.
IF(NOT CMAKE_VERSION VERSION_LESS 3.9)
CMAKE_POLICY(SET CMP0068 OLD)
ENDIF()

if(LMMS_HAVE_CARLA)
INCLUDE(BuildPlugin)
INCLUDE_DIRECTORIES(${CARLA_INCLUDE_DIRS})
Expand Down
28 changes: 9 additions & 19 deletions plugins/carlabase/carla.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* carla.cpp - Carla for LMMS
*
* Copyright (C) 2014 Filipe Coelho <[email protected]>
* Copyright (C) 2014-2018 Filipe Coelho <[email protected]>
*
* This file is part of LMMS - https://lmms.io
*
Expand All @@ -24,9 +24,6 @@

#include "carla.h"

#define REAL_BUILD // FIXME this shouldn't be needed
#include "CarlaHost.h"

#include "Engine.h"
#include "Song.h"
#include "gui_templates.h"
Expand Down Expand Up @@ -132,14 +129,6 @@ static const char* host_ui_save_file(NativeHostHandle, bool isDir, const char* t

// -----------------------------------------------------------------------

CARLA_EXPORT
const NativePluginDescriptor* carla_get_native_patchbay_plugin();

CARLA_EXPORT
const NativePluginDescriptor* carla_get_native_rack_plugin();

// -----------------------------------------------------------------------

CarlaInstrument::CarlaInstrument(InstrumentTrack* const instrumentTrack, const Descriptor* const descriptor, const bool isPatchbay)
: Instrument(instrumentTrack, descriptor),
kIsPatchbay(isPatchbay),
Expand All @@ -161,8 +150,9 @@ CarlaInstrument::CarlaInstrument(InstrumentTrack* const instrumentTrack, const D
path.cdUp();
resourcesPath = path.absolutePath() + "/share/carla/resources";
#elif defined(CARLA_OS_MAC)
// assume standard install location
resourcesPath = "/Applications/Carla.app/Contents/MacOS/resources";
// parse prefix from dll filename
QDir path = QFileInfo(dllName).dir();
resourcesPath = path.absolutePath() + "/resources";
#elif defined(CARLA_OS_WIN32) || defined(CARLA_OS_WIN64)
// not yet supported
#endif
Expand Down Expand Up @@ -254,7 +244,7 @@ void CarlaInstrument::handleUiClosed()
emit uiClosed();
}

intptr_t CarlaInstrument::handleDispatcher(const NativeHostDispatcherOpcode opcode, const int32_t index, const intptr_t value, void* const ptr, const float opt)
intptr_t CarlaInstrument::handleDispatcher(const NativeHostDispatcherOpcode opcode, const int32_t, const intptr_t, void* const, const float)
{
intptr_t ret = 0;

Expand All @@ -267,13 +257,10 @@ intptr_t CarlaInstrument::handleDispatcher(const NativeHostDispatcherOpcode opco
qApp->processEvents();
break;
default:
break;
break;
}

return ret;

// unused for now
(void)index; (void)value; (void)ptr; (void)opt;
}

// -------------------------------------------------------------------
Expand Down Expand Up @@ -448,9 +435,12 @@ bool CarlaInstrument::handleMidiEvent(const MidiEvent& event, const MidiTime&, f

PluginView* CarlaInstrument::instantiateView(QWidget* parent)
{
// Disable plugin focus per https://bugreports.qt.io/browse/QTBUG-30181
#ifndef CARLA_OS_MAC
if (QWidget* const window = parent->window())
fHost.uiParentId = window->winId();
else
#endif
fHost.uiParentId = 0;

std::free((char*)fHost.uiName);
Expand Down
18 changes: 15 additions & 3 deletions plugins/carlabase/carla.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* carla.h - Carla for LMMS
*
* Copyright (C) 2014 Filipe Coelho <[email protected]>
* Copyright (C) 2014-2018 Filipe Coelho <[email protected]>
*
* This file is part of LMMS - https://lmms.io
*
Expand All @@ -27,7 +27,19 @@

#include <QtCore/QMutex>

#include "CarlaNative.h"
#define REAL_BUILD // FIXME this shouldn't be needed
#if CARLA_VERSION_HEX >= 0x010911
#include "CarlaNativePlugin.h"
#else
#include "CarlaBackend.h"
#include "CarlaNative.h"
#include "CarlaUtils.h"
CARLA_EXPORT
const NativePluginDescriptor* carla_get_native_patchbay_plugin();

CARLA_EXPORT
const NativePluginDescriptor* carla_get_native_rack_plugin();
#endif

#include "Instrument.h"
#include "InstrumentView.h"
Expand All @@ -44,7 +56,7 @@ class PLUGIN_EXPORT CarlaInstrument : public Instrument
CarlaInstrument(InstrumentTrack* const instrumentTrack, const Descriptor* const descriptor, const bool isPatchbay);
virtual ~CarlaInstrument();

// CarlaNative functions
// Carla NativeHostDescriptor functions
uint32_t handleGetBufferSize() const;
double handleGetSampleRate() const;
bool handleIsOffline() const;
Expand Down
4 changes: 2 additions & 2 deletions plugins/carlapatchbay/carlapatchbay.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* carlapatchbay.cpp - Carla for LMMS (Patchbay)
*
* Copyright (C) 2014 Filipe Coelho <[email protected]>
* Copyright (C) 2014-2018 Filipe Coelho <[email protected]>
*
* This file is part of LMMS - https://lmms.io
*
Expand Down Expand Up @@ -36,7 +36,7 @@ Plugin::Descriptor PLUGIN_EXPORT carlapatchbay_plugin_descriptor =
QT_TRANSLATE_NOOP( "pluginBrowser",
"Carla Patchbay Instrument" ),
"falkTX <falktx/at/falktx.com>",
0x0195,
CARLA_VERSION_HEX,
Plugin::Instrument,
new PluginPixmapLoader( "logo" ),
NULL,
Expand Down
4 changes: 2 additions & 2 deletions plugins/carlarack/carlarack.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* carlarack.cpp - Carla for LMMS (Rack)
*
* Copyright (C) 2014 Filipe Coelho <[email protected]>
* Copyright (C) 2014-2018 Filipe Coelho <[email protected]>
*
* This file is part of LMMS - https://lmms.io
*
Expand Down Expand Up @@ -36,7 +36,7 @@ Plugin::Descriptor PLUGIN_EXPORT carlarack_plugin_descriptor =
QT_TRANSLATE_NOOP( "pluginBrowser",
"Carla Rack Instrument" ),
"falkTX <falktx/at/falktx.com>",
0x0195,
CARLA_VERSION_HEX,
Plugin::Instrument,
new PluginPixmapLoader( "logo" ),
NULL,
Expand Down

0 comments on commit f3d4019

Please sign in to comment.