Clean up VST plugin key handling slightly.

git-svn-id: svn://localhost/ardour2/branches/3.0@8377 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Carl Hetherington 2010-12-29 23:31:02 +00:00
parent cf2cd98db0
commit 72190954c4
3 changed files with 80 additions and 11 deletions

View File

@ -139,7 +139,45 @@ void
VSTPluginUI::forward_key_event (GdkEventKey* ev)
{
if (ev->type == GDK_KEY_PRESS) {
vst->fst()->pending_key = ev->keyval;
FST* fst = vst->fst ();
pthread_mutex_lock (&fst->lock);
if (fst->n_pending_keys == (sizeof (fst->pending_keys) * sizeof (FSTKey))) {
/* buffer full */
return;
}
int special_windows_key = 0;
int character_windows_key = 0;
switch (ev->keyval) {
case GDK_Left:
special_windows_key = 0x25;
break;
case GDK_Right:
special_windows_key = 0x27;
break;
case GDK_Up:
special_windows_key = 0x26;
break;
case GDK_Down:
special_windows_key = 0x28;
break;
case GDK_Return:
case GDK_KP_Enter:
special_windows_key = 0xd;
break;
default:
character_windows_key = ev->keyval;
break;
}
fst->pending_keys[fst->n_pending_keys].special = special_windows_key;
fst->pending_keys[fst->n_pending_keys].character = character_windows_key;
fst->n_pending_keys++;
pthread_mutex_unlock (&fst->lock);
}
}

View File

@ -34,6 +34,7 @@ void fst_error (const char *fmt, ...);
typedef struct _FST FST;
typedef struct _FSTHandle FSTHandle;
typedef struct _FSTInfo FSTInfo;
typedef struct _FSTKey FSTKey;
struct _FSTInfo
{
@ -70,6 +71,14 @@ struct _FSTHandle
int plugincnt;
};
struct _FSTKey
{
/** virtual-key code, or 0 if this _FSTKey is a `character' key */
int special;
/** `character' key, or 0 if this _FSTKey is a virtual-key */
int character;
};
struct _FST
{
struct AEffect* plugin;
@ -89,7 +98,9 @@ struct _FST
int current_program;
float *want_params;
float *set_params;
int pending_key;
FSTKey pending_keys[16];
int n_pending_keys;
int dispatcher_wantcall;
int dispatcher_opcode;

View File

@ -14,6 +14,8 @@
#include <X11/X.h>
#include <X11/Xlib.h>
extern char * strdup (const char *);
struct ERect{
short top;
short left;
@ -73,7 +75,7 @@ fst_new ()
fst->want_program = -1;
fst->want_chunk = 0;
fst->current_program = -1;
fst->pending_key = 0;
fst->n_pending_keys = 0;
return fst;
}
@ -211,20 +213,39 @@ again:
}
pthread_mutex_lock (&plugin_mutex);
for (fst = fst_first; fst; fst = fst->next) {
if (fst->pending_key) {
msg.message = WM_CHAR;
pthread_mutex_lock (&fst->lock);
/* Dispatch messages to send keypresses to the plugin */
for (int i = 0; i < fst->n_pending_keys; ++i) {
/* I'm not quite sure what is going on here; it seems
`special' keys must be delivered with WM_KEYDOWN,
but that alphanumerics etc. must use WM_CHAR or
they will be ignored. Ours is not to reason why ...
*/
if (fst->pending_keys[i].special != 0) {
msg.message = WM_KEYDOWN;
msg.wParam = fst->pending_keys[i].special;
} else {
msg.message = WM_CHAR;
msg.wParam = fst->pending_keys[i].character;
}
msg.hwnd = GetFocus ();
msg.wParam = fst->pending_key;
msg.lParam = 0;
DispatchMessageA (&msg);
fst->pending_key = 0;
}
fst->n_pending_keys = 0;
pthread_mutex_unlock (&fst->lock);
}
pthread_mutex_unlock (&plugin_mutex);
}
return 0;
@ -752,7 +773,6 @@ int fst_save_state (FST * fst, char * filename)
if (f) {
int bytelen;
int numParams = fst->plugin->numParams;
unsigned i;
char productString[64];
char effectName[64];
char vendorString[64];
@ -789,13 +809,13 @@ int fst_save_state (FST * fst, char * filename)
numParams = 0;
}
for( i=0; i<numParams; i++ ) {
for (int j = 0; j < numParams; ++j) {
float val;
pthread_mutex_lock( &fst->lock );
val = fst->plugin->getParameter( fst->plugin, i );
val = fst->plugin->getParameter (fst->plugin, j);
pthread_mutex_unlock( &fst->lock );
fprintf( f, " <param index=\"%d\" value=\"%f\"/>\n", i, val );
fprintf( f, " <param index=\"%d\" value=\"%f\"/>\n", j, val );
}
if( fst->plugin->flags & 32 ) {