Old 05-24-2008, 10:10 AM   #1
shaman
Human being with feelings
 
Join Date: Mar 2008
Posts: 56
Default register ("gaccel")

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...
shaman is offline   Reply With Quote
Old 05-24-2008, 11:00 AM   #2
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
Default

You need something like this first in the plugin entry point function :

Code:
acreg13.accel.cmd=g_registered_cmd_SelectFirstTakeOfSelectedItems =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 :

Code:
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 :

Code:
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.)
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.

Last edited by Xenakios; 05-24-2008 at 11:11 AM.
Xenakios is offline   Reply With Quote
Old 05-24-2008, 11:39 PM   #3
shaman
Human being with feelings
 
Join Date: Mar 2008
Posts: 56
Default

Thanks Xenakios! The following works nicely:

Code:
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
shaman is offline   Reply With Quote
Old 05-24-2008, 11:55 PM   #4
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
Default

Quote:
Originally Posted by shaman View Post

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...
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.
Xenakios is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 04:06 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.