correctly forward configure events to plugin windows, and cleanup FST code

git-svn-id: svn://localhost/ardour2/trunk@635 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Paul Davis 2006-06-22 21:04:47 +00:00
parent 58c39d50b1
commit 2b5d095464
10 changed files with 248 additions and 247 deletions

View file

@ -103,12 +103,6 @@ handler (int sig)
shutdown (1); shutdown (1);
} }
static void
handler2 (int sig, siginfo_t* ctxt, void* ignored)
{
handler (sig);
}
static void * static void *
signal_thread (void *arg) signal_thread (void *arg)
{ {
@ -452,7 +446,7 @@ int main (int argc, char *argv[])
try { try {
engine = new ARDOUR::AudioEngine (jack_client_name); engine = new ARDOUR::AudioEngine (jack_client_name);
ARDOUR::init (*engine, use_vst, try_hw_optimization, handler2); ARDOUR::init (*engine, use_vst, try_hw_optimization);
ui->set_engine (*engine); ui->set_engine (*engine);
} catch (AudioEngine::NoBackendAvailable& err) { } catch (AudioEngine::NoBackendAvailable& err) {
gui_jack_error (); gui_jack_error ();

View file

@ -228,7 +228,7 @@ class VSTPluginUI : public PlugUIBase, public Gtk::VBox
Gtk::HBox preset_box; Gtk::HBox preset_box;
Gtk::VBox vpacker; Gtk::VBox vpacker;
gboolean configure_handler (GdkEventConfigure*, Gtk::Socket*); bool configure_handler (GdkEventConfigure*, Gtk::Socket*);
void save_plugin_setting (); void save_plugin_setting ();
}; };
#endif #endif

View file

@ -19,7 +19,7 @@
*/ */
#include <fst.h> #include <fst.h>
#include <gtk/gtksocket.h>
#include <ardour/insert.h> #include <ardour/insert.h>
#include <ardour/vst_plugin.h> #include <ardour/vst_plugin.h>
@ -61,16 +61,12 @@ VSTPluginUI::get_preferred_height ()
int int
VSTPluginUI::package (Gtk::Window& win) VSTPluginUI::package (Gtk::Window& win)
{ {
/* for GTK+2, remove this: you cannot add to a realized socket */
//socket.realize ();
/* forward configure events to plugin window */ /* forward configure events to plugin window */
win.signal_configure_event().connect (bind (mem_fun (*this, &VSTPluginUI::configure_handler), &socket)); win.signal_configure_event().connect (bind (mem_fun (*this, &VSTPluginUI::configure_handler), &socket), false);
/* XXX in GTK2, use add_id() instead of steal, although add_id() /*
assumes that the window's owner understands the XEmbed protocol. this assumes that the window's owner understands the XEmbed protocol.
*/ */
socket.add_id (fst_get_XID (vst.fst())); socket.add_id (fst_get_XID (vst.fst()));
@ -78,45 +74,42 @@ VSTPluginUI::package (Gtk::Window& win)
return 0; return 0;
} }
gboolean bool
VSTPluginUI::configure_handler (GdkEventConfigure* ev, Gtk::Socket *socket) VSTPluginUI::configure_handler (GdkEventConfigure* ev, Gtk::Socket *socket)
{ {
XEvent event; XEvent event;
gint x, y; gint x, y;
GdkWindow* w;
if (socket->gobj() == NULL) { if (socket == 0 || ((w = socket->gobj()->plug_window) == 0)) {
return FALSE; return false;
} }
event.xconfigure.type = ConfigureNotify; event.xconfigure.type = ConfigureNotify;
event.xconfigure.event = GDK_WINDOW_XWINDOW (socket->get_window()->gobj()); event.xconfigure.event = GDK_WINDOW_XWINDOW (w);
event.xconfigure.window = GDK_WINDOW_XWINDOW (socket->get_window()->gobj()); event.xconfigure.window = GDK_WINDOW_XWINDOW (w);
/* The ICCCM says that synthetic events should have root relative /* The ICCCM says that synthetic events should have root relative
* coordinates. We still aren't really ICCCM compliant, since * coordinates. We still aren't really ICCCM compliant, since
* we don't send events when the real toplevel is moved. * we don't send events when the real toplevel is moved.
*/ */
gdk_error_trap_push (); gdk_error_trap_push ();
gdk_window_get_origin (socket->get_window()->gobj(), &x, &y); gdk_window_get_origin (w, &x, &y);
gdk_error_trap_pop (); gdk_error_trap_pop ();
event.xconfigure.x = x; event.xconfigure.x = x;
event.xconfigure.y = y; event.xconfigure.y = y;
event.xconfigure.width = GTK_WIDGET(socket)->allocation.width; event.xconfigure.width = GTK_WIDGET(socket->gobj())->allocation.width;
event.xconfigure.height = GTK_WIDGET(socket)->allocation.height; event.xconfigure.height = GTK_WIDGET(socket->gobj())->allocation.height;
event.xconfigure.border_width = 0; event.xconfigure.border_width = 0;
event.xconfigure.above = None; event.xconfigure.above = None;
event.xconfigure.override_redirect = False; event.xconfigure.override_redirect = False;
gdk_error_trap_push (); gdk_error_trap_push ();
XSendEvent (GDK_WINDOW_XDISPLAY (socket->get_window()->gobj()), XSendEvent (GDK_WINDOW_XDISPLAY (w), GDK_WINDOW_XWINDOW (w), False, StructureNotifyMask, &event);
GDK_WINDOW_XWINDOW (socket->get_window()->gobj()),
False, StructureNotifyMask, &event);
// gdk_display_sync (GDK_WINDOW_XDISPLAY (socket->plug_window));
gdk_error_trap_pop (); gdk_error_trap_pop ();
return FALSE; return false;
} }

View file

@ -45,7 +45,7 @@ namespace ARDOUR {
static const jack_nframes_t max_frames = JACK_MAX_FRAMES; static const jack_nframes_t max_frames = JACK_MAX_FRAMES;
int init (AudioEngine&, bool with_vst, bool try_optimization, void (*sighandler)(int,siginfo_t*,void*) = 0); int init (AudioEngine&, bool with_vst, bool try_optimization);
int cleanup (); int cleanup ();

View file

@ -92,12 +92,6 @@ _thread_init_callback (void *arg)
*/ */
PBD::ThreadCreatedWithRequestSize (pthread_self(), X_("Audioengine"), 4096); PBD::ThreadCreatedWithRequestSize (pthread_self(), X_("Audioengine"), 4096);
#ifdef VST_SUPPORT
if (Config->get_use_vst()) {
fst_adopt_thread ();
}
#endif
} }
int int

View file

@ -189,7 +189,7 @@ setup_midi ()
} }
int int
ARDOUR::init (AudioEngine& engine, bool use_vst, bool try_optimization, void (*sighandler)(int,siginfo_t*,void*)) ARDOUR::init (AudioEngine& engine, bool use_vst, bool try_optimization)
{ {
bool generic_mix_functions = true; bool generic_mix_functions = true;
@ -214,7 +214,7 @@ ARDOUR::init (AudioEngine& engine, bool use_vst, bool try_optimization, void (*s
#endif #endif
#ifdef VST_SUPPORT #ifdef VST_SUPPORT
if (Config->get_use_vst() && fst_init (sighandler)) { if (Config->get_use_vst() && fst_init ()) {
return -1; return -1;
} }
#endif #endif

View file

@ -3,6 +3,15 @@
#include "fst.h" #include "fst.h"
void
default_fst_error_callback (const char *desc)
{
fprintf(stderr, "%s\n", desc);
}
void (*fst_error_callback)(const char *desc) = &default_fst_error_callback;
void void
fst_error (const char *fmt, ...) fst_error (const char *fmt, ...)
{ {
@ -15,10 +24,4 @@ fst_error (const char *fmt, ...)
va_end (ap); va_end (ap);
} }
void
default_fst_error_callback (const char *desc)
{
fprintf(stderr, "%s\n", desc);
}
void (*fst_error_callback)(const char *desc) = &default_fst_error_callback;

View file

@ -8,18 +8,18 @@
/** /**
* Display FST error message. * Display FST error message.
* *
* Set via fst_set_error_function(), otherwise a FST-provided * @param fmt printf-style formatting specification
* default will print @a msg (plus a newline) to stderr.
*
* @param msg error message text (no newline at end).
*/ */
extern void (*fst_error_callback)(const char *msg); extern void fst_error (const char *fmt, ...);
/** /**
* Set the @ref fst_error_callback for error message display. * Set the @ref fst_error_callback for error message display.
* *
* The FST library provides two built-in callbacks for this purpose: * The FST library provides two built-in callbacks for this purpose:
* default_fst_error_callback() and silent_fst_error_callback(). * default_fst_error_callback().
*
* The default will print the message (plus a newline) to stderr.
*
*/ */
void fst_set_error_function (void (*func)(const char *)); void fst_set_error_function (void (*func)(const char *));
@ -81,7 +81,7 @@ struct _FST
extern "C" { extern "C" {
#endif #endif
extern int fst_init (void (*sighandler)(int,siginfo_t*,void*)); extern int fst_init ();
extern FSTHandle* fst_load (const char*); extern FSTHandle* fst_load (const char*);
extern int fst_unload (FSTHandle*); extern int fst_unload (FSTHandle*);
@ -96,9 +96,6 @@ extern int fst_run_editor (FST*);
extern void fst_destroy_editor (FST*); extern void fst_destroy_editor (FST*);
extern int fst_get_XID (FST*); extern int fst_get_XID (FST*);
extern int fst_adopt_thread ();
extern void* fst_get_teb();
extern void fst_signal_handler (int sig, siginfo_t* info, void* context); extern void fst_signal_handler (int sig, siginfo_t* info, void* context);
extern FSTInfo *fst_get_info( char *dllpathname ); extern FSTInfo *fst_get_info( char *dllpathname );

View file

@ -9,7 +9,7 @@
#include <stddef.h> #include <stddef.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdlib.h>
#define MAX_STRING_LEN 256 #define MAX_STRING_LEN 256

View file

@ -21,81 +21,162 @@ struct ERect{
short right; short right;
}; };
static pthread_mutex_t plugin_mutex; static pthread_mutex_t plugin_mutex = PTHREAD_MUTEX_INITIALIZER;
static FST* fst_first = NULL; static FST* fst_first = NULL;
DWORD gui_thread_id = 0; DWORD gui_thread_id = 0;
static char* message_name (int message)
{
switch (message) {
case 0x0000:
return "WM_NULL";
case 0x0001:
return "WM_CREATE";
case 0x0002:
return "WM_DESTROY";
case 0x0003:
return "WM_MOVE";
case 0x0004:
return "WM_SIZEWAIT";
case 0x0005:
return "WM_SIZE";
/* Define to a macro to generate an assembly function directive */ case 0x0006:
#define __ASM_FUNC(name) ".type " __ASM_NAME(name) ",@function" return "WM_ACTIVATE";
/* Define to a macro to generate an assembly name from a C symbol */ case 0x0007:
#define __ASM_NAME(name) name return "WM_SETFOCUS";
# define __ASM_GLOBAL_FUNC(name,code) \ case 0x0008:
__asm__( ".align 4\n\t" \ return "WM_KILLFOCUS";
".globl " __ASM_NAME(#name) "\n\t" \
__ASM_FUNC(#name) "\n" \
__ASM_NAME(#name) ":\n\t" \
code );
__ASM_GLOBAL_FUNC( fst_get_teb, ".byte 0x64\n\tmovl 0x18,%eax\n\tret" ); case 0x0009:
return "WM_SETVISIBLE";
case 0x000a:
return "WM_ENABLE";
case 0x000b:
return "WM_SETREDRAW";
#define DELAYED_WINDOW case 0x000c:
return "WM_SETTEXT";
case 0x000d:
return "WM_GETTEXT";
case 0x000e:
return "WM_GETTEXTLENGTH";
case 0x000f:
return "WM_PAINT";
case 0x0010:
return "WM_CLOSE";
case 0x0011:
return "WM_QUERYENDSESSION";
case 0x0012:
return "WM_QUIT";
case 0x0013:
return "WM_QUERYOPEN";
case 0x0014:
return "WM_ERASEBKGND";
case 0x0015:
return "WM_SYSCOLORCHANGE";
case 0x0016:
return "WM_ENDSESSION";
case 0x0017:
return "WM_SYSTEMERROR";
case 0x0018:
return "WM_SHOWWINDOW";
case 0x0019:
return "WM_CTLCOLOR";
case 0x001a:
return "WM_WININICHANGE";
case 0x001b:
return "WM_DEVMODECHANGE";
case 0x001c:
return "WM_ACTIVATEAPP";
case 0x001d:
return "WM_FONTCHANGE";
case 0x001e:
return "WM_TIMECHANGE";
case 0x001f:
return "WM_CANCELMODE";
case 0x0020:
return "WM_SETCURSOR";
case 0x0021:
return "WM_MOUSEACTIVATE";
case 0x0022:
return "WM_CHILDACTIVATE";
case 0x0023:
return "WM_QUEUESYNC";
case 0x0024:
return "WM_GETMINMAXINFO";
default:
break;
}
return "--- OTHER ---";
}
static LRESULT WINAPI static LRESULT WINAPI
my_window_proc (HWND w, UINT msg, WPARAM wp, LPARAM lp) my_window_proc (HWND w, UINT msg, WPARAM wp, LPARAM lp)
{ {
FST* fst; FST* fst;
LRESULT result;
// if (msg != WM_TIMER) { // if (msg != WM_TIMER) {
// fst_error ("window callback handler, msg = 0x%x win=%p\n", msg, w); // fst_error ("window callback handler, msg = 0x%x (%s) win=%p\n", msg, message_name (msg), w);
// } // }
switch (msg) { switch (msg) {
case WM_KEYUP: case WM_KEYUP:
case WM_KEYDOWN: case WM_KEYDOWN:
printf( "got a key\n" );
break; break;
case WM_CLOSE: case WM_CLOSE:
printf("wtf.\n" );
PostQuitMessage (0); PostQuitMessage (0);
case WM_DESTROY: case WM_DESTROY:
case WM_NCDESTROY: case WM_NCDESTROY:
/* we should never get these */ /* we should never get these */
//return 0; //return 0;
break; break;
case WM_PAINT: case WM_PAINT:
// case WM_ACTIVATE:
#ifdef DELAYED_WINDOW
//if (wp & WA_ACTIVE) {
if ((fst = GetPropA (w, "fst_ptr")) != NULL) { if ((fst = GetPropA (w, "fst_ptr")) != NULL) {
if (fst->window && !fst->been_activated) { if (fst->window && !fst->been_activated) {
fst->been_activated = TRUE; fst->been_activated = TRUE;
// {
// XSetWindowAttributes attr;
//
// attr.override_redirect = TRUE;
//// XChangeWindowAttributes( thread_display(), fst->xid, CWOverrideRedirect, &attr );
// }
pthread_cond_signal (&fst->window_status_change); pthread_cond_signal (&fst->window_status_change);
pthread_mutex_unlock (&fst->lock); pthread_mutex_unlock (&fst->lock);
} }
} }
// }
#endif
break; break;
default: default:
@ -123,31 +204,102 @@ fst_handle_new ()
return fst; return fst;
} }
#ifdef HAVE_TLS
static __thread int ejmpbuf_valid = FALSE;
static __thread jmp_buf ejmpbuf;
#else
static pthread_key_t ejmpbuf_valid_key;
static pthread_key_t ejmpbuf_key;
#endif
void debreak( void ) { printf( "debreak\n" ); }
int int
fst_init (void (*sighandler)(int,siginfo_t*,void*)) fst_create_editor (FST* fst)
{ {
//SharedWineInit (sighandler); HMODULE hInst;
wine_shared_premain(); HWND window;
/* "guard point" to trap errors that occur during plugin loading */
/* Note: fst->lock is held while this function is called */
if (!(fst->plugin->flags & effFlagsHasEditor)) {
fst_error ("Plugin \"%s\" has no editor", fst->handle->name);
return -1;
}
if ((hInst = GetModuleHandleA (NULL)) == NULL) {
fst_error ("can't get module handle");
return 1;
}
// if ((window = CreateWindowExA (WS_EX_TOOLWINDOW | WS_EX_TRAYWINDOW, "FST", fst->handle->name,
if ((window = CreateWindowExA (0, "FST", fst->handle->name,
(WS_OVERLAPPEDWINDOW & ~WS_THICKFRAME & ~WS_MAXIMIZEBOX),
0, 0, 1, 1,
NULL, NULL,
hInst,
NULL)) == NULL) {
fst_error ("cannot create editor window");
return 1;
}
if (!SetPropA (window, "fst_ptr", fst)) {
fst_error ("cannot set fst_ptr on window");
}
fst->window = window;
fst->xid = (int) GetPropA (window, "__wine_x11_whole_window");
{
struct ERect* er;
ShowWindow (fst->window, SW_SHOW);
fst->plugin->dispatcher (fst->plugin, effEditOpen, 0, 0, fst->window, 0 );
fst->plugin->dispatcher (fst->plugin, effEditGetRect, 0, 0, &er, 0 );
fst->width = er->right-er->left;
fst->height = er->bottom-er->top;
SetWindowPos (fst->window, 0, 0, 0, er->right-er->left+8, er->bottom-er->top+26, SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOZORDER);
}
return 0; return 0;
} }
void
fst_destroy_editor (FST* fst)
{
pthread_mutex_lock (&fst->lock);
if (fst->window) {
fst->destroy = TRUE;
if (!PostThreadMessageA (gui_thread_id, WM_USER, 0, 0)) {
fst_error ("could not post message to gui thread");
}
pthread_cond_wait (&fst->window_status_change, &fst->lock);
}
pthread_mutex_unlock (&fst->lock);
}
void
fst_event_loop_remove_plugin (FST* fst)
{
FST* p;
FST* prev;
for (p = fst_first, prev = NULL; p->next; prev = p, p = p->next) {
if (p == fst) {
if (prev) {
prev->next = p->next;
}
}
}
if (fst_first == fst) {
fst_first = fst_first->next;
}
}
void debreak( void ) { printf( "debreak\n" ); }
DWORD WINAPI gui_event_loop (LPVOID param) DWORD WINAPI gui_event_loop (LPVOID param)
{ {
MSG msg; MSG msg;
FST* fst; FST* fst;
char c;
HMODULE hInst; HMODULE hInst;
HWND window; HWND window;
@ -175,6 +327,7 @@ DWORD WINAPI gui_event_loop (LPVOID param)
} }
while (GetMessageA (&msg, NULL, 0,0)) { while (GetMessageA (&msg, NULL, 0,0)) {
if( msg.message == WM_KEYDOWN ) debreak(); if( msg.message == WM_KEYDOWN ) debreak();
TranslateMessage( &msg ); TranslateMessage( &msg );
DispatchMessageA (&msg); DispatchMessageA (&msg);
@ -221,21 +374,12 @@ again:
pthread_mutex_unlock (&plugin_mutex); pthread_mutex_unlock (&plugin_mutex);
} }
} }
printf( "quit........\n" ); fst_error ("FST GUI event loop has quit!");
exit(0); return 0;
gtk_main_quit();
}
void
fst_set_focus (FST* fst)
{
if (fst->window) {
SetFocus (fst->window);
}
} }
int int
wine_shared_premain () fst_init ()
{ {
WNDCLASSA wc; WNDCLASSA wc;
HMODULE hInst; HMODULE hInst;
@ -270,6 +414,8 @@ wine_shared_premain ()
int int
fst_run_editor (FST* fst) fst_run_editor (FST* fst)
{ {
/* Add the FST to the list of all that should be handled by the GUI thread */
pthread_mutex_lock (&plugin_mutex); pthread_mutex_lock (&plugin_mutex);
if (fst_first == NULL) { if (fst_first == NULL) {
@ -282,7 +428,6 @@ fst_run_editor (FST* fst)
p->next = fst; p->next = fst;
} }
printf( "gui_thread_id = %d\n", gui_thread_id );
if (!PostThreadMessageA (gui_thread_id, WM_USER, 0, 0)) { if (!PostThreadMessageA (gui_thread_id, WM_USER, 0, 0)) {
fst_error ("could not post message to gui thread"); fst_error ("could not post message to gui thread");
return -1; return -1;
@ -306,129 +451,10 @@ fst_run_editor (FST* fst)
return 0; return 0;
} }
int
fst_create_editor (FST* fst)
{
HMODULE hInst;
char class[20];
HWND window;
/* "guard point" to trap errors that occur during plugin loading */
/* Note: fst->lock is held while this function is called */
if (!(fst->plugin->flags & effFlagsHasEditor)) {
fst_error ("Plugin \"%s\" has no editor", fst->handle->name);
return -1;
}
if ((hInst = GetModuleHandleA (NULL)) == NULL) {
fst_error ("can't get module handle");
return 1;
}
// if ((window = CreateWindowExA (WS_EX_TOOLWINDOW | WS_EX_TRAYWINDOW, "FST", fst->handle->name,
if ((window = CreateWindowExA (0, "FST", fst->handle->name,
(WS_OVERLAPPEDWINDOW & ~WS_THICKFRAME & ~WS_MAXIMIZEBOX),
0, 0, 1, 1,
NULL, NULL,
hInst,
NULL)) == NULL) {
fst_error ("cannot create editor window");
return 1;
}
if (!SetPropA (window, "fst_ptr", fst)) {
fst_error ("cannot set fst_ptr on window");
}
fst->window = window;
fst->xid = (int) GetPropA (window, "__wine_x11_whole_window");
// XChangeWindowAttributes( XOpenDisplay(NULL), fst->xid, CWOverrideRedirect, ~0 );
#ifdef DELAYED_WINDOW
{
struct ERect* er;
ShowWindow (fst->window, SW_SHOW);
fst->plugin->dispatcher (fst->plugin, effEditOpen, 0, 0, fst->window, 0 );
fst->plugin->dispatcher (fst->plugin, effEditGetRect, 0, 0, &er, 0 );
fst->width = er->right-er->left;
fst->height = er->bottom-er->top;
SetWindowPos (fst->window, 0, 0, 0, er->right-er->left+8, er->bottom-er->top+26, SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOZORDER);
}
#else
pthread_cond_signal (&fst->window_status_change);
pthread_mutex_unlock (&fst->lock);
#endif
return 0;
}
void
fst_show_editor (FST* fst)
{
#ifndef DELAYED_WINDOW
struct ERect* er;
fst->plugin->dispatcher (fst->plugin, effEditOpen, 0, 0, fst->window, 0 );
fst->plugin->dispatcher (fst->plugin, effEditGetRect, 0, 0, &er, 0 );
fst->width = er->right-er->left;
fst->height = er->bottom-er->top;
SetWindowPos (window, 0, 0, 0, er->right-er->left+8, er->bottom-er->top+26, SWP_NOMOVE | SWP_NOZORDER);
*ejmpbuf_valid = FALSE;
#endif
}
void
fst_destroy_editor (FST* fst)
{
FST* p;
FST* prev;
pthread_mutex_lock (&fst->lock);
if (fst->window) {
fst->destroy = TRUE;
if (!PostThreadMessageA (gui_thread_id, WM_USER, 0, 0)) {
fst_error ("could not post message to gui thread");
}
pthread_cond_wait (&fst->window_status_change, &fst->lock);
}
pthread_mutex_unlock (&fst->lock);
}
void
fst_event_loop_remove_plugin (FST* fst)
{
FST* p;
FST* prev;
for (p = fst_first, prev = NULL; p->next; prev = p, p = p->next) {
if (p == fst) {
if (prev) {
prev->next = p->next;
}
}
}
if (fst_first == fst) {
fst_first = fst_first->next;
}
}
FSTHandle* FSTHandle*
fst_load (const char *path) fst_load (const char *path)
{ {
char* buf, *buf2; char* buf;
FSTHandle* fhandle; FSTHandle* fhandle;
char* period; char* period;
@ -555,9 +581,3 @@ fst_get_XID (FST* fst)
{ {
return fst->xid; return fst->xid;
} }
int
fst_adopt_thread ()
{
return 0;
}