CLAP plugin SDK for MPC Simple
by mikefeedback · mikefeedback/mpc-simple-plugin-sdk
A C++ SDK, extensions and example plugins for building CLAP plugins that run in MPC Simple, the custom OS for the Akai MPC Sample.
About
MPC Simple Plugin SDK
Everything you need to write CLAP plugins for MPC Simple, the custom OS for the Akai MPC Sample: MPC Simple's CLAP extensions, a C++ SDK, and examples that build for the unit.
Every effect, instrument and sample process in MPC Simple is a CLAP plugin. Yours go on the SD card and run through the same host as the built-in ones.
| Kind | Where it's used | What it is |
|---|---|---|
| Effect | Any insert slot: pads, programs, returns, the main outputs | Audio in, audio out |
| Instrument | A plugin program's Instrument | Notes in, audio out |
| Process | Sample Edit's PROCESS | A whole sample in, one or more samples out |
What's here
include/mpcsimple/ MPC Simple's CLAP extensions, plain C (need only the CLAP headers)
mpcs_screen_ext.h com.mpcsimple.screen/1: a page of the plugin's own
mpcs_pads_ext.h com.mpcsimple.pads/1: a page that plays the pads, lights them, SHIFT + F1 / F3
mpcs_fx_ext.h param hints, param text, sidechain bus
mpcs_process_ext.h com.mpcsimple.sample-process/1: Sample Edit PROCESS plugins
sdk/ the C++ SDK (C++20): describe a plugin, write its DSP
third_party/clap/ CLAP 1.2.6 headers (MIT)
examples/
scope_synth/ plain C, no SDK: an instrument with its own animated page
sdk_utility/ SDK: the smallest effect (three settings)
sdk_compressor/ SDK: an effect with a page and live meters
cmake/aarch64-mpc.cmake cross toolchain for the unit
tools/check_unit_libs.sh checks a .clap will load on the unit
Building for the unit
On Linux (or WSL) with gcc-aarch64-linux-gnu / g++-aarch64-linux-gnu and CMake 3.17+:
cmake -B build -DCMAKE_TOOLCHAIN_FILE=cmake/aarch64-mpc.cmake -DCMAKE_BUILD_TYPE=Release
cmake --build build
tools/check_unit_libs.sh build/clap/*.clap
The .clap files land in build/clap/. Without the toolchain file you get
builds for your own computer, handy for testing with a desktop CLAP host.
The unit's libraries: glibc 2.39 and GCC 13's libstdc++. The CMake setup
links libstdc++ and libgcc into each plugin and pins a few libm functions
(sdk/glibc_compat.c), so a newer compiler works. check_unit_libs.sh tells
you if a plugin still asks for something newer.
Installing on the unit
Copy the .clap into MPC-Simple/Plugins/ on the SD card (subfolders are fine)
and restart MPC Simple. Effects show up in the effect lists, instruments in a
plugin program's Instrument browser (sorted by their CLAP features, such as
synthesizer), processes in Sample Edit's PROCESS.
The card is mounted noexec: at each start MPC Simple copies every .clap to RAM
and runs the copy. Everything else in the folder is linked from the card, so a
data folder beside your .clap is found through the path CLAP passes to
clap_entry.init(). A shared library beside it is not copied: link what you
need into the .clap.
Plugins get a normal Linux environment: HOME is MPC-Simple/Home on the card,
the XDG_* folders are under it, TMPDIR is /tmp (RAM).
How MPC Simple decides the kind
The first rule that fits:
- It offers
com.mpcsimple.sample-process/1: a process. - It has no note input port (
clap.note-ports): an effect. - It has a note input and the feature
instrument: an instrument;audio-effect: an effect. - Otherwise, a note input plus an audio input is an effect, a note input alone an instrument.
One .clap can hold effects, instruments and processes together.
A page of its own (com.mpcsimple.screen/1)
MPC Simple has no window system: no clap.gui. Instead a plugin can draw a page
of its own, 320 x 160 pixels between the soft keys and the knob values. On
the unit, F2 switches between the page (VIEW) and MPC Simple's list of the
plugin's settings (SETTINGS).
- Offer
mpcs_plugin_screen_tfromget_extension(MPCS_EXT_SCREEN):open(),close(),draw()and an optionalcursor_order(). draw()gets MPC Simple's drawing functions (mpcs_host_screen_t: rectangles, lines, polylines, text at 16/18/22/28 px, a level meter, images) and what to highlight. Take colors fromcolor()by name ("base","inset","text","accent","wave"...) so the page follows the user's theme.- MPC Simple keeps the controls. The knobs set the current page's settings;
the encoder moves a cursor over the settings and pressing it edits one.
draw()is told the cursor (focus->cursor) and whether it's being edited: draw the highlight. Read settings withvalue(); they're what the knobs show, even before the audio has them. - Animation: call
request_redraw()(fromdraw()is fine) for another frame. MPC Simple draws at most 30 frames a second, only while the page shows. - Live values (meters, a playhead, a waveform) are written by the audio
thread and read in
draw()through atomics.examples/scope_synthdoes exactly this. - Each draw must take under 3 ms. A page that runs over three times in a row is turned off until MPC Simple next starts; the plugin keeps its SETTINGS list.
- A page of a slot that isn't playing is drawn by an idle copy of the plugin, so its meters rest.
With the SDK, override hasView() and draw(View&) instead; the SDK offers the
extension for you (see sdk/mpcs_effect.h and sdk/stock_pages.h).
A page that plays the pads (com.mpcsimple.pads/1)
A plugin with a page can take the pads while that page shows. They then play the plugin instead of the program:
- Every running copy gets each pad on its note input port:
CLAP_EVENT_NOTE_ON(key = the pad, 0-127: bank A pad 1 = 0, bank B pad 1 = 16), the held pad's pressure asCLAP_EVENT_NOTE_EXPRESSION/CLAP_NOTE_EXPRESSION_PRESSURE, andCLAP_EVENT_NOTE_OFF. - The page's own instance hears
pad()on the main thread too, to pick what the knobs show (show_section) and redraw. set_lightlights pads (0xRRGGBB). Once a plugin lights any pad, the pads it hasn't lit are off; set them all back toMPCS_PAD_LIGHT_HOSTto hand them back.set_valuechanges one of its settings as the user would (saved, undoable, sent to every copy).- SHIFT + F1 and SHIFT + F3 are its own:
key_infogives each a label and the actions it takes (click, double click, long press),keyreports one.
With the SDK: withPads(def), then override Dsp::noteOn / notePressure /
noteOff (audio thread) and pad / keyInfo / key (UI thread); the
Pads& they get lights the pads, reads and sets values, and picks sections.
MPC Simple's other extensions
All optional, all plain C, in include/mpcsimple/.
| Extension | What it does |
|---|---|
com.mpcsimple.param-hints/1 |
curve(): a log knob curve (Hz, ms, Q). step(): one encoder step. summary(): short text for slot lists. |
com.mpcsimple.param-text/1 |
A setting's text given all the slot's settings. |
com.mpcsimple.sidechain-bus/1 |
Marks a send effect; any effect with a second audio input gets a Sidechain field (Off, Bus 1-4). |
com.mpcsimple.sample-process/1 |
Makes the plugin a Sample Edit PROCESS (also add the feature mpcsimple-sample-process). |
Writing an SDK plugin
An SDK plugin is one .cpp: a class that does the DSP and an MPCS_EFFECT(<name>)
block that describes it (settings, pages, presets, instrument or effect). See
the top of sdk/mpcs_effect.h and the two SDK examples. Add yours to
CMakeLists.txt with:
mpcs_sdk_plugin(myfx path/to/myfx.cpp)
sdk/dsp.h has building blocks (an RBJ biquad, PolyBLEP oscillators and more);
sdk/voice_mode.h does Poly / Mono / Legato voices for instruments.
Threading
| Thread | What runs there |
|---|---|
| Main (the user interface) | Create / destroy, activate, parameters and their text, state, presets, the page's draw() |
| Audio | process(), with parameter changes and notes as events |
| A worker | A sample process's run() (as long as it needs) |
On the audio thread never allocate, lock, wait, read files or print. MPC Simple
answers clap.thread-check, and calls on_main_thread() after request_callback().
Instruments get CLAP note events (note_id -1, port 0, channel 0, velocity
0-1); a note-off with key -1 means all notes off. Sample rate is 44.1 kHz.
Porting an existing CLAP plugin
Cross-compile the plugin's own source for 64-bit ARM Linux with
cmake/aarch64-mpc.cmake, link its libraries in statically, and check it with
tools/check_unit_libs.sh. The plugin's code isn't changed. Surge XT runs this way.
License
MIT (see LICENSE). The CLAP headers are MIT, (c) the CLAP authors
(third_party/clap/LICENSE).
Something wrong or missing?
Suggest an edit on GitHub — accepted changes credit you as a contributor.