Skip to content

Instantly share code, notes, and snippets.

@Xenakios
Created December 13, 2019 15:16
Show Gist options
  • Save Xenakios/53c1f15a810e958d1151b628a9967003 to your computer and use it in GitHub Desktop.
Save Xenakios/53c1f15a810e958d1151b628a9967003 to your computer and use it in GitHub Desktop.
int g_my_action_id1 = 0;
// the callback should handle all the actions handled by this single plugin
// so, don't add new callback functions separately for each action!
bool hookCommandProc(int command, int flag)
{
if (command != 0 && command == g_my_action_id1)
{
ShowConsoleMsg("Extension test action executed.\n");
return true; // action was found and handled
}
return false; // action not handled by this plugin
}
extern "C"
{
REAPER_PLUGIN_DLL_EXPORT int REAPER_PLUGIN_ENTRYPOINT(REAPER_PLUGIN_HINSTANCE hInstance, reaper_plugin_info_t *rec)
{
if (rec != nullptr)
{
// Load the ShowConsoleMsg API function to be able to do something marginally interesting in the action implementation code
// Every API function must be separately loaded!
// In C or C++, the ShowConsoleMsg declaration and function pointer are already available
// I guess In Rust, you have to separately add the function pointers for the API functions as global variables
((*(void **)&(ShowConsoleMsg)) = (void *)rec->GetFunc("ShowConsoleMsg"));
// register new command ID
g_my_action_id1 = rec->Register("command_id", (void*)"FOOTEST_ACTION_ID1");
// but not enough, must also register accel for keyboard shortcut and command description for action
// list window
// gaccel_register_t is declared in reaper_plugin.h
// the ACCEL accel field is a Windows type
gaccel_register_t accel_reg;
accel_reg.accel = { 0,0,0 }; // means, no shortcut key assigned by default
accel_reg.desc = "Xenakios : Extension action example";
accel_reg.accel.cmd = g_my_action_id1;
rec->Register("gaccel", (void*)&accel_reg);
rec->Register("hookcommand", (void*)hookCommandProc);
return 1; // plugin succesfully loaded, return 0 here if could not initialize properly
}
else
{
// plugin is being unloaded when Reaper quits
ShowConsoleMsg("Unloading extension plugin\n"); // you will never get to see this message, though...
return 0;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment