Skip to content

Instantly share code, notes, and snippets.

@cfillion
Last active May 2, 2023 21:35
Show Gist options
  • Save cfillion/ade31c6cacbd18bd4accbad36aa88e96 to your computer and use it in GitHub Desktop.
Save cfillion/ade31c6cacbd18bd4accbad36aa88e96 to your computer and use it in GitHub Desktop.
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(); }
void NSEEL_HOSTSTUB_LeaveMutex() { eel_leave_mutex(); }
class eel_gmem_space {
public:
eel_gmem_space(const char *name) : m_space{eel_gmem_attach(name, true)} {}
EEL_F read(const int index) const
{
EEL_F *slot = __NSEEL_RAMAllocGMEM(m_space, index);
return slot ? *slot : 0;
}
void write(const int index, const EEL_F value)
{
if(EEL_F *slot = __NSEEL_RAMAllocGMEM(m_space, index))
*slot = value;
}
private:
EEL_F ***m_space;
};
extern "C" REAPER_PLUGIN_DLL_EXPORT int REAPER_PLUGIN_ENTRYPOINT(
REAPER_PLUGIN_HINSTANCE instance, reaper_plugin_info_t *rec)
{
if(!rec || rec->caller_version != REAPER_PLUGIN_VERSION)
return 0;
eel_gmem_attach = (decltype(eel_gmem_attach))rec->GetFunc("eel_gmem_attach");
eel_enter_mutex = (decltype(eel_enter_mutex))rec->GetFunc("NSEEL_HOSTSTUB_EnterMutex");
eel_leave_mutex = (decltype(eel_leave_mutex))rec->GetFunc("NSEEL_HOSTSTUB_LeaveMutex");
eel_gmem_space foobar("foobar");
foobar.write(42, 4.2);
return 1;
}
@cfillion
Copy link
Author

cfillion commented May 2, 2023

No, because it requires shipping an implementation of EEL's RAMAllocGMEM assuming it perfectly matches the one compiled inside of REAPER, which is inherently unsafe.

@ryanorendorff
Copy link

Ah good point. I currently write global memory to sliders and read it off there. Not an amazing solution but seems to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment