0.5.0 Audio Programming Environment Manual
0.5.0 Audio Programming Environment Manual
Table of contents
INTRODUCTION 3 Plugin SDK 15
Parameter controls 9
RELEASES AND CHANGELOG 20
Alpha 0.5.0 21
CONFIGURATION 10
Alpha 0.3.0 23
Application settings 10
Alpha 0.2 23
Editor settings 11
Alpha 0.1 23
Language settings 12
LICENSES 23
CPPAPE: USER SCRIPTING & API
DOCUMENTATION 13 CREDITS AND THANKS 24
Plugin anatomy: Getting started 13
DOWNLOADS, VIDEOS, CONTACT, LINKS 24
Methods for basic events and callbacks 14
Details on lifetime, locals, exceptions 14 ENDNOTES 25
Nesting plugins 14
2
Manual - Audio Programming Environment 07-02-2021
Version 0.5.0 Lightbridge Studios
Introduction
Welcome to the manual for the APE program, Audio Programming Environment. APE is my biggest procrastina-
tion yet, having struggled to learn to write DSP code in a practical manner. I grew tired of spending most of my time
writing interfaces, frameworks, GUI's and whatnot, managing different libraries, dependencies etc. for very small
plugins until I ultimately decided that it would be better to abstract the whole package away - enter APE.
APE is a comparatively small program that hosts user-written code and integrates it into the signal path of your
host program. It provides a set of commonly used math and DSP tools, and a generally idiomatic plugin declaration
syntax - that maps to a final plugin SDK well - to hit the ground running. Integrated, automatable real time parame-
ters with automatic UI to adjust variables inside your code, and access to certain system information like tempo,
channels etc. together with a console and an editor allows easy development and testing.
APE's intended use is the development process - testing out and fine-tuning algorithms in an efficient manner
before integrating it into your primary project. It allows for on-the-fly compilation and testing; hence iteration speed
is fundamental and very optimized.
You don't have to worry about anything but the actual relevant code, since it's intended to provide a simple intro-
duction to writing DSP code. It is therefore an ideal tool for teaching/educational projects and demonstrating small
algorithms and / or effects.
I hope that someday it will evolve into a user provided library of effects with a working implementation, with a
design that allows to easily use the code in your own projects. Many great sites on the internet provide a lot of great
examples, though they are mostly scattered, incomplete and with a difficult path to testing.
If you are more of a visual type, see the following videos:
Rundown of features: https://youtu.be/srJ6EWiXOTo
Developing an effect: https://youtu.be/7_jtCDy39FU
Features
Completely self-contained - ships with SDKs, compiler, linker, editor, console and runtime
Bleeding edge Clang/LLVM C++ compiler for class leading diagnostics and code optimization
Full C++17 support (partial C++20 support)
Most of the C++ standard library included (containers, math, numeric, algorithmic etc.)
I/O Audio file streaming with a variety of codecs
System-level exception handling to avoid crashing your host on small errors like integral division
Console with logging
Themeable editor with syntax highlighting
Oscilloscope with expression evaluation
Precise, smoothed automatable parameters
Built-in optimized FFTs
26 included effect scripts that are documented (54 legacy scripts for inspiration, as well)
Extensible backend with ability to interface to any compiler installed on the computer - write in any language
you want!
Cross platform support (AU/VST Windows, OS X, Linux for anyone who wants to compile it)
Extensive configuration file
3
Manual - Audio Programming Environment 07-02-2021
Version 0.5.0 Lightbridge Studios
WIP features
Support for compilation of programs to self-contained plugins
Support for presets
Actual AST expression evaluator for oscilloscope, not just a define hack
Integrated projects and tabbed editor
Explodable GUI and better graphics (for controls, as well), less taxing
More languages supported, potentially Python
Stable releases for Linux variants
Instrument / MIDI support
Standalone workflow support
Release / debug switchable code generation (current: optimized debug)
User-toggleable oversampling factor
Scrollable, selectable console
FPU exceptions and control flow
Requirements
Minimum
Processor: 1 GHz, SSE 4.2
RAM: 4 gigabytes
Disk: 200 megabytes free
Graphics: OpenGL 2 compatible
Recommended
Processor: 3 GHz, AVX2, 4 cores+
RAM: 8 gigabytes
Disk: SSD, 1 gigabyte free
Graphics: Discrete, 2 gigabyte RAM, OpenGL 3.0
Experimental support
(These require building the plugin from source)
Audio Unit 2 - 3, VST 2.4 - 3.6, AAX: MacOS 10.8 - 10.15
VST 2.4 - 3.6, AAX: Windows XP - Windows 10
VST 2.4 - 3.6: Debian, Ubuntu
4
Manual - Audio Programming Environment 07-02-2021
Version 0.5.0 Lightbridge Studios
User interface
The UI uses a composite tabbed/dockable system to better utilize screen real estate. There are five main tabs you
will work with:
1. The code editor
2. The running plugin UI
3. Console
4. Oscilloscope
5. Settings pane of the oscilloscope.
But for now, let us look at the plugin when you open it the first time - and how the general UI is structured.
Splash
5
Manual - Audio Programming Environment 07-02-2021
Version 0.5.0 Lightbridge Studios
Editor tab
This is the code editor - the heart of the plugin. Changes you make in here reflect
whenever you recompile. It supports standard operations as shown to the right, with
syntax highlighting for C++.
The editor by default auto indents your code, and you can scale the text size by
holding control and scrolling. Defaults for these, as well as colour scheming, can be
edited in the Editor settings.
6
Manual - Audio Programming Environment 07-02-2021
Version 0.5.0 Lightbridge Studios
Menus
File
New File Create a completely blank file
New from Template This loads the template file, as configured in the
Language settings
Open... Open any file
Open recent... Open from a list of recently touched files
Save Save the current contents into the file, if it already exists
Save as... Save the current contents into a custom location
Open home... Open the home directory of your scripts, as configured in the
Language settings
Edit
Edit externally This will open the file in your system's default editor and watch it for changes.
Whenever you save the file externally, APE will recompile the session automati-
cally.
Build
Compile Compile your script, but not activate it.
Compile and Run Recompile your script and activate it if possible - crossfading the old sound with
the new one.
Activate Activate any currently compiled script. Activating and deactivating is a fast way of
turning your script on and off.
Deactivate Deactivate any active script.
Clean This cleans the cached compilation of the runtime and library code - this is useful
if you are developing or rewriting the runtime code (separate from the plugin
code).
Scope probe
This is an experimental feature, but when used properly,
it's an indispensable tool for understanding your code - it
specifically aims to provide a similar workflow to oscillo-
scope probing in analog circuits.
Clicking to the left of the line numbers in the editor inserts
a "probing point" at an expression, which will - after a recom-
pile - display it as an audio signal, with a sample every time
the expression is evaluated. As you can see in the legend,
there's now a new signal titled after the expression line you
probed. You can probe up to 16 lines simultaneously.
This only really makes sense in a rendering context, and
the plugin will protect you to some degree if you place a
breakpoint that isn't called from a processing callback. Simi-
larly, if you try to probe something that's not really an expres-
sion.
If your expression is evaluated at a different rate than your sampling rate, it will be resampled.
There's basic support for data types that can be converted to floating point values, including complex numbers. You
can add traits support for custom data types - see the implementation here.
7
Manual - Audio Programming Environment 07-02-2021
Version 0.5.0 Lightbridge Studios
The oscilloscope displays a real time signal of your plugin's input and outputs, together with any scope probing
points you have added - see Scope probe. You can drag around in the display and zoom in/out with the mouse wheel.
You can configure the oscilloscope in the settings tab:
For more information on how to use the oscilloscope, please check out the documentation and general usage of
Signalizer instead.
Console tab
The console will in detail print info, warning and error messages from the GUI, compiler and runtime instances.
If something goes wrong, you can find it in here. You can also print to the console from the plugin - see the various
print APIs: print.h
You can also log the console to disk - see Configuration.
8
Manual - Audio Programming Environment 07-02-2021
Version 0.5.0 Lightbridge Studios
Plugin tab
When you have an active, running plugin, a
new tab is opened for the parameters and
widgets for the plugin script.
Parameter controls
Some of the widgets display various me-
tered values like plots, but most importantly are
the parameter controls. A complete list of widg-
ets that can appear on the screen are defined
here, in the online documentation. As for the in-
teractive controls for parameters, there are
three types:
1. Knobs / sliders - for a range of values
2. Combo boxes - for a choice of predefined values
3. Buttons - for toggles.
The UI controllers for parameter values in scripts are automatically created and managed, with a class depending
on the defined parameter type in the script. Knobs are for ranges (regardless of whether they are floating point or
discrete), combo boxes are for enumerations while buttons are for boolean values.
The controllers reflect changes in parameters from the script or the host as well, as the parameters can be
automated. Combo boxes and buttons have the simplest interface: Click them to change the value.
Combo box Button
Idle
Clicked
9
Manual - Audio Programming Environment 07-02-2021
Version 0.5.0 Lightbridge Studios
Configuration
The configuration file resides in the root of the APE directory and is called config.cfg. APE uses the open source
library libconfigi to read and parse the configuration file. The syntax is easy and structured, and can be learned from
the linked homepage. Currently, the file consists of two segments, the application- and language settings.
Application settings
This section contains the global application settings.
application:
{
log_console = false;
use_buffers = true;
use_fpe = false;
num_channels = 2;
force_single_precision = true;
greeting_shown = true;
unique_id = 1634755960;
ui_refresh_interval = 80;
console_std_writing = false;
autosave_interval = 60;
render_opengl = false;
use_tcc_convention_hack = true;
preserve_parameters = true;
}
10
Manual - Audio Programming Environment 07-02-2021
Version 0.5.0 Lightbridge Studios
Editor settings
This section controls the code editor component.
editor:
{
zoom = 1.20;
x_offset = 50;
y_offset = 50;
auto_indent = true;
enable_scopepoints = true;
check_restored_against_disk = true;
external_edit_command_line = "";
hkey_save = "cmd+s";
hkey_open = "cmd+o";
hkey_new = "cmd+n";
hkey_externaledit = "f10";
hkey_compile = "f7";
hkey_run = "f5";
hkey_clean = "f8";
hkey_activate = "f3";
hkey_deactivate = "f4";
colours:
{
background = "FF1E1E1E";
highlight = "FF264F78";
caret = "FFFFFFFF";
line_number:
{
background = "FF1E1E1E";
text = "FF7E7EAE";
}
}
}
Beyond ability to adjust general editor color scheme and hotkeys, there's a couple of UX settings:
Name Type Description
zoom float controls the text point scaling, based on a standard 12 point mono-
spaced font.
x_offset & y_offset integer ignored currently
auto_indent boolean controls whether a newline is automatically indented similarly to the
previous line
enable_scopepoints boolean if true, scope points will be enabled. Otherwise, they are ignored. See
usage in Scope probe.
check_restored_against_disk boolean if true, whenever a session is reloaded, the plugin script contents
will be compared against the disk version. If different, the user will
be asked whether they want to use the disk version instead.
external_edit_command_line string by default, when editing a file externally, the system shell will be in-
voked with just the path to the file. With this setting, you can prepend
some arguments or select a particular program.
This will allow you to change the hotkeys of the editor. cmd is command on OSX and control on Windows.
11
Manual - Audio Programming Environment 07-02-2021
Version 0.5.0 Lightbridge Studios
Language settings
This section contains the language settings. It has the following structure:
languages:
{
default = "c";
default_file = "examples/template.c";
<languagen-specification>
}
The default setting is the default language that the editor will select, and what will be assumed if you save a file
without extension. default_file is what the editor will open on a fresh load, or when you use the "New from tem-
plate" menu option in the editor.
The language specification instructs the program on what to with a specific language. APE supports any number
of language specifications, as languages and compilers are selected and identified from the file extensions. They
have the following structure:
<language-name>
{
extensions = ("");
compiler:
{
name = "";
path = "";
arguments = "";
exports:
{
<exportn> = <exportn-name>;
}
}
syntax_highlight:
{
error = "FF8B0000";
comment = "FF008000";
keyword = "FF69ADEE";
operator = "FFA6CE2E";
identifier = "FFC8C8C8";
integer = "FF8E9EB3";
float = "FF9E8EB3";
string = "FFD69D85";
bracket = "FFCCB7C0";
punctuation = "FFC9E6BD";
preprocessor_text = "FF556B2F";
}
}
language-name is the name of the language. extensions is a list of strings, comma-separated, that denotes
what file extensions the editor can open and what language they are to be associated with. name is the name of the
compiler (irrelevant, but for debugging), path is the relative path to the module that is the compiler, and arguments
is a classic command line that is passed to the compiler.
exports is an optional group of aliases for the names APE look up. See the section Compiler API for more info.
You can change the name APE looks up by using this pattern:
GetSymbol = "x";
12
Manual - Audio Programming Environment 07-02-2021
Version 0.5.0 Lightbridge Studios
#include <effect.h>
using namespace ape;
GlobalData(Template, "");
public:
private:
GlobalData(Template, "");
Here you declare what plugin is to be instantiated in this file. This needs to be kept in synchronization with the
plugin effect name. The string literal is an optional small description of the plugin.
Next, your choice of base class for your plugin defines available capabilities and callbacks: Effects are uniform
input/output processors, while Generators are plugins that don't take any input but still provide sound. There is also
Transport* variants of these, see the hierarchy here.
13
Manual - Audio Programming Environment 07-02-2021
Version 0.5.0 Lightbridge Studios
Nesting plugins
In order to reuse another plugin, simply #include "your_other_plugin.hpp" in your file, and wrap it inside
your own plugin using the Embedded* class of wrappers.
14
Manual - Audio Programming Environment 07-02-2021
Version 0.5.0 Lightbridge Studios
Plugin SDK
The CppApe plugin SDK is automatically included so long as you #include <effect.h> or #include <gener-
ator.h>. All headers are available as system includes as well, so you can angle bracket parameter.h for instance.
An in-memory precompiled header is automatically created for all standard includes.
15
Manual - Audio Programming Environment 07-02-2021
Version 0.5.0 Lightbridge Studios
Standalone workflow
While it would be nice to have a standalone version, for now the free and open source JUCE Plugin-In Host gen-
erally provides a really good workflow, including patching support, I/O device selection and project recall. I would
suggest just using this, instead of trying to compile the plugin as a standalone for now.
16
Manual - Audio Programming Environment 07-02-2021
Version 0.5.0 Lightbridge Studios
Prerequisites
Note the target plugins that will be produced (e.g. VST2.4 / VST3.6, AAX, AU) needs to be configured in
projects/plugin/JuceLibraryCode/AppConfig.h
Windows 7, 8 or 10:
Git
Python 3.6
Visual Studio 2017 at least, with C++ development installed.
You will need to add your target plugin SDK as an include directory to the Plugin project.
MacOS 10.14+:
Git
Python 3.6
Xcode 10.12
o C++ std::filesystem support:
Brew
Boost
o If building audio units, you probably need to add the old audio unit SDK into the Xcode extras folder.
Xcode command line tools
You will need to add your target plugin SDK as an include directory to the Plugin project.
17
Manual - Audio Programming Environment 07-02-2021
Version 0.5.0 Lightbridge Studios
Building APE
Clone the repository firstly:
Checkout a suitable branch (master for released checkpoints, dev/stable for bleeding edge):
Then, you need to prepare your development setup. This is automated in the prepare.py script:
$ py -3.6 prepare.py
This checks out all submodules, links projects together, downloads any needed SDKs and binaries.
From here on, just open your preferred solution and execute one of the built in targets, like debug, testing or
release / archive.
18
Manual - Audio Programming Environment 07-02-2021
Version 0.5.0 Lightbridge Studios
CreateProject
CompileProject
InitProject
ActivateProject
DisableProject
ProcessReplacing
OnEvent
ReleaseProject
CleanCache
As long as the above functions returns correctly, APE doesn't have to know anything about any specific language
or whatever. Indeed, the compiler may host a client process to do the actual processing, and pass buffers using
shared memory.
If you want to create your own compiler, first take a look at the CppApe project in the repository which is the
current recommended approach. You will find extensive, although slightly out of date, documentation in the former
manual. The following files in the repository provide the skeleton for creating a new compiler, that can be loaded
directly be APE:
CompilerBindings.h
CppCompilerInterface.cpp
ProtoCompiler.hpp
ProtoCompiler is a scaffolding base class for creating an object oriented stateful compiler.
19
Manual - Audio Programming Environment 07-02-2021
Version 0.5.0 Lightbridge Studios
Tcc4APE
Tcc4APE was a restricted subset of the C language. All the same functionality exists as safe API for CppApe: User
scripting & API documentation instead, in a faster and more modern language.
While we had a good run with TCC, its performance is limited and C itself does not provide much in terms of
removing boilerplate.
syswrap
Syswrap is still shipped in source in the repository, but currently not a part of the binary release. It simply hasn't
been ported yet, if you were relying on the feature set please contact me: Downloads, videos, contact, links
Version 0.5.0
o https://bitbucket.org/Mayae/ape/downloads/
Version 0.3.0
o http://jthorborg.com/content/ape/ape_release_0.3.0.zip
20
Manual - Audio Programming Environment 07-02-2021
Version 0.5.0 Lightbridge Studios
Alpha 0.5.0
Released 01-06-2020.
Version controlled
New repository: https://bitbucket.org/Mayae/ape
o New source structure with permanent platform projects
o Most dependencies now included as submodules
o Modular and testable components
o Unit tests
Build system
Headers shared between plugin and user scripts, removes stale errors
Complete rewrite to modern C++
All manual memory management and leaks removed
All UI, utility etc. now uses cpl
Extended platform support, including technical Linux support. See requirements.
Parameters
o Much more precise user controls, with ability to type in precise 64 bit values
o More flexible and extensible format / range options for parameter values
o Enumeration / lists of strings now supported as combo boxes
o Now automatable by host
o 64-bit precision internally
Widgets
o Meters are now per-sample evaluated and properly decaying. Also contains peak markers.
Iteration
o Compatible parameter values preserved
o Hotkeys for all major operations
o True multithreaded compilation across plugins
o Old/new sound blended on swapping instances
Engine
o Optimized and built-in FFT
o Support for streaming audio files to and from disk, optionally resampled
o Audio thread interactions now completely lock free
o Precise transport access and playback state events to the plugin
Quality of life
o SDKs and libraries now ship included, removed reliance on user development setup
o Plugin callbacks for initialization and reconfigurations now run asynchronously to avoid stutter on
audio thread and hiccups on main thread
o Many more checks of resource managements, assertions etc. to make it much more safe
o Working code is serialized into the project as well, instead of referencing a script on disk.
o User is notified mismatched / out-of-date scripts
o Removed nonsensical errors on abandoned save dialogs
o Long operations timed and printed to the console
Plugin GUI
o Resizable
o Redesigned, bit buttons removed in favor of simple icons and hotkeys
o Now completely uses vector graphics instead of bitmaps
o Switched to a tabbed system to increase real estate
o Tabs can be orphaned into separate desktop windows, and redocked back
o Graphics optimized and employs precise redrawing, much faster on OS X using core graphics ren-
derer
o Subpixel text rasterization for normal DPI displays
21
Manual - Audio Programming Environment 07-02-2021
Version 0.5.0 Lightbridge Studios
o Removed "fpu exceptions" and "protected buffers" switches. These are now determined by compi-
lation mode.
Source code editor
o Externally editing files is now supported, reloading and recompiling whenever the file is saved ex-
ternally
o Full project and intellisense when working in the source repository for user scripts
o Evaluate source code expressions as "breakpoints"
o Text scaling
o Auto indentation
o Saving a file without extension and determined language appends the default language extension
o Menu option to open "home" (also configurable) scripting directory
o Menu option to create a new file, cloned from the template file
o Menu options for build events (compile, activate, clean, edit externally etc.)
o Default now with a dark theme
New compiler / language: CppApe
o C++ 17 bleeding edge compiler, based on Clang
o Runtime vehicle is libCppJit: Multithreaded, lazy JIT based on LLVM
o User scripts can now include and use other scripts
o Completely revised front end together with safe and idiomatic user API, boiler plate removed
o Access to most of C++ standard library, based on libcxx
o Subset of C standard library available, based on ccore
o Built-in SIMD vectorized math
o DSP primitives, interpolation algorithms
o Type safe and much faster print() family functions
o 32-bit / 64-bit / 80-bit templated math precision, switchable by user in UI
o Typical scientific math constants available as templated constant expressions
o Complete user API documentation here: TODO
o Assertions supported
o RAII and unwind support
o Some exception support
o Globals, static constructors and destructors supported
o Memory mapped and precompiled system headers for compilation speed
Oscilloscope
o Based on Signalizer
o Per-sample source code expression evaluation and graphing
o Color coded inputs / outputs
o User-defined triggering
Bugs
o Console is now thread safe
o Compilation is now thread safe
o Fixed crashes on immediate deserialization
o Many user file bugs fixed
Tcc4APE
o More or less deprecated, still ships in source form but complete support is missing
o Same for syswrap.
22
Manual - Audio Programming Environment 07-02-2021
Version 0.5.0 Lightbridge Studios
Alpha 0.3.0
Released on 08-04-2014.
Source code rewritten to support JUCE also, which is the primary target platform now.
o this affects several things; notably the editor is switched from Scintilla to JUCE's inbuilt code editor
now
this has the welcome side effect of hotkeys working again
o syntax highlight only for C++ and friends for the moment.
x32 and x64 builds on both Windows and OSx as AudioUnit and VST 2.4
Countless bug fixes / code rewrite
project recall now implemented
autosave now implemented
support for high dpi display
an actual threading- and multi-instance model is now implemented; it should be completely safe to run mul-
tiple plugins in the same or other processes
fix of fpu exceptions
improved header support for other compilers than tcc
Alpha 0.2
Released on 10-02-2014
fixed uninitialized variable 'Engine::clocksPerSample'
scilexer now properly adds filenames to project struct even in case of singleString-compilation
scilexer now properly sets amount of files in the project
the console should now properly print strings with linebreaks in them, this affects the core, api and scripts.
fixed a bug where newlines will crash the console code.
output logging of console now properly contains newlines.
due to larger amounts of info being printed to the console, it is now scrollable and has a longer history
added new compiler: syswrap. syswrap allows to interface to installed system compilers.
fixed a bug where closing the editor would not reset the editor button in APE
pressing the editor button now properly restores the window if user had minimized it before
fixed a memory leak in the TCC compiler (early return caused no deallocation of plugin data)
fixed a wrong return value in CInterface.h
added a new knob function: api.createRangeKnob(). This knob formats its display value based off a minimum,
maximum and a callback function.
fixed a bug where knobs initially would have the wrong format
to enhance c++ compability, 'this' is now an illegal identifier
CInterface.h:
o added new valuestruct: scale
o added f_mod() and f_sin()
o added pi values
o compatized header with various compilers
updated the example scripts to reflect these changes.
Alpha 0.1
Initial version.
Licenses
See /licenses/.
23
Manual - Audio Programming Environment 07-02-2021
Version 0.5.0 Lightbridge Studios
24
Manual - Audio Programming Environment 07-02-2021
Version 0.5.0 Lightbridge Studios
Endnotes
i
libconfig: http://www.hyperrealm.com/libconfig/
ii
clang: https://clang.llvm.org/
iii
ccore: https://bitbucket.org/Mayae/ccore
iv
libc++: https://libcxx.llvm.org/
v
libCppJit: https://bitbucket.org/Mayae/cppjit/src/master/
vi
llvm: http://llvm.org/
vii
kvraudio: http://www.kvraudio.com/
viii
stackoverflow: http://stackoverflow.com/
ix
musicdsp: http://www.musicdsp.org/
x
vstgui: http://sourceforge.net/projects/vstgui/
xi
juce: http://www.juce.com
xii
steinberg: http://www.steinberg.net
xiii
minGW: http://www.mingw.org/
25