X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Ffst%2Fvstwin.c;h=ba3187684b2da2dbafd2cc2ce138899d54ec39ae;hb=d50df82799665e4bbf7c9d8cf2a7c2af866f0da2;hp=37ea86dc19796cd02450bab765496bfdaa3864e2;hpb=40aa7e5e9034321f8af0b3067bd5f3005c537d5d;p=ardour.git diff --git a/libs/fst/vstwin.c b/libs/fst/vstwin.c index 37ea86dc19..ba3187684b 100644 --- a/libs/fst/vstwin.c +++ b/libs/fst/vstwin.c @@ -2,24 +2,28 @@ #include #include +#define fst_error(...) fprintf(stderr, __VA_ARGS__) + #ifdef PLATFORM_WINDOWS -#include -#include +#include static UINT_PTR idle_timer_id = 0; #else /* linux + wine */ #include // PATH_MAX -#include // basename #include #include #include static int gui_quit = 0; +static unsigned int idle_id = 0; #endif +#ifndef COMPILER_MSVC extern char * strdup (const char *); +#endif + #include #include "fst.h" @@ -115,9 +119,9 @@ idle_hands( } } + pthread_mutex_lock (&fst->lock); #ifndef PLATFORM_WINDOWS /* linux + wine */ /* Dispatch messages to send keypresses to the plugin */ - pthread_mutex_lock (&fst->lock); int i; for (i = 0; i < fst->n_pending_keys; ++i) { @@ -140,6 +144,7 @@ idle_hands( } fst->n_pending_keys = 0; +#endif /* See comment for maybe_set_program call below */ maybe_set_program (fst); @@ -157,7 +162,6 @@ idle_hands( maybe_set_program (fst); fst->program_set_without_editor = 1; } -#endif pthread_mutex_unlock (&fst->lock); } @@ -222,9 +226,11 @@ fst_new (void) fst->n_pending_keys = 0; fst->has_editor = 0; #ifdef PLATFORM_WINDOWS - fst->voffset = 36; + fst->voffset = 50; + fst->hoffset = 0; #else /* linux + wine */ fst->voffset = 24; + fst->hoffset = 6; #endif fst->program_set_without_editor = 0; return fst; @@ -249,12 +255,14 @@ fst_handle_new (void) #ifndef PLATFORM_WINDOWS /* linux + wine */ static gboolean g_idle_call (gpointer ignored) { + if (gui_quit) return FALSE; MSG msg; if (PeekMessageA (&msg, NULL, 0, 0, 1)) { TranslateMessage (&msg); DispatchMessageA (&msg); } idle_hands(NULL, 0, 0, 0); + g_main_context_iteration(NULL, FALSE); return gui_quit ? FALSE : TRUE; } #endif @@ -311,12 +319,31 @@ fst_init (void* possible_hmodule) fst_error ("Error in fst_init(): (class registration failed"); return -1; } + return 0; +} + +void +fst_start_threading(void) +{ +#ifndef PLATFORM_WINDOWS /* linux + wine */ + if (idle_id == 0) { + gui_quit = 0; + idle_id = g_idle_add (g_idle_call, NULL); + } +#endif +} + +void +fst_stop_threading(void) { #ifndef PLATFORM_WINDOWS /* linux + wine */ - gui_quit = 0; - g_idle_add (g_idle_call, NULL); // XXX too early ? - //g_timeout_add(40, g_idle_call, NULL); + if (idle_id != 0) { + gui_quit = 1; + PostQuitMessage (0); + g_main_context_iteration(NULL, FALSE); + //g_source_remove(idle_id); + idle_id = 0; + } #endif - return 0; } void @@ -333,8 +360,10 @@ fst_exit (void) KillTimer(NULL, idle_timer_id); } #else /* linux + wine */ - gui_quit = 1; - PostQuitMessage (0); + if (idle_id) { + gui_quit = 1; + PostQuitMessage (0); + } #endif host_initialized = FALSE; @@ -345,10 +374,13 @@ fst_exit (void) int fst_run_editor (VSTState* fst, void* window_parent) { + /* For safety, remove any pre-existing editor window */ + fst_destroy_editor (fst); + if (fst->windows_window == NULL) { HMODULE hInst; HWND window; - struct ERect* er; + struct ERect* er = NULL; if (!(fst->plugin->flags & effFlagsHasEditor)) { fst_error ("Plugin \"%s\" has no editor", fst->handle->name); @@ -395,9 +427,10 @@ fst_run_editor (VSTState* fst, void* window_parent) fst->plugin->dispatcher (fst->plugin, effEditOpen, 0, 0, fst->windows_window, 0 ); fst->plugin->dispatcher (fst->plugin, effEditGetRect, 0, 0, &er, 0 ); - fst->width = er->right-er->left; - fst->height = er->bottom-er->top; - + if (er != NULL) { + fst->width = er->right - er->left; + fst->height = er->bottom - er->top; + } fst->been_activated = TRUE; @@ -439,9 +472,9 @@ fst_move_window_into_view (VSTState* fst) { if (fst->windows_window) { #ifdef PLATFORM_WINDOWS - SetWindowPos ((HWND)(fst->windows_window), 0, 0, fst->voffset, fst->width, fst->height, 0); + SetWindowPos ((HWND)(fst->windows_window), 0, fst->hoffset, fst->voffset, fst->width + fst->hoffset, fst->height + fst->voffset, 0); #else /* linux + wine */ - SetWindowPos ((HWND)(fst->windows_window), 0, 0, 0, fst->width, fst->height, 0); + SetWindowPos ((HWND)(fst->windows_window), 0, 0, 0, fst->width + fst->hoffset, fst->height + fst->voffset, 0); #endif ShowWindow ((HWND)(fst->windows_window), SW_SHOWNA); } @@ -463,9 +496,8 @@ fst_load (const char *path) if ((strlen(path)) && (NULL != (fhandle = fst_handle_new ()))) { char* period; - fhandle->nameptr = strdup (path); fhandle->path = strdup (path); - fhandle->name = basename(fhandle->nameptr); + fhandle->name = g_path_get_basename(path); if ((period = strrchr (fhandle->name, '.'))) { *period = '\0'; } @@ -476,10 +508,10 @@ fst_load (const char *path) return NULL; } - fhandle->main_entry = (main_entry_t) GetProcAddress (fhandle->dll, "main"); + fhandle->main_entry = (main_entry_t) GetProcAddress ((HMODULE)fhandle->dll, "main"); if (fhandle->main_entry == 0) { - if ((fhandle->main_entry = (main_entry_t) GetProcAddress (fhandle->dll, "VSTPluginMain"))) { + if ((fhandle->main_entry = (main_entry_t) GetProcAddress ((HMODULE)fhandle->dll, "VSTPluginMain"))) { fprintf(stderr, "VST >= 2.4 plugin '%s'\n", path); //PBD::warning << path << _(": is a VST >= 2.4 - this plugin may or may not function correctly with this version of Ardour.") << endmsg; } @@ -514,9 +546,8 @@ fst_unload (VSTHandle** fhandle) (*fhandle)->path = NULL; } - if ((*fhandle)->nameptr) { - free ((*fhandle)->nameptr); - (*fhandle)->nameptr = NULL; + if ((*fhandle)->name) { + free ((*fhandle)->name); (*fhandle)->name = NULL; } @@ -562,6 +593,10 @@ fst_instantiate (VSTHandle* fhandle, audioMasterCallback amc, void* userptr) return fst; } +void fst_audio_master_idle(void) { + while(g_main_context_iteration(NULL, FALSE)) ; +} + void fst_close (VSTState* fst) { @@ -578,7 +613,7 @@ fst_close (VSTState* fst) if (fst->handle->plugincnt && --fst->handle->plugincnt == 0) { fst->handle->main_entry = NULL; - fst_unload (&fst->handle); + fst_unload (&fst->handle); // XXX } }