Skip to content

Instantly share code, notes, and snippets.

@cfillion
cfillion / reaper_gmem.cpp
Last active May 2, 2023 21:35
Proof of concept for accessing gmem data from REAPER extensions using eel_gmem_attach
#include "reaper_plugin.h"
#define EEL_F_SIZE WDL_FFT_REALSIZE
#include "WDL/WDL/eel2/nseel-ram.c"
EEL_F *** (*eel_gmem_attach)(const char *nm, bool is_alloc);
void (*eel_enter_mutex)();
void (*eel_leave_mutex)();
void NSEEL_HOSTSTUB_EnterMutex() { eel_enter_mutex(); }
@cfillion
cfillion / main.cpp
Last active April 10, 2023 04:07
Bare-bone REAPER extension (prints Hello World! using the API)
// Bare-bone REAPER extension
//
// 1. Grab reaper_plugin.h from https://github.com/justinfrankel/reaper-sdk/raw/main/sdk/reaper_plugin.h
// 2. Grab reaper_plugin_functions.h by running the REAPER action "[developer] Write C++ API functions header"
// 3. Grab WDL: git clone https://github.com/justinfrankel/WDL.git
// 4. Build then copy or link the binary file into <REAPER resource directory>/UserPlugins
//
// Linux
// =====
//
--dofile(reaper.GetResourcePath() ..
--'/Scripts/ReaTeam Extensions/API/imgui.lua')('0.7')
r = reaper
local demo, cache = {}, {}
function demo.EachEnum(enum)
local enum_cache = cache[enum]
if not enum_cache then
enum_cache = {}
cache[enum] = enum_cache
@cfillion
cfillion / main.cpp
Last active October 12, 2022 02:43
Proof of concept: Add prevent UI refresh to REAPER native custom actions
#include <cstring>
#define REAPERAPI_IMPLEMENT
#include <reaper_plugin_functions.h>
const char *(*__localizeFunc)(const char *str, const char *subctx, int flags);
static bool IsCustomAction(KbdSectionInfo *section, const int id)
{
// logic from SWS's IsMacroOrScript
@cfillion
cfillion / reaper-www-toolbar.html
Last active September 17, 2022 23:51
Simple web interface example for running REAPER actions remotely https://i.imgur.com/ZhC3vF4.gif
<!DOCTYPE html>
<html>
<head>
<title>Toolbar demo by cfillion</title>
<meta charset="utf-8"/>
<style>
@font-face {
font-family: 'Bravura';
src: url('https://cdn.rawgit.com/openlilylib/openlilylib/3d6a145a/custom-music-fonts/smufl/bravura-1.12/woff/Bravura.woff');
}
@cfillion
cfillion / reaper_widemsg.cpp
Created May 6, 2022 14:51
Hack to allow input of any characters in Unicode windows
// cl /nologo /O2 reaper_widemsg.cpp User32.lib /link /DLL /OUT:reaper_widemsg.dll
#include <cstdint>
#define REAPERAPI_IMPLEMENT
#include "reaper_plugin_functions.h"
template<typename T>
bool patch(const uintptr_t addr, const T newCode, T *backup = nullptr)
{
// c++ -fPIC -O2 -std=c++14 -DSWELL_PROVIDED_BY_APP -IWDL -IWDL/WDL -dynamiclib reaper_idenoreload.cpp WDL/WDL/swell/swell-modstub.mm -lc++ -framework AppKit -o reaper_ideautoreload.dylib
//
// cl /nologo /O2 reaper_idenoreload.cpp User32.lib /link /OPT:REF /PDBALTPATH:%_PDB% /DLL /OUT:reaper_ideautoreload.dll
#ifndef _WIN32
# include <sys/mman.h>
# include <WDL/wdltypes.h>
#endif
#include <cstdint>
// equivalent to __builtin_return_address(1);
uintptr_t rbp {};
asm("mov %%rbp, %0" : "=r"(rbp));
rbp = *reinterpret_cast<uintptr_t *>(rbp); // dig one level
intptr_t *ret { reinterpret_cast<uintptr_t *>(rbp + 8) };
*ret = s_current->m_redirect;
// ConfigVar Layout
//
// 1. Grab reaper_plugin.h from https://landoleet.org/dev/reaper_plugin.h
// 2. Grab reaper_plugin_functions.h by running the REAPER action "[developer] Write C++ API functions header"
// 3. Grab WDL: git clone https://github.com/justinfrankel/WDL.git
// 4. Build then copy or link the binary file into <REAPER resource directory>/UserPlugins
//
// Linux
// =====
//
@cfillion
cfillion / load-reaper-api.cpp
Last active July 3, 2020 17:18
Loader for the REAPER C++ API
// Usage:
// if(rec->caller_version != REAPER_PLUGIN_VERSION || !loadAPI(rec->GetFunc))
// return 0;
// See also (bare-bone REAPER extension):
// https://gist.github.com/cfillion/f32b04e75e84e03cc463abb1eda41400
#define REQUIRED_API(name) {(void **)&name, #name, true}
#define OPTIONAL_API(name) {(void **)&name, #name, false}
static bool loadAPI(void *(*getFunc)(const char *))