2008-06-02 17:41:35 -04:00
|
|
|
#include <stdio.h>
|
2014-02-21 11:28:47 -05:00
|
|
|
#include <string.h>
|
2008-06-02 17:41:35 -04:00
|
|
|
#include <windows.h>
|
2014-02-21 11:28:47 -05:00
|
|
|
|
2014-04-11 13:36:17 -04:00
|
|
|
#define fst_error(...) fprintf(stderr, __VA_ARGS__)
|
|
|
|
|
2014-02-21 11:28:47 -05:00
|
|
|
#ifdef PLATFORM_WINDOWS
|
|
|
|
|
2014-03-04 09:25:58 -05:00
|
|
|
#include <pthread.h>
|
2014-02-21 11:28:47 -05:00
|
|
|
static UINT_PTR idle_timer_id = 0;
|
|
|
|
|
|
|
|
#else /* linux + wine */
|
|
|
|
|
|
|
|
#include <linux/limits.h> // PATH_MAX
|
2008-06-02 17:41:35 -04:00
|
|
|
#include <winnt.h>
|
|
|
|
#include <wine/exception.h>
|
|
|
|
#include <pthread.h>
|
2014-02-21 11:28:47 -05:00
|
|
|
static int gui_quit = 0;
|
2014-02-21 20:44:34 -05:00
|
|
|
static unsigned int idle_id = 0;
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2014-02-21 11:28:47 -05:00
|
|
|
#endif
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2014-11-04 08:08:00 -05:00
|
|
|
#ifndef COMPILER_MSVC
|
2010-12-29 18:31:02 -05:00
|
|
|
extern char * strdup (const char *);
|
2014-11-04 08:08:00 -05:00
|
|
|
#endif
|
|
|
|
|
2014-02-21 11:28:47 -05:00
|
|
|
#include <glib.h>
|
|
|
|
#include "fst.h"
|
2010-12-29 18:31:02 -05:00
|
|
|
|
2014-02-21 11:28:47 -05:00
|
|
|
struct ERect {
|
|
|
|
short top;
|
|
|
|
short left;
|
|
|
|
short bottom;
|
|
|
|
short right;
|
2008-06-02 17:41:35 -04:00
|
|
|
};
|
|
|
|
|
2014-02-21 11:28:47 -05:00
|
|
|
static pthread_mutex_t plugin_mutex;
|
|
|
|
static VSTState* fst_first = NULL; /**< Head of linked list of all FSTs */
|
|
|
|
static int host_initialized = 0;
|
|
|
|
static const char magic[] = "FST Plugin State v002";
|
2010-12-29 19:53:37 -05:00
|
|
|
|
|
|
|
|
2014-02-21 11:28:47 -05:00
|
|
|
static LRESULT WINAPI
|
|
|
|
vstedit_wndproc (HWND w, UINT msg, WPARAM wp, LPARAM lp)
|
|
|
|
{
|
|
|
|
switch (msg) {
|
|
|
|
case WM_KEYUP:
|
|
|
|
case WM_KEYDOWN:
|
|
|
|
break;
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2017-03-06 21:22:13 -05:00
|
|
|
case WM_SIZE:
|
|
|
|
#ifdef PLATFORM_WINDOWS
|
|
|
|
{
|
|
|
|
LRESULT rv = DefWindowProcA (w, msg, wp, lp);
|
|
|
|
RECT rect;
|
|
|
|
GetClientRect(w, &rect);
|
|
|
|
#ifndef NDEBUG
|
|
|
|
printf("VST WM_SIZE.. %ld %ld %ld %ld\n", rect.top, rect.left, (rect.right - rect.left), (rect.bottom - rect.top));
|
|
|
|
#endif
|
|
|
|
VSTState* fst = (VSTState*) GetProp (w, "fst_ptr");
|
|
|
|
if (fst) {
|
|
|
|
int32_t width = (rect.right - rect.left);
|
|
|
|
int32_t height = (rect.bottom - rect.top);
|
|
|
|
if (width > 0 && height > 0) {
|
|
|
|
fst->amc (fst->plugin, 15 /*audioMasterSizeWindow */, width, height, NULL, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
break;
|
2014-02-21 11:28:47 -05:00
|
|
|
case WM_CLOSE:
|
|
|
|
/* we don't care about windows closing ...
|
|
|
|
* WM_CLOSE is used for minimizing the window.
|
|
|
|
* Our window has no frame so it shouldn't ever
|
|
|
|
* get sent - but if it does, we don't want our
|
|
|
|
* window to get minimized!
|
|
|
|
*/
|
|
|
|
return 0;
|
|
|
|
break;
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2014-02-21 11:28:47 -05:00
|
|
|
case WM_DESTROY:
|
|
|
|
case WM_NCDESTROY:
|
|
|
|
/* we don't care about windows being destroyed ... */
|
|
|
|
return 0;
|
|
|
|
break;
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2014-02-21 11:28:47 -05:00
|
|
|
default:
|
|
|
|
break;
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
2017-03-06 21:22:13 -05:00
|
|
|
return DefWindowProcA (w, msg, wp, lp);
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-21 11:28:47 -05:00
|
|
|
static VOID CALLBACK
|
|
|
|
idle_hands(
|
|
|
|
HWND hwnd, // handle to window for timer messages
|
|
|
|
UINT message, // WM_TIMER message
|
|
|
|
UINT idTimer, // timer identifier
|
|
|
|
DWORD dwTime) // current system time
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2011-11-21 21:27:26 -05:00
|
|
|
VSTState* fst;
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2014-02-21 11:28:47 -05:00
|
|
|
pthread_mutex_lock (&plugin_mutex);
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2014-02-21 11:28:47 -05:00
|
|
|
for (fst = fst_first; fst; fst = fst->next) {
|
|
|
|
if (fst->gui_shown) {
|
|
|
|
// this seems insane, but some plugins will not draw their meters if you don't
|
|
|
|
// call this every time. Example Ambience by Magnus @ Smartelectron:x
|
|
|
|
fst->plugin->dispatcher (fst->plugin, effEditIdle, 0, 0, NULL, 0);
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2014-02-21 11:28:47 -05:00
|
|
|
if (fst->wantIdle) {
|
|
|
|
fst->wantIdle = fst->plugin->dispatcher (fst->plugin, effIdle, 0, 0, NULL, 0);
|
|
|
|
}
|
|
|
|
}
|
2009-04-15 20:43:41 -04:00
|
|
|
|
2014-03-04 09:25:58 -05:00
|
|
|
pthread_mutex_lock (&fst->lock);
|
2014-02-21 11:28:47 -05:00
|
|
|
#ifndef PLATFORM_WINDOWS /* linux + wine */
|
|
|
|
/* Dispatch messages to send keypresses to the plugin */
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < fst->n_pending_keys; ++i) {
|
|
|
|
MSG msg;
|
|
|
|
/* 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;
|
2009-04-15 20:43:41 -04:00
|
|
|
} else {
|
2014-02-21 11:28:47 -05:00
|
|
|
msg.message = WM_CHAR;
|
|
|
|
msg.wParam = fst->pending_keys[i].character;
|
2009-04-15 20:43:41 -04:00
|
|
|
}
|
2014-02-21 11:28:47 -05:00
|
|
|
msg.hwnd = GetFocus ();
|
|
|
|
msg.lParam = 0;
|
|
|
|
DispatchMessageA (&msg);
|
2009-04-15 20:43:41 -04:00
|
|
|
}
|
|
|
|
|
2014-02-21 11:28:47 -05:00
|
|
|
fst->n_pending_keys = 0;
|
2014-03-04 09:25:58 -05:00
|
|
|
#endif
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2016-11-15 11:07:04 -05:00
|
|
|
/* See comment for call below */
|
|
|
|
vststate_maybe_set_program (fst);
|
2014-02-21 11:28:47 -05:00
|
|
|
fst->want_program = -1;
|
|
|
|
fst->want_chunk = 0;
|
|
|
|
/* If we don't have an editor window yet, we still need to
|
|
|
|
* set up the program, otherwise when we load a plugin without
|
|
|
|
* opening its window it will sound wrong. However, it seems
|
|
|
|
* that if you don't also load the program after opening the GUI,
|
|
|
|
* the GUI does not reflect the program properly. So we'll not
|
|
|
|
* mark that we've done this (ie we won't set want_program to -1)
|
|
|
|
* and so it will be done again if and when the GUI arrives.
|
|
|
|
*/
|
|
|
|
if (fst->program_set_without_editor == 0) {
|
2016-11-15 11:07:04 -05:00
|
|
|
vststate_maybe_set_program (fst);
|
2014-02-21 11:28:47 -05:00
|
|
|
fst->program_set_without_editor = 1;
|
2010-12-29 19:53:37 -05:00
|
|
|
}
|
|
|
|
|
2014-02-21 11:28:47 -05:00
|
|
|
pthread_mutex_unlock (&fst->lock);
|
|
|
|
}
|
2010-12-29 18:31:02 -05:00
|
|
|
|
2014-02-21 11:28:47 -05:00
|
|
|
pthread_mutex_unlock (&plugin_mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
fst_idle_timer_add_plugin (VSTState* fst)
|
|
|
|
{
|
|
|
|
pthread_mutex_lock (&plugin_mutex);
|
|
|
|
|
|
|
|
if (fst_first == NULL) {
|
|
|
|
fst_first = fst;
|
|
|
|
} else {
|
|
|
|
VSTState* p = fst_first;
|
|
|
|
while (p->next) {
|
|
|
|
p = p->next;
|
|
|
|
}
|
|
|
|
p->next = fst;
|
|
|
|
}
|
|
|
|
|
|
|
|
pthread_mutex_unlock (&plugin_mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
fst_idle_timer_remove_plugin (VSTState* fst)
|
|
|
|
{
|
|
|
|
VSTState* p;
|
|
|
|
VSTState* prev;
|
2010-12-29 16:58:44 -05:00
|
|
|
|
2014-02-21 11:28:47 -05:00
|
|
|
pthread_mutex_lock (&plugin_mutex);
|
|
|
|
|
|
|
|
for (p = fst_first, prev = NULL; p; prev = p, p = p->next) {
|
|
|
|
if (p == fst) {
|
|
|
|
if (prev) {
|
|
|
|
prev->next = p->next;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!p->next) {
|
|
|
|
break;
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
2014-02-21 11:28:47 -05:00
|
|
|
}
|
2010-12-29 16:58:44 -05:00
|
|
|
|
2014-02-21 11:28:47 -05:00
|
|
|
if (fst_first == fst) {
|
|
|
|
fst_first = fst_first->next;
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
2009-04-15 20:43:41 -04:00
|
|
|
|
2014-02-21 11:28:47 -05:00
|
|
|
pthread_mutex_unlock (&plugin_mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VSTState*
|
|
|
|
fst_new (void)
|
|
|
|
{
|
|
|
|
VSTState* fst = (VSTState*) calloc (1, sizeof (VSTState));
|
2016-11-15 11:07:04 -05:00
|
|
|
vststate_init (fst);
|
2016-11-14 21:21:02 -05:00
|
|
|
|
2014-02-21 11:28:47 -05:00
|
|
|
#ifdef PLATFORM_WINDOWS
|
2017-03-06 21:22:13 -05:00
|
|
|
fst->voffset = 45;
|
2014-02-21 20:30:57 -05:00
|
|
|
fst->hoffset = 0;
|
2014-02-21 11:28:47 -05:00
|
|
|
#else /* linux + wine */
|
|
|
|
fst->voffset = 24;
|
2014-02-21 20:30:57 -05:00
|
|
|
fst->hoffset = 6;
|
2014-02-21 11:28:47 -05:00
|
|
|
#endif
|
|
|
|
return fst;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
fst_delete (VSTState* fst)
|
|
|
|
{
|
|
|
|
if (fst) {
|
|
|
|
free((void*)fst);
|
|
|
|
fst = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static VSTHandle*
|
|
|
|
fst_handle_new (void)
|
|
|
|
{
|
|
|
|
VSTHandle* fst = (VSTHandle*) calloc (1, sizeof (VSTHandle));
|
|
|
|
return fst;
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
2014-02-21 11:28:47 -05:00
|
|
|
#ifndef PLATFORM_WINDOWS /* linux + wine */
|
|
|
|
static gboolean
|
|
|
|
g_idle_call (gpointer ignored) {
|
2014-02-21 20:44:34 -05:00
|
|
|
if (gui_quit) return FALSE;
|
2014-02-21 11:28:47 -05:00
|
|
|
MSG msg;
|
|
|
|
if (PeekMessageA (&msg, NULL, 0, 0, 1)) {
|
|
|
|
TranslateMessage (&msg);
|
|
|
|
DispatchMessageA (&msg);
|
|
|
|
}
|
|
|
|
idle_hands(NULL, 0, 0, 0);
|
2014-02-21 20:44:34 -05:00
|
|
|
g_main_context_iteration(NULL, FALSE);
|
2014-02-21 11:28:47 -05:00
|
|
|
return gui_quit ? FALSE : TRUE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
int
|
2009-02-27 12:11:21 -05:00
|
|
|
fst_init (void* possible_hmodule)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2014-02-21 11:28:47 -05:00
|
|
|
if (host_initialized) return 0;
|
2008-06-02 17:41:35 -04:00
|
|
|
HMODULE hInst;
|
2014-02-21 11:28:47 -05:00
|
|
|
|
2009-02-27 12:11:21 -05:00
|
|
|
if (possible_hmodule) {
|
2014-02-21 11:28:47 -05:00
|
|
|
#ifdef PLATFORM_WINDOWS
|
|
|
|
fst_error ("Error in fst_init(): (module handle is unnecessary for Win32 build)");
|
|
|
|
return -1;
|
|
|
|
#else /* linux + wine */
|
2009-04-15 20:43:41 -04:00
|
|
|
hInst = (HMODULE) possible_hmodule;
|
2014-02-21 11:28:47 -05:00
|
|
|
#endif
|
2009-02-27 12:11:21 -05:00
|
|
|
} else if ((hInst = GetModuleHandleA (NULL)) == NULL) {
|
2009-04-15 20:43:41 -04:00
|
|
|
fst_error ("can't get module handle");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-02-21 11:28:47 -05:00
|
|
|
if (!hInst) {
|
|
|
|
fst_error ("Cannot initialise VST host");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
WNDCLASSEX wclass;
|
|
|
|
|
2009-04-15 20:43:41 -04:00
|
|
|
wclass.cbSize = sizeof(WNDCLASSEX);
|
2014-02-21 11:28:47 -05:00
|
|
|
#ifdef PLATFORM_WINDOWS
|
|
|
|
wclass.style = (CS_HREDRAW | CS_VREDRAW);
|
|
|
|
wclass.hIcon = NULL;
|
|
|
|
wclass.hCursor = LoadCursor(0, IDC_ARROW);
|
|
|
|
#else /* linux + wine */
|
2009-04-15 20:43:41 -04:00
|
|
|
wclass.style = 0;
|
2014-02-21 11:28:47 -05:00
|
|
|
wclass.hIcon = LoadIcon(hInst, "FST");
|
|
|
|
wclass.hCursor = LoadCursor(0, IDI_APPLICATION);
|
|
|
|
#endif
|
|
|
|
wclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
|
|
|
|
wclass.lpfnWndProc = vstedit_wndproc;
|
2009-04-15 20:43:41 -04:00
|
|
|
wclass.cbClsExtra = 0;
|
|
|
|
wclass.cbWndExtra = 0;
|
|
|
|
wclass.hInstance = hInst;
|
|
|
|
wclass.lpszMenuName = "MENU_FST";
|
|
|
|
wclass.lpszClassName = "FST";
|
|
|
|
wclass.hIconSm = 0;
|
2009-02-27 12:11:21 -05:00
|
|
|
|
2014-02-21 11:28:47 -05:00
|
|
|
pthread_mutex_init (&plugin_mutex, NULL);
|
|
|
|
host_initialized = -1;
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2009-02-27 12:11:21 -05:00
|
|
|
if (!RegisterClassExA(&wclass)){
|
2014-02-21 11:28:47 -05:00
|
|
|
fst_error ("Error in fst_init(): (class registration failed");
|
2009-02-27 12:11:21 -05:00
|
|
|
return -1;
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
2014-02-21 20:44:34 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fst_start_threading(void)
|
|
|
|
{
|
2014-04-14 09:10:28 -04:00
|
|
|
#ifndef PLATFORM_WINDOWS /* linux + wine */
|
2014-02-21 20:44:34 -05:00
|
|
|
if (idle_id == 0) {
|
|
|
|
gui_quit = 0;
|
|
|
|
idle_id = g_idle_add (g_idle_call, NULL);
|
|
|
|
}
|
2014-04-11 11:48:12 -04:00
|
|
|
#endif
|
2014-04-14 09:10:28 -04:00
|
|
|
}
|
2014-02-21 20:44:34 -05:00
|
|
|
|
|
|
|
void
|
|
|
|
fst_stop_threading(void) {
|
2014-04-14 09:10:28 -04:00
|
|
|
#ifndef PLATFORM_WINDOWS /* linux + wine */
|
2014-02-21 20:44:34 -05:00
|
|
|
if (idle_id != 0) {
|
|
|
|
gui_quit = 1;
|
|
|
|
PostQuitMessage (0);
|
|
|
|
g_main_context_iteration(NULL, FALSE);
|
|
|
|
//g_source_remove(idle_id);
|
|
|
|
idle_id = 0;
|
|
|
|
}
|
2014-04-11 11:48:12 -04:00
|
|
|
#endif
|
2014-04-14 09:10:28 -04:00
|
|
|
}
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2009-04-15 20:43:41 -04:00
|
|
|
void
|
2014-02-21 11:28:47 -05:00
|
|
|
fst_exit (void)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2014-02-21 11:28:47 -05:00
|
|
|
if (!host_initialized) return;
|
|
|
|
VSTState* fst;
|
|
|
|
// If any plugins are still open at this point, close them!
|
|
|
|
while ((fst = fst_first))
|
|
|
|
fst_close (fst);
|
2010-12-29 19:53:37 -05:00
|
|
|
|
2014-02-21 11:28:47 -05:00
|
|
|
#ifdef PLATFORM_WINDOWS
|
|
|
|
if (idle_timer_id != 0) {
|
|
|
|
KillTimer(NULL, idle_timer_id);
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
2014-02-21 11:28:47 -05:00
|
|
|
#else /* linux + wine */
|
2014-02-21 20:44:34 -05:00
|
|
|
if (idle_id) {
|
|
|
|
gui_quit = 1;
|
|
|
|
PostQuitMessage (0);
|
|
|
|
}
|
2014-02-21 11:28:47 -05:00
|
|
|
#endif
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2014-02-21 11:28:47 -05:00
|
|
|
host_initialized = FALSE;
|
|
|
|
pthread_mutex_destroy (&plugin_mutex);
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
2009-02-27 12:11:21 -05:00
|
|
|
|
|
|
|
int
|
2014-02-21 11:28:47 -05:00
|
|
|
fst_run_editor (VSTState* fst, void* window_parent)
|
2009-02-27 12:11:21 -05:00
|
|
|
{
|
2016-08-28 05:26:02 -04:00
|
|
|
/* For safety, remove any pre-existing editor window */
|
|
|
|
fst_destroy_editor (fst);
|
|
|
|
|
2014-02-21 11:28:47 -05:00
|
|
|
if (fst->windows_window == NULL) {
|
|
|
|
HMODULE hInst;
|
|
|
|
HWND window;
|
2015-08-11 18:08:45 -04:00
|
|
|
struct ERect* er = NULL;
|
2014-02-21 11:28:47 -05:00
|
|
|
|
|
|
|
if (!(fst->plugin->flags & effFlagsHasEditor)) {
|
|
|
|
fst_error ("Plugin \"%s\" has no editor", fst->handle->name);
|
|
|
|
return -1;
|
|
|
|
}
|
2009-02-27 12:11:21 -05:00
|
|
|
|
2014-02-21 11:28:47 -05:00
|
|
|
if ((hInst = GetModuleHandleA (NULL)) == NULL) {
|
|
|
|
fst_error ("fst_create_editor() can't get module handle");
|
|
|
|
return 1;
|
|
|
|
}
|
2009-02-27 12:11:21 -05:00
|
|
|
|
2014-02-21 11:28:47 -05:00
|
|
|
if ((window = CreateWindowExA (0, "FST", fst->handle->name,
|
|
|
|
window_parent ? WS_CHILD : (WS_OVERLAPPEDWINDOW & ~WS_THICKFRAME & ~WS_MAXIMIZEBOX),
|
|
|
|
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
|
|
|
|
(HWND)window_parent, NULL,
|
|
|
|
hInst,
|
|
|
|
NULL) ) == NULL) {
|
|
|
|
fst_error ("fst_create_editor() cannot create editor window");
|
|
|
|
return 1;
|
|
|
|
}
|
2009-02-27 12:11:21 -05:00
|
|
|
|
2014-02-21 11:28:47 -05:00
|
|
|
if (!SetPropA (window, "fst_ptr", fst)) {
|
|
|
|
fst_error ("fst_create_editor() cannot set fst_ptr on window");
|
|
|
|
}
|
2009-02-27 12:11:21 -05:00
|
|
|
|
2014-02-21 11:28:47 -05:00
|
|
|
fst->windows_window = window;
|
2009-02-27 12:11:21 -05:00
|
|
|
|
2014-02-21 11:28:47 -05:00
|
|
|
if (window_parent) {
|
|
|
|
// This is requiredv for some reason. Note the parent is set above when the window
|
|
|
|
// is created. Without this extra call the actual plugin window will draw outside
|
|
|
|
// of our plugin window.
|
|
|
|
SetParent((HWND)fst->windows_window, (HWND)window_parent);
|
|
|
|
fst->xid = 0;
|
|
|
|
#ifndef PLATFORM_WINDOWS /* linux + wine */
|
|
|
|
} else {
|
|
|
|
SetWindowPos (fst->windows_window, 0, 9999, 9999, 2, 2, 0);
|
|
|
|
ShowWindow (fst->windows_window, SW_SHOWNA);
|
|
|
|
fst->xid = (int) GetPropA (fst->windows_window, "__wine_x11_whole_window");
|
|
|
|
#endif
|
|
|
|
}
|
2009-02-27 12:11:21 -05:00
|
|
|
|
2014-02-21 11:28:47 -05:00
|
|
|
// This is the suggested order of calls.
|
|
|
|
fst->plugin->dispatcher (fst->plugin, effEditGetRect, 0, 0, &er, 0 );
|
|
|
|
fst->plugin->dispatcher (fst->plugin, effEditOpen, 0, 0, fst->windows_window, 0 );
|
|
|
|
fst->plugin->dispatcher (fst->plugin, effEditGetRect, 0, 0, &er, 0 );
|
2009-02-27 12:11:21 -05:00
|
|
|
|
2015-08-11 18:08:45 -04:00
|
|
|
if (er != NULL) {
|
|
|
|
fst->width = er->right - er->left;
|
|
|
|
fst->height = er->bottom - er->top;
|
|
|
|
}
|
2009-02-27 12:11:21 -05:00
|
|
|
|
2014-02-21 11:28:47 -05:00
|
|
|
fst->been_activated = TRUE;
|
2009-02-27 12:11:21 -05:00
|
|
|
|
2014-02-21 11:28:47 -05:00
|
|
|
}
|
2009-02-27 12:11:21 -05:00
|
|
|
|
2014-02-21 11:28:47 -05:00
|
|
|
if (fst->windows_window) {
|
|
|
|
#ifdef PLATFORM_WINDOWS
|
|
|
|
if (idle_timer_id == 0) {
|
|
|
|
// Init the idle timer if needed, so that the main window calls us.
|
|
|
|
idle_timer_id = SetTimer(NULL, idle_timer_id, 50, (TIMERPROC) idle_hands);
|
|
|
|
}
|
|
|
|
#endif
|
2009-02-27 12:11:21 -05:00
|
|
|
|
2014-02-21 11:28:47 -05:00
|
|
|
fst_idle_timer_add_plugin (fst);
|
2009-02-27 12:11:21 -05:00
|
|
|
}
|
2014-02-21 11:28:47 -05:00
|
|
|
|
|
|
|
return fst->windows_window == NULL ? -1 : 0;
|
2009-02-27 12:11:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-11-21 21:27:26 -05:00
|
|
|
fst_destroy_editor (VSTState* fst)
|
2009-02-27 12:11:21 -05:00
|
|
|
{
|
2011-11-21 21:27:26 -05:00
|
|
|
if (fst->windows_window) {
|
2014-02-21 11:28:47 -05:00
|
|
|
fprintf (stderr, "%s destroying edit window\n", fst->handle->name);
|
2009-02-27 12:11:21 -05:00
|
|
|
|
2014-02-21 11:28:47 -05:00
|
|
|
fst_idle_timer_remove_plugin (fst);
|
|
|
|
fst->plugin->dispatcher( fst->plugin, effEditClose, 0, 0, NULL, 0.0 );
|
2009-02-27 12:11:21 -05:00
|
|
|
|
2014-02-21 11:28:47 -05:00
|
|
|
DestroyWindow ((HWND)(fst->windows_window));
|
2009-02-27 12:11:21 -05:00
|
|
|
|
2014-02-21 11:28:47 -05:00
|
|
|
fst->windows_window = NULL;
|
2009-02-27 12:11:21 -05:00
|
|
|
}
|
|
|
|
|
2014-02-21 11:28:47 -05:00
|
|
|
fst->been_activated = FALSE;
|
2009-02-27 12:11:21 -05:00
|
|
|
}
|
|
|
|
|
2014-02-21 11:28:47 -05:00
|
|
|
void
|
|
|
|
fst_move_window_into_view (VSTState* fst)
|
2009-02-27 12:11:21 -05:00
|
|
|
{
|
2014-02-21 11:28:47 -05:00
|
|
|
if (fst->windows_window) {
|
|
|
|
#ifdef PLATFORM_WINDOWS
|
2017-03-06 21:22:13 -05:00
|
|
|
SetWindowPos ((HWND)(fst->windows_window),
|
|
|
|
HWND_TOP /*0*/,
|
|
|
|
fst->hoffset, fst->voffset,
|
|
|
|
fst->width, fst->height,
|
|
|
|
SWP_NOACTIVATE|SWP_NOOWNERZORDER);
|
2014-02-21 11:28:47 -05:00
|
|
|
#else /* linux + wine */
|
2014-02-21 20:30:57 -05:00
|
|
|
SetWindowPos ((HWND)(fst->windows_window), 0, 0, 0, fst->width + fst->hoffset, fst->height + fst->voffset, 0);
|
2014-02-21 11:28:47 -05:00
|
|
|
#endif
|
|
|
|
ShowWindow ((HWND)(fst->windows_window), SW_SHOWNA);
|
2017-03-06 21:22:13 -05:00
|
|
|
UpdateWindow ((HWND)(fst->windows_window));
|
2009-02-27 12:11:21 -05:00
|
|
|
}
|
2014-02-21 11:28:47 -05:00
|
|
|
}
|
2009-02-27 12:11:21 -05:00
|
|
|
|
2014-02-21 11:28:47 -05:00
|
|
|
static HMODULE
|
|
|
|
fst_load_vst_library(const char * path)
|
|
|
|
{
|
|
|
|
char legalized_path[PATH_MAX];
|
|
|
|
strcpy (legalized_path, g_locale_from_utf8(path, -1, NULL, NULL, NULL));
|
|
|
|
return ( LoadLibraryA (legalized_path) );
|
2009-02-27 12:11:21 -05:00
|
|
|
}
|
|
|
|
|
2011-11-21 20:28:34 -05:00
|
|
|
VSTHandle *
|
2008-06-02 17:41:35 -04:00
|
|
|
fst_load (const char *path)
|
|
|
|
{
|
2014-02-21 11:28:47 -05:00
|
|
|
VSTHandle* fhandle = NULL;
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2014-02-21 11:28:47 -05:00
|
|
|
if ((strlen(path)) && (NULL != (fhandle = fst_handle_new ())))
|
|
|
|
{
|
|
|
|
char* period;
|
|
|
|
fhandle->path = strdup (path);
|
2014-04-14 09:21:29 -04:00
|
|
|
fhandle->name = g_path_get_basename(path);
|
2014-02-21 11:28:47 -05:00
|
|
|
if ((period = strrchr (fhandle->name, '.'))) {
|
|
|
|
*period = '\0';
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
2014-02-21 11:28:47 -05:00
|
|
|
// See if we can load the plugin DLL
|
|
|
|
if ((fhandle->dll = (HMODULE)fst_load_vst_library (path)) == NULL) {
|
|
|
|
fst_unload (&fhandle);
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2016-11-17 07:03:36 -05:00
|
|
|
fhandle->main_entry = (main_entry_t) GetProcAddress ((HMODULE)fhandle->dll, "VSTPluginMain");
|
2014-02-19 20:29:58 -05:00
|
|
|
|
2014-02-21 11:28:47 -05:00
|
|
|
if (fhandle->main_entry == 0) {
|
2016-11-17 07:03:36 -05:00
|
|
|
fhandle->main_entry = (main_entry_t) GetProcAddress ((HMODULE)fhandle->dll, "main");
|
2014-02-19 20:29:58 -05:00
|
|
|
}
|
|
|
|
|
2014-02-21 11:28:47 -05:00
|
|
|
if (fhandle->main_entry == 0) {
|
|
|
|
fst_unload (&fhandle);
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
return fhandle;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2014-02-21 11:28:47 -05:00
|
|
|
fst_unload (VSTHandle** fhandle)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2014-02-21 11:28:47 -05:00
|
|
|
if (!(*fhandle)) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((*fhandle)->plugincnt) {
|
2008-06-02 17:41:35 -04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-02-21 11:28:47 -05:00
|
|
|
if ((*fhandle)->dll) {
|
|
|
|
FreeLibrary ((HMODULE)(*fhandle)->dll);
|
|
|
|
(*fhandle)->dll = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((*fhandle)->path) {
|
|
|
|
free ((*fhandle)->path);
|
|
|
|
(*fhandle)->path = NULL;
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
2014-04-14 09:21:29 -04:00
|
|
|
if ((*fhandle)->name) {
|
|
|
|
free ((*fhandle)->name);
|
2014-02-21 11:28:47 -05:00
|
|
|
(*fhandle)->name = NULL;
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
2014-02-21 11:28:47 -05:00
|
|
|
|
|
|
|
free (*fhandle);
|
|
|
|
*fhandle = NULL;
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-11-21 21:27:26 -05:00
|
|
|
VSTState*
|
2011-11-21 20:28:34 -05:00
|
|
|
fst_instantiate (VSTHandle* fhandle, audioMasterCallback amc, void* userptr)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2014-02-21 11:28:47 -05:00
|
|
|
VSTState* fst = NULL;
|
2010-12-29 19:53:37 -05:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
if( fhandle == NULL ) {
|
2014-02-21 11:28:47 -05:00
|
|
|
fst_error( "fst_instantiate(): (the handle was NULL)\n" );
|
|
|
|
return NULL;
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
2014-02-21 11:28:47 -05:00
|
|
|
fst = fst_new ();
|
2017-03-06 21:22:13 -05:00
|
|
|
fst->amc = amc;
|
2014-02-21 11:28:47 -05:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
if ((fst->plugin = fhandle->main_entry (amc)) == NULL) {
|
2014-02-21 11:28:47 -05:00
|
|
|
fst_error ("fst_instantiate: %s could not be instantiated\n", fhandle->name);
|
2008-06-02 17:41:35 -04:00
|
|
|
free (fst);
|
|
|
|
return NULL;
|
|
|
|
}
|
2014-02-21 11:28:47 -05:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
fst->handle = fhandle;
|
2017-07-08 12:13:42 -04:00
|
|
|
fst->plugin->ptr1 = userptr;
|
2014-02-21 11:28:47 -05:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
if (fst->plugin->magic != kEffectMagic) {
|
2014-02-21 11:28:47 -05:00
|
|
|
fst_error ("fst_instantiate: %s is not a vst plugin\n", fhandle->name);
|
|
|
|
fst_close(fst);
|
2008-06-02 17:41:35 -04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-03-06 17:49:40 -05:00
|
|
|
if (!userptr) {
|
|
|
|
/* scanning.. or w/o master-callback userptr == 0, open now.
|
|
|
|
*
|
|
|
|
* Session::vst_callback needs a pointer to the AEffect
|
|
|
|
* ((VSTPlugin*)userptr)->_plugin = vstfx->plugin
|
|
|
|
* before calling effOpen, because effOpen may call back
|
|
|
|
*/
|
|
|
|
fst->plugin->dispatcher (fst->plugin, effOpen, 0, 0, 0, 0);
|
|
|
|
fst->vst_version = fst->plugin->dispatcher (fst->plugin, effGetVstVersion, 0, 0, 0, 0);
|
|
|
|
}
|
2014-02-21 11:28:47 -05:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
fst->handle->plugincnt++;
|
2009-02-27 12:11:21 -05:00
|
|
|
fst->wantIdle = 0;
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
return fst;
|
|
|
|
}
|
|
|
|
|
2014-02-21 20:44:34 -05:00
|
|
|
void fst_audio_master_idle(void) {
|
|
|
|
while(g_main_context_iteration(NULL, FALSE)) ;
|
|
|
|
}
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
void
|
2011-11-21 21:27:26 -05:00
|
|
|
fst_close (VSTState* fst)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2014-02-21 11:28:47 -05:00
|
|
|
if (fst != NULL) {
|
|
|
|
fst_destroy_editor (fst);
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2014-02-21 11:28:47 -05:00
|
|
|
if (fst->plugin) {
|
|
|
|
fst->plugin->dispatcher (fst->plugin, effMainsChanged, 0, 0, NULL, 0);
|
|
|
|
fst->plugin->dispatcher (fst->plugin, effClose, 0, 0, 0, 0);
|
|
|
|
fst->plugin = NULL;
|
2009-02-27 12:11:21 -05:00
|
|
|
}
|
|
|
|
|
2014-02-21 11:28:47 -05:00
|
|
|
if (fst->handle) {
|
|
|
|
if (fst->handle->plugincnt && --fst->handle->plugincnt == 0) {
|
2009-02-27 12:11:21 -05:00
|
|
|
|
2014-02-21 11:28:47 -05:00
|
|
|
fst->handle->main_entry = NULL;
|
2014-02-22 23:51:58 -05:00
|
|
|
fst_unload (&fst->handle); // XXX
|
2009-02-27 12:11:21 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-21 11:28:47 -05:00
|
|
|
/* It might be good for this to be in it's own cleanup function
|
|
|
|
since it will free the memory for the fst leaving the caller
|
|
|
|
with an invalid pointer. Caller beware */
|
|
|
|
fst_delete(fst);
|
2009-02-27 12:11:21 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-21 11:28:47 -05:00
|
|
|
#if 0 // ?? who needs this, where?
|
|
|
|
float htonf (float v)
|
2009-02-27 12:11:21 -05:00
|
|
|
{
|
2014-02-21 11:28:47 -05:00
|
|
|
float result;
|
|
|
|
char * fin = (char*)&v;
|
|
|
|
char * fout = (char*)&result;
|
|
|
|
fout[0] = fin[3];
|
|
|
|
fout[1] = fin[2];
|
|
|
|
fout[2] = fin[1];
|
|
|
|
fout[3] = fin[0];
|
|
|
|
return result;
|
2009-02-27 12:11:21 -05:00
|
|
|
}
|
2014-02-21 11:28:47 -05:00
|
|
|
#endif
|