5 #include <wine/exception.h>
9 //#include <x11/xlib.h>
10 //#include <x11/xresource.h>
11 //#include <x11/xutil.h>
12 //#include <x11/xatom.h>
24 static pthread_mutex_t plugin_mutex = PTHREAD_MUTEX_INITIALIZER;
25 static FST* fst_first = NULL;
27 DWORD gui_thread_id = 0;
29 static char* message_name (int message)
57 return "WM_KILLFOCUS";
60 return "WM_SETVISIBLE";
66 return "WM_SETREDRAW";
75 return "WM_GETTEXTLENGTH";
84 return "WM_QUERYENDSESSION";
90 return "WM_QUERYOPEN";
93 return "WM_ERASEBKGND";
96 return "WM_SYSCOLORCHANGE";
99 return "WM_ENDSESSION";
102 return "WM_SYSTEMERROR";
105 return "WM_SHOWWINDOW";
108 return "WM_CTLCOLOR";
111 return "WM_WININICHANGE";
114 return "WM_DEVMODECHANGE";
117 return "WM_ACTIVATEAPP";
120 return "WM_FONTCHANGE";
123 return "WM_TIMECHANGE";
126 return "WM_CANCELMODE";
129 return "WM_SETCURSOR";
132 return "WM_MOUSEACTIVATE";
135 return "WM_CHILDACTIVATE";
138 return "WM_QUEUESYNC";
141 return "WM_GETMINMAXINFO";
146 return "--- OTHER ---";
149 static LRESULT WINAPI
150 my_window_proc (HWND w, UINT msg, WPARAM wp, LPARAM lp)
154 // if (msg != WM_TIMER) {
155 // fst_error ("window callback handler, msg = 0x%x (%s) win=%p\n", msg, message_name (msg), w);
168 /* we should never get these */
173 if ((fst = GetPropA (w, "fst_ptr")) != NULL) {
174 if (fst->window && !fst->been_activated) {
175 fst->been_activated = TRUE;
176 pthread_cond_signal (&fst->window_status_change);
177 pthread_mutex_unlock (&fst->lock);
186 return DefWindowProcA (w, msg, wp, lp );
192 FST* fst = (FST*) calloc (1, sizeof (FST));
194 pthread_mutex_init (&fst->lock, NULL);
195 pthread_cond_init (&fst->window_status_change, NULL);
203 FSTHandle* fst = (FSTHandle*) calloc (1, sizeof (FSTHandle));
208 fst_create_editor (FST* fst)
213 /* "guard point" to trap errors that occur during plugin loading */
215 /* Note: fst->lock is held while this function is called */
217 if (!(fst->plugin->flags & effFlagsHasEditor)) {
218 fst_error ("Plugin \"%s\" has no editor", fst->handle->name);
222 if ((hInst = GetModuleHandleA (NULL)) == NULL) {
223 fst_error ("can't get module handle");
227 // if ((window = CreateWindowExA (WS_EX_TOOLWINDOW | WS_EX_TRAYWINDOW, "FST", fst->handle->name,
228 if ((window = CreateWindowExA (0, "FST", fst->handle->name,
229 (WS_OVERLAPPEDWINDOW & ~WS_THICKFRAME & ~WS_MAXIMIZEBOX),
234 fst_error ("cannot create editor window");
238 if (!SetPropA (window, "fst_ptr", fst)) {
239 fst_error ("cannot set fst_ptr on window");
242 fst->window = window;
243 fst->xid = (int) GetPropA (window, "__wine_x11_whole_window");
248 ShowWindow (fst->window, SW_SHOW);
250 fst->plugin->dispatcher (fst->plugin, effEditOpen, 0, 0, fst->window, 0 );
251 fst->plugin->dispatcher (fst->plugin, effEditGetRect, 0, 0, &er, 0 );
253 fst->width = er->right-er->left;
254 fst->height = er->bottom-er->top;
256 SetWindowPos (fst->window, 0, 0, 0, er->right-er->left+8, er->bottom-er->top+26, SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOZORDER);
263 fst_destroy_editor (FST* fst)
265 pthread_mutex_lock (&fst->lock);
268 if (!PostThreadMessageA (gui_thread_id, WM_USER, 0, 0)) {
269 fst_error ("could not post message to gui thread");
271 pthread_cond_wait (&fst->window_status_change, &fst->lock);
274 pthread_mutex_unlock (&fst->lock);
278 fst_event_loop_remove_plugin (FST* fst)
283 for (p = fst_first, prev = NULL; p->next; prev = p, p = p->next) {
286 prev->next = p->next;
291 if (fst_first == fst) {
292 fst_first = fst_first->next;
297 void debreak( void ) { printf( "debreak\n" ); }
299 DWORD WINAPI gui_event_loop (LPVOID param)
306 gui_thread_id = GetCurrentThreadId ();
308 /* create a dummy window for timer events */
310 if ((hInst = GetModuleHandleA (NULL)) == NULL) {
311 fst_error ("can't get module handle");
315 if ((window = CreateWindowExA (0, "FST", "dummy",
316 WS_OVERLAPPEDWINDOW & ~WS_THICKFRAME & ~WS_MAXIMIZEBOX,
317 CW_USEDEFAULT, CW_USEDEFAULT,
318 CW_USEDEFAULT, CW_USEDEFAULT,
322 fst_error ("cannot create dummy timer window");
325 if (!SetTimer (window, 1000, 100, NULL)) {
326 fst_error ("cannot set timer on dummy window");
329 while (GetMessageA (&msg, NULL, 0,0)) {
331 if( msg.message == WM_KEYDOWN ) debreak();
332 TranslateMessage( &msg );
333 DispatchMessageA (&msg);
335 /* handle window creation requests, destroy requests,
336 and run idle callbacks
340 if( msg.message == WM_TIMER ) {
341 pthread_mutex_lock (&plugin_mutex);
343 for (fst = fst_first; fst; fst = fst->next) {
347 fst->plugin->dispatcher( fst->plugin, effEditClose, 0, 0, NULL, 0.0 );
348 CloseWindow (fst->window);
350 fst->destroy = FALSE;
352 fst_event_loop_remove_plugin (fst);
353 fst->been_activated = FALSE;
354 pthread_mutex_lock (&fst->lock);
355 pthread_cond_signal (&fst->window_status_change);
356 pthread_mutex_unlock (&fst->lock);
360 if (fst->window == NULL) {
361 pthread_mutex_lock (&fst->lock);
362 if (fst_create_editor (fst)) {
363 fst_error ("cannot create editor for plugin %s", fst->handle->name);
364 fst_event_loop_remove_plugin (fst);
365 pthread_cond_signal (&fst->window_status_change);
366 pthread_mutex_unlock (&fst->lock);
369 /* condition/unlock handled when we receive WM_ACTIVATE */
372 fst->plugin->dispatcher (fst->plugin, effEditIdle, 0, 0, NULL, 0);
374 pthread_mutex_unlock (&plugin_mutex);
377 fst_error ("FST GUI event loop has quit!");
387 if ((hInst = GetModuleHandleA (NULL)) == NULL) {
388 fst_error ("can't get module handle");
392 wc.lpfnWndProc = my_window_proc;
395 wc.hInstance = hInst;
396 wc.hIcon = LoadIconA( hInst, "FST");
397 wc.hCursor = LoadCursorA( NULL, IDI_APPLICATION );
398 wc.hbrBackground = GetStockObject( BLACK_BRUSH );
399 wc.lpszMenuName = "MENU_FST";
400 wc.lpszClassName = "FST";
402 if (!RegisterClassA(&wc)){
406 if (CreateThread (NULL, 0, gui_event_loop, NULL, 0, NULL) == NULL) {
407 fst_error ("could not create new thread proxy");
415 fst_run_editor (FST* fst)
417 /* Add the FST to the list of all that should be handled by the GUI thread */
419 pthread_mutex_lock (&plugin_mutex);
421 if (fst_first == NULL) {
431 if (!PostThreadMessageA (gui_thread_id, WM_USER, 0, 0)) {
432 fst_error ("could not post message to gui thread");
436 pthread_mutex_unlock (&plugin_mutex);
438 /* wait for the plugin editor window to be created (or not) */
440 pthread_mutex_lock (&fst->lock);
442 pthread_cond_wait (&fst->window_status_change, &fst->lock);
444 pthread_mutex_unlock (&fst->lock);
447 fst_error ("no window created for VST plugin editor");
455 fst_load (const char *path)
461 fhandle = fst_handle_new ();
463 // XXX: Would be nice to find the correct call for this.
464 // if the user does not configure Z: to be / we are doomed :(
466 if (strstr (path, ".dll") == NULL) {
468 buf = (char *) malloc (strlen (path) + 7);
470 if( path[0] == '/' ) {
471 sprintf (buf, "Z:%s.dll", path);
473 sprintf (buf, "%s.dll", path);
476 fhandle->nameptr = strdup (path);
480 buf = (char *) malloc (strlen (path) + 3);
482 if( path[0] == '/' ) {
483 sprintf (buf, "Z:%s", path);
485 sprintf (buf, "%s", path);
488 fhandle->nameptr = strdup (path);
491 fhandle->name = basename (fhandle->nameptr);
495 if ((period = strrchr (fhandle->name, '.')) != NULL) {
499 if ((fhandle->dll = LoadLibraryA (buf)) == NULL) {
500 fst_unload (fhandle);
504 if ((fhandle->main_entry = GetProcAddress (fhandle->dll, "main")) == NULL) {
505 fst_unload (fhandle);
513 fst_unload (FSTHandle* fhandle)
515 if (fhandle->plugincnt) {
520 FreeLibrary (fhandle->dll);
524 if (fhandle->nameptr) {
525 free (fhandle->nameptr);
526 fhandle->name = NULL;
534 fst_instantiate (FSTHandle* fhandle, audioMasterCallback amc, void* userptr)
536 FST* fst = fst_new ();
538 if( fhandle == NULL ) {
539 fst_error( "the handle was NULL\n" );
543 if ((fst->plugin = fhandle->main_entry (amc)) == NULL) {
544 fst_error ("%s could not be instantiated\n", fhandle->name);
549 fst->handle = fhandle;
550 fst->plugin->user = userptr;
552 if (fst->plugin->magic != kEffectMagic) {
553 fst_error ("%s is not a VST plugin\n", fhandle->name);
558 fst->plugin->dispatcher (fst->plugin, effOpen, 0, 0, 0, 0);
559 //fst->plugin->dispatcher (fst->plugin, effMainsChanged, 0, 0, NULL, 0);
561 fst->handle->plugincnt++;
569 fst_destroy_editor (fst);
571 fst->plugin->dispatcher (fst->plugin, effMainsChanged, 0, 0, NULL, 0);
572 fst->plugin->dispatcher (fst->plugin, effClose, 0, 0, 0, 0);
574 if (fst->handle->plugincnt) {
575 --fst->handle->plugincnt;
580 fst_get_XID (FST* fst)