--- /dev/null
+/*
+ * aeffectx.h - simple header to allow VeSTige compilation and eventually work
+ *
+ * Copyright (c) 2006 Javier Serrano Polo <jasp00/at/users.sourceforge.net>
+ *
+ * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program (see COPYING); if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA.
+ *
+ */
+
+
+#ifndef _AEFFECTX_H
+#define _AEFFECTX_H
+
+
+#define audioMasterAutomate 0
+#define audioMasterVersion 1
+#define audioMasterCurrentId 2
+#define audioMasterIdle 3
+#define audioMasterPinConnected 4
+// unsupported? 5
+#define audioMasterWantMidi 6
+#define audioMasterGetTime 7
+#define audioMasterProcessEvents 8
+#define audioMasterSetTime 9
+#define audioMasterTempoAt 10
+#define audioMasterGetNumAutomatableParameters 11
+#define audioMasterGetParameterQuantization 12
+#define audioMasterIOChanged 13
+#define audioMasterNeedIdle 14
+#define audioMasterSizeWindow 15
+#define audioMasterGetSampleRate 16
+#define audioMasterGetBlockSize 17
+#define audioMasterGetInputLatency 18
+#define audioMasterGetOutputLatency 19
+#define audioMasterGetPreviousPlug 20
+#define audioMasterGetNextPlug 21
+#define audioMasterWillReplaceOrAccumulate 22
+#define audioMasterGetCurrentProcessLevel 23
+#define audioMasterGetAutomationState 24
+#define audioMasterOfflineStart 25
+#define audioMasterOfflineRead 26
+#define audioMasterOfflineWrite 27
+#define audioMasterOfflineGetCurrentPass 28
+#define audioMasterOfflineGetCurrentMetaPass 29
+#define audioMasterSetOutputSampleRate 30
+// unsupported? 31
+#define audioMasterGetSpeakerArrangement 31 // deprecated in 2.4?
+#define audioMasterGetVendorString 32
+#define audioMasterGetProductString 33
+#define audioMasterGetVendorVersion 34
+#define audioMasterVendorSpecific 35
+#define audioMasterSetIcon 36
+#define audioMasterCanDo 37
+#define audioMasterGetLanguage 38
+#define audioMasterOpenWindow 39
+#define audioMasterCloseWindow 40
+#define audioMasterGetDirectory 41
+#define audioMasterUpdateDisplay 42
+#define audioMasterBeginEdit 43
+#define audioMasterEndEdit 44
+#define audioMasterOpenFileSelector 45
+#define audioMasterCloseFileSelector 46// currently unused
+#define audioMasterEditFile 47// currently unused
+#define audioMasterGetChunkFile 48// currently unused
+#define audioMasterGetInputSpeakerArrangement 49 // currently unused
+
+#define effFlagsHasEditor 1
+// very likely
+#define effFlagsCanReplacing (1 << 4)
+// currently unused
+#define effFlagsIsSynth (1 << 8)
+
+#define effOpen 0
+//currently unused
+#define effClose 1
+// currently unused
+#define effSetProgram 2
+// currently unused
+#define effGetProgram 3
+// currently unused
+#define effGetProgramName 5
+#define effGetParamLabel 6
+// currently unused
+#define effGetParamName 8
+// this is a guess
+#define effSetSampleRate 10
+#define effSetBlockSize 11
+#define effMainsChanged 12
+#define effEditGetRect 13
+#define effEditOpen 14
+#define effEditClose 15
+#define effEditIdle 19
+#define effProcessEvents 25
+#define effGetEffectName 45
+// missing
+#define effGetParameterProperties 47
+#define effGetVendorString 47
+#define effGetProductString 48
+#define effGetVendorVersion 49
+// currently unused
+#define effCanDo 51
+// currently unused
+#define effGetVstVersion 58
+
+#ifdef WORDS_BIGENDIAN
+// "VstP"
+#define kEffectMagic 0x50747356
+#else
+// "PtsV"
+#define kEffectMagic 0x56737450
+#endif
+
+#define kVstLangEnglish 1
+#define kVstMidiType 1
+#define kVstTransportPlaying (1 << 1)
+#define kVstParameterUsesFloatStep (1 << 2)
+#define kVstTempoValid (1 << 10)
+#define kVstBarsValid (1 << 11)
+#define kVstTransportChanged 1
+
+typedef struct VstMidiEvent
+{
+ // 00
+ int type;
+ // 04
+ int byteSize;
+ // 08
+ int deltaFrames;
+ // 0c?
+ int flags;
+ // 10?
+ int noteLength;
+ // 14?
+ int noteOffset;
+ // 18
+ char midiData[4];
+ // 1c?
+ char detune;
+ // 1d?
+ char noteOffVelocity;
+ // 1e?
+ char reserved1;
+ // 1f?
+ char reserved2;
+
+} VstMidiEvent;
+
+
+
+
+typedef struct VstEvent
+{
+ char dump[sizeof( VstMidiEvent )];
+
+} VstEvent ;
+
+
+
+
+typedef struct VstEvents
+{
+ // 00
+ int numEvents;
+ // 04
+ int reserved;
+ // 08
+ VstEvent * events[];
+} VstEvents;
+
+
+
+
+// Not finished, neither really used
+typedef struct VstParameterProperties
+{
+ float stepFloat;
+ char label[64];
+ int flags;
+ int minInteger;
+ int maxInteger;
+ int stepInteger;
+ char shortLabel[8];
+ int category;
+ char categoryLabel[24];
+ char empty[128];
+
+} VstParameterProperties;
+
+
+
+
+typedef struct AEffect
+{
+ // Never use c++!!!
+ // 00-03
+ int magic;
+ // dispatcher 04-07
+ int (* dispatcher)( struct AEffect * , int , int , int , void * , float );
+ // process, quite sure 08-0b
+ void (* process)( struct AEffect * , float * * , float * * , int );
+ // setParameter 0c-0f
+ void (* setParameter)( struct AEffect * , int , float );
+ // getParameter 10-13
+ float (* getParameter)( struct AEffect * , int );
+ // programs 14-17
+ int numPrograms;
+ // Params 18-1b
+ int numParams;
+ // Input 1c-1f
+ int numInputs;
+ // Output 20-23
+ int numOutputs;
+ // flags 24-27
+ int flags;
+ // Fill somewhere 28-2b
+ void * user;
+ // Zeroes 2c-2f 30-33 34-37 38-3b
+ char empty3[4 + 4 + 4 + 4];
+ // 1.0f 3c-3f
+ float unkown_float;
+ // An object? pointer 40-43
+ char empty4[4];
+ // Zeroes 44-47
+ char empty5[4];
+ // Id 48-4b
+ char unused_id[4];
+ // Don't know 4c-4f
+ char unknown1[4];
+ // processReplacing 50-53
+ void (* processReplacing)( struct AEffect * , float * * , float * * , int );
+
+ int uniqueID;
+
+} AEffect;
+
+
+
+
+typedef struct VstTimeInfo
+{
+ // 00
+ double samplePos;
+ // 08
+ double sampleRate;
+ // unconfirmed 10 18
+ char empty1[8 + 8];
+ // 20?
+ double tempo;
+ // unconfirmed 28 30 38
+ char empty2[8 + 8 + 8];
+ // 40?
+ int timeSigNumerator;
+ // 44?
+ int timeSigDenominator;
+ // unconfirmed 48 4c 50
+ char empty3[4 + 4 + 4];
+ // 54
+ int flags;
+
+} VstTimeInfo;
+
+
+
+
+typedef long int (* audioMasterCallback)( AEffect * , long int , long int ,
+ long int , void * , float );
+// we don't use it, may be noise
+#define VSTCALLBACK
+
+
+
+
+#endif
#include <wine/exception.h>
#include <pthread.h>
#include <signal.h>
-
-//#include <x11/xlib.h>
-//#include <x11/xresource.h>
-//#include <x11/xutil.h>
-//#include <x11/xatom.h>
+#include <glib.h>
#include "fst.h"
+#include <X11/X.h>
+#include <X11/Xlib.h>
struct ERect{
short top;
short right;
};
-static pthread_mutex_t plugin_mutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t plugin_mutex;
static FST* fst_first = NULL;
+const char magic[] = "FST Plugin State v002";
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";
-
- case 0x0006:
- return "WM_ACTIVATE";
-
- case 0x0007:
- return "WM_SETFOCUS";
-
- case 0x0008:
- return "WM_KILLFOCUS";
-
- case 0x0009:
- return "WM_SETVISIBLE";
-
- case 0x000a:
- return "WM_ENABLE";
-
- case 0x000b:
- return "WM_SETREDRAW";
-
- 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";
+extern boolean g_quit;
- case 0x0013:
- return "WM_QUERYOPEN";
- case 0x0014:
- return "WM_ERASEBKGND";
- case 0x0015:
- return "WM_SYSCOLORCHANGE";
- case 0x0016:
- return "WM_ENDSESSION";
+#define DELAYED_WINDOW 1
- 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
my_window_proc (HWND w, UINT msg, WPARAM wp, LPARAM lp)
{
- FST* fst;
+ FST* fst=NULL;
+ LRESULT result;
// if (msg != WM_TIMER) {
-// fst_error ("window callback handler, msg = 0x%x (%s) win=%p\n", msg, message_name (msg), w);
+// fst_error ("window callback handler, msg = 0x%x win=%p\n", msg, w);
// }
switch (msg) {
break;
case WM_CLOSE:
+ //printf("wtf.\n" );
PostQuitMessage (0);
-
case WM_DESTROY:
case WM_NCDESTROY:
/* we should never get these */
//return 0;
break;
-
+#if 0
case WM_PAINT:
- if ((fst = GetPropA (w, "fst_ptr")) != NULL) {
- if (fst->window && !fst->been_activated) {
- fst->been_activated = TRUE;
- pthread_cond_signal (&fst->window_status_change);
- pthread_mutex_unlock (&fst->lock);
+ if ((fst = GetPropA (w, "fst_ptr")) != NULL) {
+ if (fst->window && !fst->been_activated) {
+ fst->been_activated = TRUE;
+ pthread_cond_signal (&fst->window_status_change);
+ pthread_mutex_unlock (&fst->lock);
+ }
}
- }
break;
+#endif
+
+#if 0
+ case WM_TIMER:
+ fst = GetPropA( w, "fst_ptr" );
+ if( !fst ) {
+ printf( "Timer without fst_ptr Prop :(\n" );
+ return 0;
+ }
+
+ fst->plugin->dispatcher(fst->plugin, effEditIdle, 0, 0, NULL, 0.0f);
+ if( fst->wantIdle )
+ fst->plugin->dispatcher(fst->plugin, 53, 0, 0, NULL, 0.0f);
+ return 0;
+#endif
+
+
default:
break;
}
return DefWindowProcA (w, msg, wp, lp );
+ //return 0;
}
static FST*
fst_new ()
{
FST* fst = (FST*) calloc (1, sizeof (FST));
-
pthread_mutex_init (&fst->lock, NULL);
pthread_cond_init (&fst->window_status_change, NULL);
-
+ pthread_cond_init (&fst->plugin_dispatcher_called, NULL);
+ fst->want_program = -1;
return fst;
}
return fst;
}
-int
-fst_create_editor (FST* fst)
-{
- HMODULE hInst;
- 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;
-}
-
-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)
{
MSG msg;
FST* fst;
+ char c;
HMODULE hInst;
HWND window;
if ((window = CreateWindowExA (0, "FST", "dummy",
WS_OVERLAPPEDWINDOW & ~WS_THICKFRAME & ~WS_MAXIMIZEBOX,
- CW_USEDEFAULT, CW_USEDEFAULT,
- CW_USEDEFAULT, CW_USEDEFAULT,
+ 9999, 9999,
+ 1, 1,
NULL, NULL,
hInst,
NULL )) == NULL) {
fst_error ("cannot create dummy timer window");
}
- if (!SetTimer (window, 1000, 100, NULL)) {
+ if (!SetTimer (window, 1000, 20, NULL)) {
fst_error ("cannot set timer on dummy window");
}
- while (1) {
-
- GetMessageA (&msg, NULL, 0,0);
-
- if (msg.message == WM_SYSTEMERROR) {
- /* sent when this thread is supposed to exist */
- break;
- }
-
- if (msg.message == WM_KEYDOWN) debreak();
-
+ while (GetMessageA (&msg, NULL, 0,0)) {
TranslateMessage( &msg );
DispatchMessageA (&msg);
and run idle callbacks
*/
- if( msg.message == WM_TIMER ) {
+ if( msg.message == WM_TIMER ) {
pthread_mutex_lock (&plugin_mutex);
again:
for (fst = fst_first; fst; fst = fst->next) {
if (fst->window == NULL) {
pthread_mutex_lock (&fst->lock);
+ fst_error ("Creating window for FST plugin %s", fst->handle->name);
if (fst_create_editor (fst)) {
fst_error ("cannot create editor for plugin %s", fst->handle->name);
fst_event_loop_remove_plugin (fst);
pthread_mutex_unlock (&fst->lock);
goto again;
}
- /* condition/unlock handled when we receive WM_ACTIVATE */
+ /* condition/unlock: it was signalled & unlocked in fst_create_editor() */
+ }
+ if(fst->want_program != -1 ) {
+ fst->plugin->dispatcher (fst->plugin, effSetProgram, 0, fst->want_program, NULL, 0);
+ fst->want_program = -1;
+ }
+
+ if(fst->dispatcher_wantcall) {
+
+ pthread_mutex_lock (&fst->lock);
+ fst->dispatcher_retval = fst->plugin->dispatcher( fst->plugin, fst->dispatcher_opcode,
+ fst->dispatcher_index,
+ fst->dispatcher_val,
+ fst->dispatcher_ptr,
+ fst->dispatcher_opt );
+ fst->dispatcher_wantcall = 0;
+ pthread_cond_signal (&fst->plugin_dispatcher_called);
+ pthread_mutex_unlock (&fst->lock);
}
+ pthread_mutex_lock (&fst->lock);
fst->plugin->dispatcher (fst->plugin, effEditIdle, 0, 0, NULL, 0);
+ if( fst->wantIdle ) {
+ fst->plugin->dispatcher (fst->plugin, 53, 0, 0, NULL, 0);
+ }
+ pthread_mutex_unlock (&fst->lock);
}
pthread_mutex_unlock (&plugin_mutex);
}
}
- fst_error ("FST GUI event loop has quit!");
+ fprintf (stderr, "VST GUI EVENT LOOP THREAD EXIT\n");
return 0;
}
int
-fst_init ()
+fst_init (void* possible_hmodule)
{
- WNDCLASSA wc;
+ WNDCLASSEX wclass;
HMODULE hInst;
-
- if ((hInst = GetModuleHandleA (NULL)) == NULL) {
- fst_error ("can't get module handle");
- return -1;
+
+ if (possible_hmodule) {
+ hInst = (HMODULE) possible_hmodule;
+ } else if ((hInst = GetModuleHandleA (NULL)) == NULL) {
+ fst_error ("can't get module handle");
+ return -1;
}
+ wclass.cbSize = sizeof(WNDCLASSEX);
+ wclass.style = 0;
+ wclass.lpfnWndProc = my_window_proc;
+ wclass.cbClsExtra = 0;
+ wclass.cbWndExtra = 0;
+ wclass.hInstance = hInst;
+ wclass.hIcon = LoadIcon(hInst, "FST");
+ wclass.hCursor = LoadCursor(0, IDI_APPLICATION);
+// wclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
+ wclass.lpszMenuName = "MENU_FST";
+ wclass.lpszClassName = "FST";
+ wclass.hIconSm = 0;
+
+#if 0
wc.style = 0;
wc.lpfnWndProc = my_window_proc;
wc.cbClsExtra = 0;
wc.hIcon = LoadIconA( hInst, "FST");
wc.hCursor = LoadCursorA( NULL, IDI_APPLICATION );
wc.hbrBackground = GetStockObject( BLACK_BRUSH );
- wc.lpszMenuName = "MENU_FST";
+ wc.lpszMenuName = "FSTMENU";
wc.lpszClassName = "FST";
+ //wc.hIconSm = 0;
+#endif
- if (!RegisterClassA(&wc)){
- return 1;
+ if (!RegisterClassExA(&wclass)){
+ printf( "Class register failed :(\n" );
+ return -1;
}
+ fst_error ("Startup win32 GUI thread\n");
+
if (CreateThread (NULL, 0, gui_event_loop, NULL, 0, NULL) == NULL) {
fst_error ("could not create new thread proxy");
return -1;
}
-
return 0;
}
-void
-fst_finish ()
-{
- PostThreadMessageA (gui_thread_id, WM_SYSTEMERROR, 0, 0);
-}
-
int
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);
if (fst_first == NULL) {
p->next = fst;
}
- if (!PostThreadMessageA (gui_thread_id, WM_USER, 0, 0)) {
- fst_error ("could not post message to gui thread");
- return -1;
- }
-
pthread_mutex_unlock (&plugin_mutex);
/* wait for the plugin editor window to be created (or not) */
pthread_mutex_unlock (&fst->lock);
if (!fst->window) {
- fst_error ("no window created for VST plugin editor");
return -1;
}
return 0;
}
+int
+fst_call_dispatcher (FST *fst, int opcode, int index, int val, void *ptr, float opt)
+{
+ pthread_mutex_lock (&fst->lock);
+ fst->dispatcher_opcode = opcode;
+ fst->dispatcher_index = index;
+ fst->dispatcher_val = val;
+ fst->dispatcher_ptr = ptr;
+ fst->dispatcher_opt = opt;
+ fst->dispatcher_wantcall = 1;
+
+ pthread_cond_wait (&fst->plugin_dispatcher_called, &fst->lock);
+ pthread_mutex_unlock (&fst->lock);
+
+ return fst->dispatcher_retval;
+}
+
+int
+fst_create_editor (FST* fst)
+{
+ HMODULE hInst;
+ char class[20];
+ HWND window;
+ struct ERect* er;
+
+ /* "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),
+// (WS_OVERLAPPEDWINDOW & ~WS_MAXIMIZEBOX),
+ 9999,9999,1,1,
+// CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
+ 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");
+
+
+ //printf( "effEditOpen......\n" );
+ 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;
+ //printf( "get rect ses... %d,%d\n", fst->width, fst->height );
+
+ //SetWindowPos (fst->window, 0, 9999, 9999, er->right-er->left+8, er->bottom-er->top+26, 0);
+ SetWindowPos (fst->window, 0, 9999, 9999, 2, 2, 0);
+ ShowWindow (fst->window, SW_SHOWNA);
+ //SetWindowPos (fst->window, 0, 0, 0, er->right-er->left+8, er->bottom-er->top+26, SWP_NOMOVE|SWP_NOZORDER);
+
+ fst->xid = (int) GetPropA (window, "__wine_x11_whole_window");
+ printf( "And xid = %x\n", fst->xid );
+ fst->been_activated = TRUE;
+ printf ("Signalling window ready\n");
+ pthread_cond_signal (&fst->window_status_change);
+ pthread_mutex_unlock (&fst->lock);
+
+ return 0;
+}
+
+void
+fst_move_window_into_view (FST* fst)
+{
+ if (fst->window) {
+ SetWindowPos (fst->window, 0, 0, 0, fst->width, fst->height+24, 0);
+ ShowWindow (fst->window, SW_SHOWNA);
+ }
+}
+
+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)) {
+ //if (!PostThreadMessageA (gui_thread_id, WM_QUIT, 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;
+ }
+
+}
+
+HMODULE
+fst_load_vst_library(const char * path)
+{
+ HMODULE dll;
+ char * full_path;
+ char * envdup;
+ char * vst_path;
+ size_t len1;
+ size_t len2;
+
+ if ((dll = LoadLibraryA (path)) != NULL) {
+ return dll;
+ }
+
+ envdup = getenv ("VST_PATH");
+ if (envdup == NULL) {
+ return NULL;
+ }
+
+ envdup = strdup (envdup);
+ if (envdup == NULL) {
+ fst_error ("strdup failed");
+ return NULL;
+ }
+
+ len2 = strlen(path);
+
+ vst_path = strtok (envdup, ":");
+ while (vst_path != NULL) {
+ fst_error ("\"%s\"", vst_path);
+ len1 = strlen(vst_path);
+ full_path = malloc (len1 + 1 + len2 + 1);
+ memcpy(full_path, vst_path, len1);
+ full_path[len1] = '/';
+ memcpy(full_path + len1 + 1, path, len2);
+ full_path[len1 + 1 + len2] = '\0';
+
+ if ((dll = LoadLibraryA (full_path)) != NULL) {
+ break;
+ }
+
+ vst_path = strtok (NULL, ":");
+ }
+
+ free(envdup);
+
+ return dll;
+}
+
FSTHandle*
fst_load (const char *path)
{
- char* buf;
+ char* buf, *buf2;
FSTHandle* fhandle;
char* period;
*period = '\0';
}
- if ((fhandle->dll = LoadLibraryA (buf)) == NULL) {
+ if ((fhandle->dll = fst_load_vst_library (buf)) == NULL) {
fst_unload (fhandle);
return NULL;
}
- typedef AEffect* (*entryFunctionType)(audioMasterCallback);
-
- if ((fhandle->main_entry = (entryFunctionType) GetProcAddress (fhandle->dll, "main")) == NULL) {
+ if ((fhandle->main_entry = (main_entry_t) GetProcAddress (fhandle->dll, "main")) == NULL) {
fst_unload (fhandle);
return NULL;
}
//fst->plugin->dispatcher (fst->plugin, effMainsChanged, 0, 0, NULL, 0);
fst->handle->plugincnt++;
+ fst->wantIdle = 0;
return fst;
}
{
return fst->xid;
}
+
+float htonf (float v)
+{
+ 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;
+}
+
+#if 0
+int fst_load_state (FST * fst, char * filename)
+{
+ FILE * f = fopen (filename, "rb");
+ if (f) {
+ char testMagic[sizeof (magic)];
+ fread (&testMagic, sizeof (magic), 1, f);
+ if (strcmp (testMagic, magic)) {
+ printf ("File corrupt\n");
+ return FALSE;
+ }
+
+ char productString[64];
+ char vendorString[64];
+ char effectName[64];
+ char testString[64];
+ unsigned length;
+ int success;
+
+ fread (&length, sizeof (unsigned), 1, f);
+ length = htonl (length);
+ fread (productString, length, 1, f);
+ productString[length] = 0;
+ printf ("Product string: %s\n", productString);
+
+ success = fst_call_dispatcher( fst, effGetProductString, 0, 0, testString, 0 );
+ if (success == 1) {
+ if (strcmp (testString, productString) != 0) {
+ printf ("Product string mismatch! Plugin has: %s\n", testString);
+ fclose (f);
+ return FALSE;
+ }
+ } else if (length != 0) {
+ printf ("Product string mismatch! Plugin has none.\n", testString);
+ fclose (f);
+ return FALSE;
+ }
+
+ fread (&length, sizeof (unsigned), 1, f);
+ length = htonl (length);
+ fread (effectName, length, 1, f);
+ effectName[length] = 0;
+ printf ("Effect name: %s\n", effectName);
+
+ success = fst_call_dispatcher( fst, effGetEffectName, 0, 0, testString, 0 );
+ if (success == 1) {
+ if (strcmp (testString, effectName) != 0) {
+ printf ("Effect name mismatch! Plugin has: %s\n", testString);
+ fclose (f);
+ return FALSE;
+ }
+ } else if (length != 0) {
+ printf ("Effect name mismatch! Plugin has none.\n", testString);
+ fclose (f);
+ return FALSE;
+ }
+
+ fread (&length, sizeof (unsigned), 1, f);
+ length = htonl (length);
+ fread (vendorString, length, 1, f);
+ vendorString[length] = 0;
+ printf ("Vendor string: %s\n", vendorString);
+
+ success = fst_call_dispatcher( fst, effGetVendorString, 0, 0, testString, 0 );
+ if (success == 1) {
+ if (strcmp (testString, vendorString) != 0) {
+ printf ("Vendor string mismatch! Plugin has: %s\n", testString);
+ fclose (f);
+ return FALSE;
+ }
+ } else if (length != 0) {
+ printf ("Vendor string mismatch! Plugin has none.\n", testString);
+ fclose (f);
+ return FALSE;
+ }
+
+ int numParam;
+ unsigned i;
+ fread (&numParam, sizeof (int), 1, f);
+ numParam = htonl (numParam);
+ for (i = 0; i < numParam; ++i) {
+ float val;
+ fread (&val, sizeof (float), 1, f);
+ val = htonf (val);
+
+ pthread_mutex_lock( &fst->lock );
+ fst->plugin->setParameter( fst->plugin, i, val );
+ pthread_mutex_unlock( &fst->lock );
+ }
+
+ int bytelen;
+ fread (&bytelen, sizeof (int), 1, f);
+ bytelen = htonl (bytelen);
+ if (bytelen) {
+ char * buf = malloc (bytelen);
+ fread (buf, bytelen, 1, f);
+
+ fst_call_dispatcher( fst, 24, 0, bytelen, buf, 0 );
+ free (buf);
+ }
+ } else {
+ printf ("Could not open state file\n");
+ return FALSE;
+ }
+ return TRUE;
+
+}
+#endif
+
+int fst_save_state (FST * fst, char * filename)
+{
+ FILE * f = fopen (filename, "wb");
+ if (f) {
+ int bytelen;
+ int numParams = fst->plugin->numParams;
+ unsigned i;
+ char productString[64];
+ char effectName[64];
+ char vendorString[64];
+ int success;
+ unsigned length;
+
+ // write header
+ fprintf( f, "<plugin_state>\n" );
+
+ success = fst_call_dispatcher( fst, effGetProductString, 0, 0, productString, 0 );
+ if( success == 1 ) {
+ fprintf (f, " <check field=\"productString\" value=\"%s\"/>\n", productString);
+ } else {
+ printf ("No product string\n");
+ }
+
+ success = fst_call_dispatcher( fst, effGetEffectName, 0, 0, effectName, 0 );
+ if( success == 1 ) {
+ fprintf (f, " <check field=\"effectName\" value=\"%s\"/>\n", effectName);
+ printf ("Effect name: %s\n", effectName);
+ } else {
+ printf ("No effect name\n");
+ }
+
+ success = fst_call_dispatcher( fst, effGetVendorString, 0, 0, vendorString, 0 );
+ if( success == 1 ) {
+ fprintf (f, " <check field=\"vendorString\" value=\"%s\"/>\n", vendorString);
+ printf ("Vendor string: %s\n", vendorString);
+ } else {
+ printf ("No vendor string\n");
+ }
+
+
+ if( fst->plugin->flags & 32 ) {
+ numParams = 0;
+ }
+
+ for( i=0; i<numParams; i++ ) {
+ float val;
+
+ pthread_mutex_lock( &fst->lock );
+ val = fst->plugin->getParameter( fst->plugin, i );
+ pthread_mutex_unlock( &fst->lock );
+ fprintf( f, " <param index=\"%d\" value=\"%f\"/>\n", i, val );
+ }
+
+ if( fst->plugin->flags & 32 ) {
+ printf( "getting chunk...\n" );
+ void * chunk;
+ bytelen = fst_call_dispatcher( fst, 23, 0, 0, &chunk, 0 );
+ printf( "got tha chunk..\n" );
+ if( bytelen ) {
+ if( bytelen < 0 ) {
+ printf( "Chunke len < 0 !!! Not saving chunk.\n" );
+ } else {
+ char *encoded = g_base64_encode( chunk, bytelen );
+ fprintf( f, " <chunk size=\"%d\">\n %s\n </chunk>\n", bytelen, encoded );
+ g_free( encoded );
+ }
+ }
+ }
+
+ fprintf( f, "</plugin_state>\n" );
+ fclose( f );
+ } else {
+ printf ("Could not open state file\n");
+ return FALSE;
+ }
+ return TRUE;
+}
+