PDA

View Full Version : register ("gaccel")


shaman
05-24-2008, 10:10 AM
Hi,

I think i managed to register a command with "gaccel". the Commands description is selectable as Keyboard shortcut action in Reaper, but i somehow do not know how to receive it. I assumed that i would get a message=WM_COMMAND and wParam=myCommandID in the translateAccel funtion registered with "accelerator", but it seems i never get this.
The translateAccel function is actually registered correctly as i can show a messagebox (on every keydown event).
is this approach wrong? i also tried "accel_section" which seems to not work either for receiving the command...

Xenakios
05-24-2008, 11:00 AM
You need something like this first in the plugin entry point function :


acreg13.accel.cmd=g_registered_cmd_SelectFirstTake OfSelectedItems =rec->Register("command_id","XENAKIOS_SELECTFIRSTTAKEOFITEMS");
if (!g_registered_cmd_SelectFirstTakeOfSelectedItems ) {MessageBox(g_parent,"could not register cmd XENAKIOS_SELECTFIRSTTAKEOFITEMS!","BAD happened :(",MB_OK);return 0;}
rec->Register("gaccel",&acreg13);

rec->Register("hookcommand",hookCommandProc);



The hookcommand-thing is needed only once, it registers the function that actually handles the commands that looks something like :


bool hookCommandProc(int command, int flag)
{
if (g_registered_cmd_SelectFirstTakeOfSelectedItems && command == g_registered_cmd_SelectFirstTakeOfSelectedItems)
{
DoSelectTakeInSelectedItems(-1);
Undo_OnStateChange("Select First Takes",4,-1);
UpdateTimeline();
return true;
}
return false;
}


Global variable g_registered_cmd_SelectFirstTakeOfSelectedItems is of type int and global acreg13 is defined as :


gaccel_register_t acreg13=
{
{0,0,0},
"Xenakios Extensions : Select First Take Of Selected Items"
};


All this won't yet make anything appear in the menus, only in the actions lists of Reaper. I am bit uncertain right now how to add the code to add menu entries. (I recently switched to another way to register the commands and add menu entries that was provided by SWS. It maybe a bit more complex for you to try first, but it saves a lot of time and trouble when there's a lot of commands and menu entries to manage.) I'll post something about that later but you should first try/investigate the stuff above to register a keyboard shortcut/action list-only command... ;) Oh, and about translateaccel, you probably won't need it for this. (It's for your own floating dialog windows to handle keyboard passthrough to Reaper.)

shaman
05-24-2008, 11:39 PM
Thanks Xenakios! The following works nicely:


gaccel_register_t MyAccel;

bool hookCommandProc(int command, int flag)
{
if (command == MyAccel.accel.cmd)
{
MessageBox(g_hwnd,"a","a",MB_OK);
return true;
}
return false;
}


.......


MyAccel.desc="Test1";
MyAccel.accel.cmd=rec->Register("command_id","Test1");
if (!MyAccel.accel.cmd) {
MessageBox(g_hwnd,"could not register cmd!","BAD happened :(",MB_OK);
return 0;
} else {
/*
char sText[101];
ZeroMemory(sText,101);
sprintf(sText,"command ID %d accquired",MyAccel.accel.cmd);
MessageBox (g_hwnd,sText,"OK",MB_OK);
*/
}

if (!rec->Register("gaccel",&MyAccel)) {
MessageBox(g_hwnd,"could not register Accel!","BAD happened :(",MB_OK);
return 0;
}

if (!rec->Register("hookcommand",hookCommandProc)) {
MessageBox(g_hwnd,"could not register hookProc!","BAD happened :(",MB_OK);
return 0;
}


The fact that reaper assigns the command ID instead of me choosing one does also make more sense. But how did you know about Register("command_id") and Register("hookcommand")?? they are not mentioned in reaper_plugin.h

Xenakios
05-24-2008, 11:55 PM
The fact that reaper assigns the command ID instead of me choosing one does also make more sense. But how did you know about Register("command_id") and Register("hookcommand")?? they are not mentioned in reaper_plugin.h

The ever famous "Insert Random Ninjam Loop From The Internet" example project (and it's plugin entrypoint function in the main.cpp) in the Reaper extension plugins SDK... ;)