Giter VIP home page Giter VIP logo

clap-host's Introduction


Minimal Clap Host

This repo serves as an example to demonstrate how to create a CLAP host.

Notes on static build vs dynamic build

The host uses Qt for its GUI. It is fine to dynamically link to Qt, but it is not for a plugin. We offer two options:

  • static build, cmake preset: ninja-vcpkg or vs-vcpkg on Windows.
  • dynamic builg, cmake preset: ninja-system

Static builds are convenient for deployment as they are self containded.

Dynamic builds will get your started quickly if your system provides Qt6. Static builds will require more time and space.

Building on macOS

dynamic build using brew (recommended)

# Install dependencies
brew install qt6 pkgconfig rtaudio rtmidi ninja cmake

# Checkout the code
git clone --recurse-submodules https://github.com/free-audio/clap-host
cd clap-host

# Build
cmake --preset ninja-system
cmake --build --preset ninja-system

static build using vcpkg

# Install build tools
brew install cmake ninja

# Checkout the code
git clone --recurse-submodules https://github.com/free-audio/clap-host
cd clap-host
scripts/build.sh

Building on Windows

Enable long path support

Make sure your system supports long paths. Run this in an administrator PowerShell:

New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" -Name "LongPathsEnabled" -Value 1 -PropertyType DWORD -Force

Reference: https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=powershell

static build

Install Visual Studio 2022; you can install it from the Microsoft Store. It can also install git and CMake for you.

Use the following command inside git-bash:

# Checkout the code very close to the root to avoid windows long path issues...
cd c:\
git clone --recurse-submodules https://github.com/free-audio/clap-host c-h
cd c-h

scripts/build.sh

Building on Linux

dynamic build using system libraries

# on archlinux, adapt to your distribution and package manager
sudo pacman -S qt git ninja cmake rtaudio rtmidi

git clone --recurse-submodules https://github.com/free-audio/clap-host
cd clap-host
cmake --preset ninja-system
cmake --build --preset ninja-system

static build using vcpkg

git clone --recurse-submodules https://github.com/free-audio/clap-host
cd clap-host
scripts/build.sh

clap-host's People

Contributors

abique avatar baconpaul avatar cbix avatar kisielk avatar natureisfrequency avatar prokopyl avatar schroedingers-cat avatar trinitou avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

clap-host's Issues

Keyboard usage for synth plugin badly broken in windows

There are a couple of problems with the built in keyboard usage under windows. For one keyReleaseEvent never sets bit 15 for the engine to find (at least on my machine) and two, auto repeat of the keyboard wreaks major havoc sounding like audio overruns but it is not. It is just retriggering the notes in quick succession.

I have not done github pull requests for a while and I don't know if you are accepting them but at any rate both fixes to main-window.cc can be found below:

void MainWindow::keyPressEvent(QKeyEvent *event) {
Engine *engine = _application.engine();

if (!event->isAutoRepeat()) {
for (int i = 0; i < 8; i++) {
#ifdef _WIN32
if (0 == InterlockedCompareExchange(
(LONG volatile *)&engine->keyboardNoteData[i], event->key(), 0)) {
#else
if (0 == __sync_val_compare_and_swap(&engine->keyboardNoteData[i], 0, event->key())) {
#endif
break;
}
}
}
}

void MainWindow::keyReleaseEvent(QKeyEvent *event) {
Engine *engine = _application.engine();

if (!event->isAutoRepeat()) {
  for (int i = 0; i < 8; i++) {

#ifdef _WIN32
if (0 == InterlockedCompareExchange(
(LONG volatile *)&engine->keyboardNoteData[i], event->key() | 0x8000, 0)) {
#else
if (0 ==
__sync_val_compare_and_swap(&engine->keyboardNoteData[i], 0, 0x8000 | event->key())) {
#endif
break;
}
}
}
}

Don't depend on submodule for clap

On Arch Linux, the clap package installs headers, pkg-config and cmake module files globally so in theory it could be found by cmake. Right now however clap-host's CMakeLists.txt depends on the clap submodule being in a subdirectory.

Feature request: type-to-MIDI (or equivalent)

I'm trying to port my plugin to CLAP beta, and I've built the clap-host project on Linux and it loads and I get audio output, but I don't have a way to send MIDI note on/off to my plugin. My feature request is that there is a way to use the typing keyboard to simulate MIDI note on/off events, as in available in many DAWs. This is currently a roadblock for me with porting my plugin, so I think it is important to add this feature as it will probably be a roadblock for other developers. There could also be another alternative method for simulating note on/off, such as with GUI buttons.

Add 'How to load .clap plugin' to README.md

Took me a moment to see how to load a .clap plugin.
Could something like the following be added to the README.md for future users, cheers

How to load .clap plugin

Replace <PATH_TO_PLUGIN.clap> with your plugin path

Command line example

-p <PATH_TO_PLUGIN.clap>

Vscode launch.json example

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(lldb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/builds/ninja-system/host/Debug/clap-host",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [{ "name": "CLAP_HOST_FORCE_PLUGIN", "value": "<PATH_TO_PLUGIN.clap>" }],
            "externalConsole": false,
            "MIMode": "lldb"
        }
    ]
}

Empty window at startup

Hi, I compiled clap-host under Windows following the Readme instructions.

What is its expected behavior? I tried launching it from command line, with and without the path to a clap plugin (Odin2) as the first argument, and in both case I get an empty Windows (with no available menu or action) and the following console error:
Failed to load plugin ' "" ': "The shared library was not found."

I noticed issue #15 referencing a similar error message, but seemingly later (in my case I cannot even perform the "Select File => Load Native Plugin Preset" step by lack of a menu).

Parameter value changes are ignored when *_GESTURE_BEGIN -> *_PARAM_VALUE * -> _GESTURE_END happen in the same sample

When a plugin begins an automation gesture, sets a value, and then ends the automation gesture all during the same sample clap-host will currently ignore the value change. This is likely because the host doesn't add these events to a queue but rather assigns the event to a parameter index, causing any other events that happened for that parameter to be overridden:

_engineToAppValueQueue.set(ev->param_id, {EngineToAppParamQueueValue::Value, ev->value});

Command line -p works but --plugin doesn't seem to

It seems for me the long version of the command line argument is not working for me. I'm simply passing the exact same path but with --plugin instead of -p.

Can anyone else repro this?

The code that parses the command line arguments looks like correct to me so I'm scratching my head here.

QCommandLineOption pluginOpt(QStringList() << "p"
                                           << "plugin",
                             tr("path to the plugin"),
                             tr("path"));

https://doc.qt.io/qt-6.2/qcommandlineoption.html#QCommandLineOption-3

Linux dynamic build fails on first cmake step

Ubuntu 20.04

$ cd clap-plugins/
$ cmake --preset ninja-system
CMake Error: The source directory "./src/clap-plugins/ninja-system" does not exist.
Specify --help for usage, or press the help button on the CMake GUI.

I don't know enough about cmake or ninja to know what's supposed to happen next. The same error happens with the clap-plugins project.

clap-host does not load clap plugins

How to reproduce

  1. Build clap-host locally or using actions on github
  2. Build Dexed or clap-plugins (clap-plugins.clap) from github locally or on github with github actions
  3. Run clap-host
  4. Select File => Load Native Plugin Preset
  5. Select Dexed.clap or clap-plugins.clap
  6. After clicking OPEN nothing happens

Environment

Ubuntu 22.04 with Pipewire

Screenshot from 2022-06-19 00-21-01

Screenshot from 2022-06-19 00-22-28

gdb output

Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff681b640 (LWP 79650)]
[New Thread 0x7ffff6006640 (LWP 79651)]
[New Thread 0x7ffff5805640 (LWP 79652)]
[New Thread 0x7ffff5004640 (LWP 79653)]
[New Thread 0x7ffff4803640 (LWP 79654)]
Failed to load plugin ' "" ': "The shared library was not found."
[New Thread 0x7fffdd5ff640 (LWP 79656)]
Case insensitive sorting unsupported in the posix collation implementation
Numeric mode unsupported in the posix collation implementation

Questions

why does WebMIDI API show up but not the ALSA or Jack MIDI API ? does this mean a plugin can only communicate to broswer based MIDI ports and how would that work ?

save state

In Jalv (LV2 host) it is possible to save the plugin state in a folder. Could this be added to clap-host as well?

And export to preset?

And restore it.
(
Jalv: Application Options:
-l, --load=DIR Load state from save directory
-p, --preset=URI Load state from preset
)

rtmidi not found when on my system

OS: Kubuntu 22.04.1 LTS x86_64
Laptop: 20HBCTO1WW ThinkPad P51s
Kernel: 5.15.0-52-lowlatency
CPU: Intel i7-7600U (4) @ 3.900GHz

after running cmake --preset ninja-system, I get the following message:

Preset CMake variables:

  CMAKE_EXPORT_COMPILE_COMMANDS:BOOL="TRUE"
  UsePkgConfig:BOOL="TRUE"

-- Could NOT find WrapVulkanHeaders (missing: Vulkan_INCLUDE_DIR) 
-- Checking for module 'rtmidi'
--   No package 'rtmidi' found
CMake Error at /usr/share/cmake-3.22/Modules/FindPkgConfig.cmake:603 (message):
  A required package was not found
Call Stack (most recent call first):
  /usr/share/cmake-3.22/Modules/FindPkgConfig.cmake:825 (_pkg_check_modules_internal)
  CMakeLists.txt:36 (pkg_check_modules)

I checked to see if I have rtmidi installed with apt search rtmidi:


hydrogen/jammy,now 1.1.1+52.gb917e057-1 amd64 [installed,automatic]
  advanced drum machine/step sequencer

libportmidi-dev/jammy,now 1:217-6 amd64 [installed]
  library for real-time MIDI input/output

libportmidi0/jammy,now 1:217-6 amd64 [installed,automatic]
  library for real-time MIDI input/output

librtmidi-dev/jammy 5.0.0-2 amd64
  C++ library for realtime MIDI input/ouput (development files)

librtmidi-doc/jammy,jammy 5.0.0-2 all
  C++ library for realtime MIDI input/ouput (documentation files)

librtmidi6/jammy,now 5.0.0-2 amd64 [installed,automatic]
  C++ library for realtime MIDI input/ouput

midisnoop/jammy,now 0.1.2+git20141108.bc30f600187e-1build3 amd64 [installed,automatic]
  MIDI monitor and prober

python3-rtmidi/jammy,now 1.4.7-1build2 amd64 [installed]
  Python wrapper for the RtMidi C++ library written with Cython

I was going to install librtmidi-dev, but it said it would remove many crucial packages on my system.

Some help on this would be much appreciated!

Incomplete build instructions for Windows

I tried to build this for a project I'm currently working on, noticed that the current instructions for Windows ends with running build.sh, which is not possible, as build.sh is a bash script and therefore not compatible with PowerShell. Are there updated build instructions?

CLAP_EXT_AUDIO_PORTS is ignored

clap-host always provides audio input and output ports. This isn't as per the specs: a plugin that doesn't implement CLAP_EXT_AUDIO_PORTS has zero audio ports.

This leads to problems if plugin developers use clap-host for testing their plugins.

This code from PluginHost::process() is the problem:

_process.audio_inputs = &_audioIn;
_process.audio_inputs_count = 1;
_process.audio_outputs = &_audioOut;
_process.audio_outputs_count = 1;

Build fails on Ubuntu 22.04

Problem

Build fails using the instructions for Linux as provided

How to reproduce

git clone --recurse-submodules https://github.com/free-audio/clap-host
git fetch
git pull origin (up to date)

Changes made

sudo apt-get install ninja-build
sudo apt-get install gettext
sudo apt-get install bison
sudo apt-get install autoconf

make build file executable:
cd scripts
chmod +x build.sh
cd ..
scripts/build.sh

Result

error: building libb2:x64-linux-clap-host failed with: BUILD_FAILED
Please ensure you're using the latest port files with git pull and vcpkg update.
Then check for known issues at:
https://github.com/microsoft/vcpkg/issues?q=is%3Aissue+is%3Aopen+in%3Atitle+libb2
You can submit a new issue at:
https://github.com/microsoft/vcpkg/issues/new?template=report-package-build-failure.md&title=[libb2]+Build+error
Include '[libb2] Build error' in your bug report title, the following version information in your bug description, and attach any relevant failure logs from above.
vcpkg-tool version: 2022-06-15-b0f08e40f8e8752dd0b260138ee078bd9599559c
vcpkg-scripts version: ac6ef2f66 2022-06-15 (2 days ago)

You can also use the prefilled template from clap/clap-host/vcpkg/installed/vcpkg/issue_body.md.

Solution

  1. Run

sudo apt update && sudo apt upgrade && sudo apt install build-essential gperf ninja-build cmake libgl1-mesa-dev libfontconfig1-dev libfreetype6-dev libx11-dev libx11-xcb-dev libxcb-damage0-dev libxcb-dpms0-dev libxcb-glx0-dev libxcb-icccm4-dev libxcb-image0-dev libxcb-keysyms1-dev libxcb-present-dev libxcb-randr0-dev libxcb-record0-dev libxcb-render-util0-dev libxcb-render0-dev libxcb-res0-dev libxcb-shape0-dev libxcb-shm0-dev libxcb-sync-dev libxcb-util-dev libxcb-xfixes0-dev libxcb-xinerama0-dev libxcb-xkb-dev libxcb1-dev libxext-dev libxfixes-dev libxi-dev libxkbcommon-dev libxkbcommon-x11-dev libxrender-dev libatspi2.0-dev

  1. Replace vcpkg (subdirectory of the repo)

rm -r vcpkg
git clone https://github.com/microsoft/vcpkg
./vcpkg/bootstrap-vcpkg.sh

No audio input ports

clap-host 1.0.2 on Linux + PipeWire (jack/alsa/pulse) doesn't provide any way to connect audio inputs, only outputs are created. This is fine for synthesizer/instrument plugins but not for effects.

Couldn't test latest master since that doesn't build at all.

Host crashes when selecting a preset in the plugin.

When I select a preset in Surge XT, the host crashes with an error.
terminate called after throwing an instance of 'std::logic_error'
what(): a parameter's info did change, but the flag CLAP_PARAM_RESCAN_INFO was not specified; id: 3032669660, name: FX S1 Left, module: /Global & FX/

Aborted (core dumped)

This problem is not present in other hosts, like Bitwig and Qtractor.

I'm using arch linux and night build of Surge

Video demonstration:
https://youtu.be/vAh8CtNEfCw

Build fails on Fedora 36

Bash log:

$ cmake --build --preset ninja-system
[1/3] Building CXX object host/CMakeFi...t.dir/Debug/audio-settings-widget.cc.o
FAILED: host/CMakeFiles/clap-host.dir/Debug/audio-settings-widget.cc.o 
/usr/lib64/ccache/c++ -DQT_CORE_LIB -DQT_GUI_LIB -DQT_WIDGETS_LIB -DCMAKE_INTDIR=\"Debug\" -I/home/<redacted>/Desktop/clap-host/builds/ninja-system/host -I/home/<redacted>/Desktop/clap-host/host -I/home/<redacted>/Desktop/clap-host/builds/ninja-system/host/clap-host_autogen/include_Debug -I/home/<redacted>/Desktop/clap-host/clap-helpers/include -I/home/<redacted>/Desktop/clap-host/clap/include -isystem /usr/include/qt6/QtWidgets -isystem /usr/include/qt6 -isystem /usr/include/qt6/QtCore -isystem /usr/lib64/qt6/mkspecs/linux-g++ -isystem /usr/include/qt6/QtGui -isystem /usr/include/rtmidi -isystem /usr/include/rtaudio -g -fvisibility=hidden -fvisibility-inlines-hidden -Werror=return-type -Werror=unused-result -Wno-unused-parameter -Wuninitialized -Wvla -Wmultichar -Werror=non-virtual-dtor -Woverloaded-virtual -pthread -D__UNIX_JACK__ -D__LINUX_ALSA__ -D_REENTRANT -D__LINUX_PULSE__ -Winvalid-pch -include /home/<redacted>/Desktop/clap-host/builds/ninja-system/host/CMakeFiles/clap-host.dir/Debug/cmake_pch.hxx -MD -MT host/CMakeFiles/clap-host.dir/Debug/audio-settings-widget.cc.o -MF host/CMakeFiles/clap-host.dir/Debug/audio-settings-widget.cc.o.d -o host/CMakeFiles/clap-host.dir/Debug/audio-settings-widget.cc.o -c /home/<redacted>/Desktop/clap-host/host/audio-settings-widget.cc
/home/<redacted>/Desktop/clap-host/host/audio-settings-widget.cc: In member function ‘void AudioSettingsWidget::initApiList()’:
/home/<redacted>/Desktop/clap-host/host/audio-settings-widget.cc:73:60: error: ‘getApiDisplayName’ is not a member of ‘RtAudio’
   73 |       _apiChooser->addItem(QString::fromStdString(RtAudio::getApiDisplayName(api)));
      |                                                            ^~~~~~~~~~~~~~~~~
/home/<redacted>/Desktop/clap-host/host/audio-settings-widget.cc:74:35: error: ‘getApiName’ is not a member of ‘RtAudio’
   74 |       if (selectedApi == RtAudio::getApiName(api))
      |                                   ^~~~~~~~~~
/home/<redacted>/Desktop/clap-host/host/audio-settings-widget.cc: In member function ‘void AudioSettingsWidget::saveSettings()’:
/home/<redacted>/Desktop/clap-host/host/audio-settings-widget.cc:204:28: error: ‘getApiName’ is not a member of ‘RtAudio’
  204 |    auto apiName = RtAudio::getApiName(getSelectedAudioApi());
      |                            ^~~~~~~~~~
[2/3] Building CXX object host/CMakeFiles/clap-host.dir/Debug/engine.cc.o
FAILED: host/CMakeFiles/clap-host.dir/Debug/engine.cc.o 
/usr/lib64/ccache/c++ -DQT_CORE_LIB -DQT_GUI_LIB -DQT_WIDGETS_LIB -DCMAKE_INTDIR=\"Debug\" -I/home/<redacted>/Desktop/clap-host/builds/ninja-system/host -I/home/<redacted>/Desktop/clap-host/host -I/home/<redacted>/Desktop/clap-host/builds/ninja-system/host/clap-host_autogen/include_Debug -I/home/<redacted>/Desktop/clap-host/clap-helpers/include -I/home/<redacted>/Desktop/clap-host/clap/include -isystem /usr/include/qt6/QtWidgets -isystem /usr/include/qt6 -isystem /usr/include/qt6/QtCore -isystem /usr/lib64/qt6/mkspecs/linux-g++ -isystem /usr/include/qt6/QtGui -isystem /usr/include/rtmidi -isystem /usr/include/rtaudio -g -fvisibility=hidden -fvisibility-inlines-hidden -Werror=return-type -Werror=unused-result -Wno-unused-parameter -Wuninitialized -Wvla -Wmultichar -Werror=non-virtual-dtor -Woverloaded-virtual -pthread -D__UNIX_JACK__ -D__LINUX_ALSA__ -D_REENTRANT -D__LINUX_PULSE__ -Winvalid-pch -include /home/<redacted>/Desktop/clap-host/builds/ninja-system/host/CMakeFiles/clap-host.dir/Debug/cmake_pch.hxx -MD -MT host/CMakeFiles/clap-host.dir/Debug/engine.cc.o -MF host/CMakeFiles/clap-host.dir/Debug/engine.cc.o.d -o host/CMakeFiles/clap-host.dir/Debug/engine.cc.o -c /home/<redacted>/Desktop/clap-host/host/engine.cc
/home/<redacted>/Desktop/clap-host/host/engine.cc: In member function ‘void Engine::start()’:
/home/<redacted>/Desktop/clap-host/host/engine.cc:95:45: error: ‘getCompiledApiByName’ is not a member of ‘RtAudio’
   95 |          std::make_unique<RtAudio>(RtAudio::getCompiledApiByName(deviceRef._api.toStdString()));
      |                                             ^~~~~~~~~~~~~~~~~~~~
ninja: build stopped: subcommand failed.

Build failing on qtbase using static build script on Arch

Running

static build using vcpkg

git clone --recurse-submodules https://github.com/free-audio/clap-host
cd clap-host
scripts/build.sh

Produces:

ERROR: Feature "egl": Forcing to "ON" breaks its condition:
    ( QT_FEATURE_opengl OR QT_FEATURE_openvg ) AND EGL_FOUND AND ( QT_FEATURE_dlopen OR NOT UNIX OR INTEGRITY )
Condition values dump:
    QT_FEATURE_opengl = "OFF"
    QT_FEATURE_openvg = "OFF"
    EGL_FOUND = "TRUE"
    QT_FEATURE_dlopen = "ON"
    UNIX = "1"
    INTEGRITY = "0"


CMake Error at cmake/QtBuildInformation.cmake:194 (message):
  Check the configuration messages for an error that has occurred.
Call Stack (most recent call first):
  cmake/QtBuildInformation.cmake:24 (qt_configure_print_summary)
  cmake/QtBuildInternals/QtBuildInternalsConfig.cmake:593 (qt_print_feature_summary)
  CMakeLists.txt:211 (qt_build_repo_end)


-- Configuring incomplete, errors occurred!
ninja: build stopped: subcommand failed.``` 

Linux 6.6.26-1-MANJARO #1 SMP PREEMPT_DYNAMIC x86_64 GNU/Linux

clap_event_note id field uninitialized

PluginHost::processNoteOn does not set the value of id in the structure clap_event_note. From what I can tell, this field reaches the plugin uninitialized. Similarly in processNoteOff.

select plugin from the gui

When launching the simple LV2 host jalv.gtk (latest version), it is possible to select the plugin from the gui. Would it be possible to add a way to select a plugin in the gui of clap-host?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.