[C++] "Hello World" in the Reaper DAW
Full code can be found here.
This article covers creating a Reaper plugins in C++ that prints “Hello world!” to the console.
Plugins are created by building a dynamic link library (DLL) with the reaper software development kit (SDK) and placing it in the UserPlugins
directory.
Project Setup
- Copy
reaper_plugin.h
andreaper_plugin_functions.h
into the project. - For a leaner DLL you can enable only the SDK functions you need by defining
REAPERAPI_MINIMAL
in the preprocessor then usingREAPERAPI_WANT_<function>
to enable specific functions. - Define
REAPERAPI_WANT_ShowConsoleMsg
to print to the console
Building with CMake
I’m using CMake as my build tool so my DLL’s target CMakeLists.txt
looks like this:
add_library(reaper_sdk SHARED
"main.cpp"
"main.hpp"
"reaper_plugin.h"
"reaper_plugin_functions.h"
)
target_compile_definitions(reaper_sdk PRIVATE
REAPERAPI_MINIMAL
REAPERAPI_WANT_ShowConsoleMsg
)
Defining the entry point
Header
The plugins’s entry point function is defined with the SDK’s REAPER_PLUGIN_ENTRYPOINT
macro.
Enable C linkage with extern "C"
and use REAPER_PLUGIN_DLL_EXPORT
from the SDK to export the function’s symbol from the DLL.
Define the header as follows:
#pragma once
#include "reaper_plugin.h"
extern "C" {
REAPER_PLUGIN_DLL_EXPORT
int REAPER_PLUGIN_ENTRYPOINT(HINSTANCE hInstance, reaper_plugin_info_t* rec);
}
Implementation
- Define
REAPERAPI_IMPLEMENT
in a single translation unit to instantiate the SDK’s functions - Create a global variable to store the plugin information struct passed to the entry point function
#define REAPERAPI_IMPLEMENT
#include "reaper_plugin_functions.h"
#include "main.hpp"
reaper_plugin_info_t* g_rec = nullptr;
The entry point function:
extern "C" {
REAPER_PLUGIN_DLL_EXPORT
int REAPER_PLUGIN_ENTRYPOINT(HINSTANCE hInstance, reaper_plugin_info_t* rec) {
if (!rec || (REAPERAPI_LoadAPI(rec->GetFunc) > 0)) {
return 0;
}
// Save the info ptr
g_rec = rec;
ShowConsoleMsg("Hello world!");
return 1;
}
}
- Check that
rec
is valid - Load the API functions using
REAPERAPI_LoadAPI
. It returns the number of functions which failed to load. - Return
0
to indicate failure - Save the
rec
pointer - Print the message using
ShowConsoleMsg
- Return 1 to indicate successful plugin initialisation.
Using the DLL
- Place the compiled DLL in the
UserPlugins
directory (you can find it in Reaper by clickingOptions->Show REAPER resource path in explorer/finder...
) - Reload Reaper
- Observe the following message.
