From 72190954c49dbe5874115132e0497cf5b8d6e633 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 29 Dec 2010 23:31:02 +0000 Subject: [PATCH] Clean up VST plugin key handling slightly. git-svn-id: svn://localhost/ardour2/branches/3.0@8377 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/vst_pluginui.cc | 40 ++++++++++++++++++++++++++++++++++++- libs/fst/fst.h | 13 +++++++++++- libs/fst/vstwin.c | 38 ++++++++++++++++++++++++++--------- 3 files changed, 80 insertions(+), 11 deletions(-) diff --git a/gtk2_ardour/vst_pluginui.cc b/gtk2_ardour/vst_pluginui.cc index 80973eb0e2..b3942235fd 100644 --- a/gtk2_ardour/vst_pluginui.cc +++ b/gtk2_ardour/vst_pluginui.cc @@ -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); } } diff --git a/libs/fst/fst.h b/libs/fst/fst.h index 25fef9dd36..2e4236fe4d 100644 --- a/libs/fst/fst.h +++ b/libs/fst/fst.h @@ -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; diff --git a/libs/fst/vstwin.c b/libs/fst/vstwin.c index f1553821ad..b9f372d461 100644 --- a/libs/fst/vstwin.c +++ b/libs/fst/vstwin.c @@ -14,6 +14,8 @@ #include #include +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; ilock ); - val = fst->plugin->getParameter( fst->plugin, i ); + val = fst->plugin->getParameter (fst->plugin, j); pthread_mutex_unlock( &fst->lock ); - fprintf( f, " \n", i, val ); + fprintf( f, " \n", j, val ); } if( fst->plugin->flags & 32 ) {