summaryrefslogtreecommitdiff
path: root/libs/fst
diff options
context:
space:
mode:
Diffstat (limited to 'libs/fst')
-rw-r--r--libs/fst/fst.c24
-rw-r--r--libs/fst/fst.h61
-rw-r--r--libs/fst/fstinfofile.c287
-rw-r--r--libs/fst/jackvst.h43
-rw-r--r--libs/fst/scanner.cc119
-rw-r--r--libs/fst/scanner.wine2
-rw-r--r--libs/fst/vsti.c192
-rw-r--r--libs/fst/vstwin.c1104
-rw-r--r--libs/fst/wscript86
9 files changed, 659 insertions, 1259 deletions
diff --git a/libs/fst/fst.c b/libs/fst/fst.c
deleted file mode 100644
index cbee5de52a..0000000000
--- a/libs/fst/fst.c
+++ /dev/null
@@ -1,24 +0,0 @@
-#include <stdio.h>
-#include <stdarg.h>
-
-#include "fst.h"
-
-void
-fst_error (const char *fmt, ...)
-{
- va_list ap;
- char buffer[512];
-
- va_start (ap, fmt);
- vsnprintf (buffer, sizeof(buffer), fmt, ap);
- fst_error_callback (buffer);
- 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;
diff --git a/libs/fst/fst.h b/libs/fst/fst.h
index ec36cf1360..7b9a67125e 100644
--- a/libs/fst/fst.h
+++ b/libs/fst/fst.h
@@ -5,64 +5,31 @@
#include <signal.h>
#include <pthread.h>
+#include "ardour/libardour_visibility.h"
#include "ardour/vst_types.h"
#include "ardour/vestige/aeffectx.h"
-/**
- * Display FST error message.
- *
- * Set via fst_set_error_function(), otherwise a FST-provided
- * 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);
-
-/**
- * Set the @ref fst_error_callback for error message display.
- *
- * The FST library provides two built-in callbacks for this purpose:
- * default_fst_error_callback() and silent_fst_error_callback().
- */
-void fst_set_error_function (void (*func)(const char *));
-
-void fst_error (const char *fmt, ...);
-
#ifdef __cplusplus
extern "C" {
#endif
-extern int fst_init (void* possible_hmodule);
-extern void fst_exit ();
-
-extern VSTHandle* fst_load (const char*);
-extern int fst_unload (VSTHandle*);
-
-extern VSTState * fst_instantiate (VSTHandle *, audioMasterCallback amc, void* userptr);
-extern void fst_close (VSTState *);
-
-extern int fst_create_editor (VSTState* fst);
-extern int fst_run_editor (VSTState *);
-extern void fst_destroy_editor (VSTState *);
-extern void fst_move_window_into_view (VSTState *);
-
-extern VSTInfo *fst_get_info (char *dllpathname);
-extern void fst_free_info (VSTInfo *info);
-extern void fst_event_loop_remove_plugin (VSTState* fst);
-extern int fst_call_dispatcher (VSTState *, int, int, int, void *, float);
+LIBARDOUR_API int fst_init (void* possible_hmodule);
+LIBARDOUR_API void fst_exit (void);
-/**
- * Load a plugin state from a file.
- */
-extern int fst_load_state (VSTState *, char *);
+LIBARDOUR_API VSTHandle* fst_load (const char*);
+LIBARDOUR_API int fst_unload (VSTHandle**);
-/**
- * Save a plugin state to a file.
- */
-extern int fst_save_state (VSTState *, char *);
+LIBARDOUR_API VSTState * fst_instantiate (VSTHandle *, audioMasterCallback amc, void* userptr);
+LIBARDOUR_API void fst_close (VSTState *);
-extern int wine_pthread_create (pthread_t* thread_id, const pthread_attr_t* attr, void *(*function)(void*), void* arg);
+LIBARDOUR_API int fst_run_editor (VSTState *, void* window_parent);
+LIBARDOUR_API void fst_destroy_editor (VSTState *);
+LIBARDOUR_API void fst_move_window_into_view (VSTState *);
+LIBARDOUR_API void fst_event_loop_remove_plugin (VSTState* fst);
+LIBARDOUR_API void fst_start_threading(void);
+LIBARDOUR_API void fst_stop_threading(void);
+LIBARDOUR_API void fst_audio_master_idle(void);
#ifdef __cplusplus
}
diff --git a/libs/fst/fstinfofile.c b/libs/fst/fstinfofile.c
deleted file mode 100644
index 4b5e95c2d1..0000000000
--- a/libs/fst/fstinfofile.c
+++ /dev/null
@@ -1,287 +0,0 @@
-#include "fst.h"
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-
-#include <stdlib.h>
-#include <stddef.h>
-#include <stdio.h>
-#include <string.h>
-
-#define MAX_STRING_LEN 256
-
-#define FALSE 0
-#define TRUE !FALSE
-
-extern char * strdup (const char *);
-
-static char *read_string( FILE *fp ) {
- char buf[MAX_STRING_LEN];
-
- fgets( buf, MAX_STRING_LEN, fp );
- if( strlen( buf ) < MAX_STRING_LEN ) {
-
- if( strlen(buf) )
- buf[strlen(buf)-1] = 0;
-
- return strdup( buf );
- } else {
- return NULL;
- }
-}
-
-static VSTInfo *
-load_fst_info_file (char* filename)
-{
- VSTInfo *info = (VSTInfo *) malloc (sizeof (VSTInfo));
- FILE *fp;
- int i;
-
- if (info == NULL) {
- return NULL;
- }
-
- fp = fopen( filename, "r" );
-
- if (fp == NULL) {
- free (info);
- return NULL;
- }
-
- if( (info->name = read_string( fp )) == NULL ) goto error;
- if( (info->creator = read_string( fp )) == NULL ) goto error;
- if( 1 != fscanf( fp, "%d\n", &info->UniqueID ) ) goto error;
- if( (info->Category = read_string( fp )) == NULL ) goto error;
- if( 1 != fscanf( fp, "%d\n", &info->numInputs ) ) goto error;
- if( 1 != fscanf( fp, "%d\n", &info->numOutputs ) ) goto error;
- if( 1 != fscanf( fp, "%d\n", &info->numParams ) ) goto error;
- if( 1 != fscanf( fp, "%d\n", &info->wantMidi ) ) goto error;
- if( 1 != fscanf( fp, "%d\n", &info->hasEditor ) ) goto error;
- if( 1 != fscanf( fp, "%d\n", &info->canProcessReplacing ) ) goto error;
-
- if( (info->ParamNames = (char **) malloc( sizeof( char * ) * info->numParams )) == NULL ) goto error;
- for( i=0; i<info->numParams; i++ ) {
- if( (info->ParamNames[i] = read_string( fp )) == NULL ) goto error;
- }
- if( (info->ParamLabels = (char **) malloc( sizeof( char * ) * info->numParams )) == NULL ) goto error;
- for( i=0; i<info->numParams; i++ ) {
- if( (info->ParamLabels[i] = read_string( fp )) == NULL ) goto error;
- }
-
-
- fclose( fp );
- return info;
-
-error:
- fclose( fp );
- free( info );
- return NULL;
-}
-
-static int
-save_fst_info_file (VSTInfo* info, char* filename)
-{
- FILE *fp;
- int i;
-
-
- if( info == NULL ) {
- fst_error( "info is NULL\n" );
- return TRUE;
- }
-
- fp = fopen( filename, "w" );
-
- if( fp == NULL ) {
- fst_error( "Cant write info file %s\n", filename );
- return TRUE;
- }
-
- fprintf( fp, "%s\n", info->name );
- fprintf( fp, "%s\n", info->creator );
- fprintf( fp, "%d\n", info->UniqueID );
- fprintf( fp, "%s\n", info->Category );
- fprintf( fp, "%d\n", info->numInputs );
- fprintf( fp, "%d\n", info->numOutputs );
- fprintf( fp, "%d\n", info->numParams );
- fprintf( fp, "%d\n", info->wantMidi );
- fprintf( fp, "%d\n", info->hasEditor );
- fprintf( fp, "%d\n", info->canProcessReplacing );
-
- for( i=0; i<info->numParams; i++ ) {
- fprintf( fp, "%s\n", info->ParamNames[i] );
- }
- for( i=0; i<info->numParams; i++ ) {
- fprintf( fp, "%s\n", info->ParamLabels[i] );
- }
-
-
- fclose( fp );
-
- return FALSE;
-}
-
-static char *fst_dllpath_to_infopath( char *dllpath ) {
- char *retval;
- if( strstr( dllpath, ".dll" ) == NULL ) return NULL;
-
- retval = strdup( dllpath );
- sprintf( retval + strlen(retval) - 4, ".fsi" );
- return retval;
-}
-
-static int fst_info_file_is_valid( char *dllpath ) {
- struct stat dllstat, fststat;
- char *fstpath = fst_dllpath_to_infopath( dllpath );
-
- if( !fstpath ) return FALSE;
-
- if( stat( dllpath, &dllstat ) ){ fst_error( "dll path %s invalid\n", dllpath ); return TRUE; }
- if( stat( fstpath, &fststat ) ) return FALSE;
-
- free( fstpath );
- if( dllstat.st_mtime > fststat.st_mtime )
- return FALSE;
- else
- return TRUE;
-}
-
-static int
-fst_can_midi (VSTState* fst)
-{
- AEffect* plugin = fst->plugin;
- int vst_version = plugin->dispatcher (plugin, effGetVstVersion, 0, 0, NULL, 0.0f);
-
- if (vst_version >= 2) {
-
- /* should we send it VST events (i.e. MIDI) */
-
- if ((plugin->flags & effFlagsIsSynth) ||
- (plugin->dispatcher (plugin, effCanDo, 0, 0,(void*) "receiveVstEvents", 0.0f) > 0))
- return TRUE;
- }
- return FALSE;
-
-}
-static VSTInfo *
-fst_info_from_plugin (VSTState* fst)
-{
- VSTInfo* info = (VSTInfo *) malloc (sizeof (VSTInfo));
- AEffect* plugin;
- int i;
- char creator[65];
-
- if( ! fst ) {
- fst_error( "fst is NULL\n" );
- return NULL;
- }
-
- if( ! info ) return NULL;
-
- plugin = fst->plugin;
-
-
- info->name = strdup(fst->handle->name );
- plugin->dispatcher (plugin, 47 /* effGetVendorString */, 0, 0, creator, 0);
- if (strlen (creator) == 0) {
- info->creator = strdup ("Unknown");
- } else {
- info->creator = strdup (creator);
- }
-
- info->UniqueID = *((int32_t *) &plugin->uniqueID);
-
- info->Category = strdup( "None" ); // FIXME:
- info->numInputs = plugin->numInputs;
- info->numOutputs = plugin->numOutputs;
- info->numParams = plugin->numParams;
- info->wantMidi = fst_can_midi( fst );
- info->hasEditor = plugin->flags & effFlagsHasEditor ? TRUE : FALSE;
- info->canProcessReplacing = plugin->flags & effFlagsCanReplacing ? TRUE : FALSE;
-
- info->ParamNames = (char **) malloc( sizeof( char * ) * info->numParams );
- info->ParamLabels = (char **) malloc( sizeof( char * ) * info->numParams );
- for( i=0; i<info->numParams; i++ ) {
- char name[20];
- char label[9];
- plugin->dispatcher (plugin,
- effGetParamName,
- i, 0, name, 0);
- info->ParamNames[i] = strdup( name );
- plugin->dispatcher (plugin,
- 6 /* effGetParamLabel */,
- i, 0, label, 0);
- info->ParamLabels[i] = strdup( label );
- }
- return info;
-}
-
-// most simple one :) could be sufficient....
-static intptr_t
-simple_master_callback (AEffect *fx, int32_t opcode, int32_t index, intptr_t value, void *ptr, float opt)
-{
- if (opcode == audioMasterVersion) {
- return 2;
- } else {
- return 0;
- }
-}
-
-VSTInfo *
-fst_get_info (char* dllpath)
-{
- if( fst_info_file_is_valid( dllpath ) ) {
- VSTInfo *info;
- char *fstpath = fst_dllpath_to_infopath( dllpath );
-
- info = load_fst_info_file( fstpath );
- free( fstpath );
- return info;
-
- } else {
-
- VSTHandle* h;
- VSTState* fst;
- VSTInfo* info;
- char* fstpath;
-
- if( !(h = fst_load( dllpath )) ) return NULL;
- if( !(fst = fst_instantiate( h, simple_master_callback, NULL )) ) {
- fst_unload( h );
- fst_error( "instantiate failed\n" );
- return NULL;
- }
- fstpath = fst_dllpath_to_infopath( dllpath );
- if( !fstpath ) {
- fst_close( fst );
- fst_unload( h );
- fst_error( "get fst filename failed\n" );
- return NULL;
- }
- info = fst_info_from_plugin( fst );
- save_fst_info_file( info, fstpath );
-
- free( fstpath );
- fst_close( fst );
- fst_unload( h );
- return info;
- }
-}
-
-void
-fst_free_info (VSTInfo *info)
-{
- int i;
-
- for( i=0; i<info->numParams; i++ ) {
- free( info->ParamNames[i] );
- free( info->ParamLabels[i] );
- }
- free( info->name );
- free( info->creator );
- free( info->Category );
- free( info );
-}
-
-
diff --git a/libs/fst/jackvst.h b/libs/fst/jackvst.h
deleted file mode 100644
index 7b7e35f89b..0000000000
--- a/libs/fst/jackvst.h
+++ /dev/null
@@ -1,43 +0,0 @@
-#ifndef __jack_vst_h__
-#define __jack_vst_h__
-
-#include <sys/types.h>
-#include <sys/time.h>
-#include <jack/jack.h>
-#include <jack/ringbuffer.h>
-#include <fst.h>
-#ifdef HAVE_ALSA
-#include <alsa/asoundlib.h>
-#endif
-
-typedef struct _JackVST JackVST;
-
-struct _JackVST {
- jack_client_t *client;
- VSTHandle * handle;
- VSTState * fst;
- float **ins;
- float **outs;
- jack_port_t *midi_port;
- jack_port_t **inports;
- jack_port_t **outports;
- void* userdata;
- int bypassed;
- int muted;
- int current_program;
-
- /* For VST/i support */
-
- int want_midi;
- pthread_t midi_thread;
-#ifdef HAVE_ALSA
- snd_seq_t* seq;
-#endif
- int midiquit;
- jack_ringbuffer_t* event_queue;
- struct VstEvents* events;
-};
-
-#define MIDI_EVENT_MAX 1024
-
-#endif /* __jack_vst_h__ */
diff --git a/libs/fst/scanner.cc b/libs/fst/scanner.cc
new file mode 100644
index 0000000000..b2041d6031
--- /dev/null
+++ b/libs/fst/scanner.cc
@@ -0,0 +1,119 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <vector>
+
+#include "pbd/pbd.h"
+#include "pbd/transmitter.h"
+#include "pbd/receiver.h"
+
+#include "ardour/filesystem_paths.h"
+#ifdef LXVST_SUPPORT
+#include "ardour/linux_vst_support.h"
+#endif
+#include "ardour/vst_info_file.h"
+
+/* make stupid waf happy.
+ * waf cannot build multiple variants of .o object files from the same
+ * source using different wscripts.. it mingles e.g.
+ * build/libs/ardour/vst_info_file.cc.1.o for
+ * both lib/ardour/wscript and lib/fst/wscript
+ *
+ * ...but waf does track include dependencies.
+ */
+#include "../ardour/vst_info_file.cc"
+#ifdef LXVST_SUPPORT
+#include "../ardour/linux_vst_support.cc"
+#endif
+#include "../ardour/filesystem_paths.cc"
+#include "../ardour/directory_names.cc"
+
+
+#ifdef LXVST_SUPPORT
+void
+vstfx_destroy_editor (VSTState* /*vstfx*/) { }
+#endif
+
+using namespace PBD;
+
+class DummyReceiver : public Receiver {
+ protected:
+ void receive (Transmitter::Channel chn, const char * str) {
+ const char *prefix = "";
+ switch (chn) {
+ case Transmitter::Error:
+ prefix = "[ERROR]: ";
+ break;
+ case Transmitter::Info:
+ /* ignore */
+ return;
+ case Transmitter::Warning:
+ prefix = "[WARNING]: ";
+ break;
+ case Transmitter::Fatal:
+ prefix = "[FATAL]: ";
+ break;
+ case Transmitter::Throw:
+ abort ();
+ }
+
+ std::cerr << prefix << str << std::endl;
+
+ if (chn == Transmitter::Fatal) {
+ ::exit (1);
+ }
+ }
+};
+
+DummyReceiver dummy_receiver;
+
+int main (int argc, char **argv) {
+ char *dllpath = NULL;
+ if (argc == 3 && !strcmp("-f", argv[1])) {
+ dllpath = argv[2];
+ if (strstr (dllpath, ".so" ) || strstr(dllpath, ".dll")) {
+ vstfx_remove_infofile(dllpath);
+ vstfx_un_blacklist(dllpath);
+ }
+
+ }
+ else if (argc != 2) {
+ fprintf(stderr, "usage: %s [-f] <vst>\n", argv[0]);
+ return EXIT_FAILURE;
+ } else {
+ dllpath = argv[1];
+ }
+
+ PBD::init();
+
+ dummy_receiver.listen_to (error);
+ dummy_receiver.listen_to (info);
+ dummy_receiver.listen_to (fatal);
+ dummy_receiver.listen_to (warning);
+
+ std::vector<VSTInfo *> *infos = 0;
+
+ if (0) { }
+#ifdef LXVST_SUPPORT
+ else if (strstr (dllpath, ".so")) {
+ infos = vstfx_get_info_lx(dllpath);
+ }
+#endif
+
+#ifdef WINDOWS_VST_SUPPORT
+ else if (strstr (dllpath, ".dll")) {
+ infos = vstfx_get_info_fst(dllpath);
+ }
+#endif
+ else {
+ fprintf(stderr, "'%s' is not a supported VST plugin.\n", dllpath);
+ }
+
+ PBD::cleanup();
+
+ if (!infos || infos->empty()) {
+ return EXIT_FAILURE;
+ } else {
+ return EXIT_SUCCESS;
+ }
+}
diff --git a/libs/fst/scanner.wine b/libs/fst/scanner.wine
new file mode 100644
index 0000000000..ac39b5b339
--- /dev/null
+++ b/libs/fst/scanner.wine
@@ -0,0 +1,2 @@
+#!/bin/sh
+exec wine "`dirname "$0"`/ardour-vst-scanner.exe.so" "$@"
diff --git a/libs/fst/vsti.c b/libs/fst/vsti.c
deleted file mode 100644
index e5c7d9c6c9..0000000000
--- a/libs/fst/vsti.c
+++ /dev/null
@@ -1,192 +0,0 @@
-/*
- * VST instrument support
- *
- * Derived from code that was marked:
- * Copyright (C) Kjetil S. Matheussen 2004 (k.s.matheussen@notam02.no)
- * Alsa-seq midi-code made by looking at the jack-rack source made by Bob Ham.
- *
- * 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; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * $Id: vsti.c,v 1.2 2004/04/07 01:56:23 pauld Exp $
- */
-
-#include <stdio.h>
-#include <unistd.h>
-#include <string.h>
-#include <stdlib.h>
-#include <memory.h>
-#include <fcntl.h>
-#include <stdbool.h>
-#include <jackvst.h>
-#include <pthread.h>
-#include <sched.h>
-#include "ardour/vestige/aeffectx.h"
-
-#ifdef HAVE_ALSAMIDIVSTIXXX // not used in ardour 3
-
-snd_seq_t *
-create_sequencer (const char* client_name, bool isinput)
-{
- snd_seq_t * seq;
- int err;
-
- if ((err = snd_seq_open (&seq, "default", SND_SEQ_OPEN_DUPLEX, 0)) != 0) {
- fst_error ("Could not open ALSA sequencer, aborting\n\n%s\n\n"
- "Make sure you have configure ALSA properly and that\n"
- "/proc/asound/seq/clients exists and contains relevant\n"
- "devices (%s).",
- snd_strerror (err));
- return NULL;
- }
-
- snd_seq_set_client_name (seq, client_name);
-
- if ((err = snd_seq_create_simple_port (seq, isinput? "Input" : "Output",
- (isinput? SND_SEQ_PORT_CAP_WRITE: SND_SEQ_PORT_CAP_READ)| SND_SEQ_PORT_CAP_DUPLEX |
- SND_SEQ_PORT_CAP_SUBS_READ|SND_SEQ_PORT_CAP_SUBS_WRITE,
- SND_SEQ_PORT_TYPE_APPLICATION|SND_SEQ_PORT_TYPE_SPECIFIC)) != 0) {
- fst_error ("Could not create ALSA port: %s", snd_strerror (err));
- snd_seq_close(seq);
- return NULL;
- }
-
- return seq;
-}
-
-static void
-queue_midi (JackVST *jvst, int val1, int val2, int val3)
-{
- VstMidiEvent *pevent;
- jack_ringbuffer_data_t vec[2];
-
- jack_ringbuffer_get_write_vector (jvst->event_queue, vec);
-
- if (vec[0].len < sizeof (VstMidiEvent)) {
- fst_error ("event queue has no write space");
- return;
- }
-
- pevent = (VstMidiEvent *) vec[0].buf;
-
- // printf("note: %d\n",note);
-
- pevent->type = kVstMidiType;
- pevent->byteSize = 24;
- pevent->deltaFrames = 0;
- pevent->flags = 0;
- pevent->detune = 0;
- pevent->noteLength = 0;
- pevent->noteOffset = 0;
- pevent->reserved1 = 0;
- pevent->reserved2 = 0;
- pevent->noteOffVelocity = 0;
- pevent->midiData[0] = val1;
- pevent->midiData[1] = val2;
- pevent->midiData[2] = val3;
- pevent->midiData[3] = 0;
-
- //printf("Sending: %x %x %x\n",val1,val2,val3);
-
- jack_ringbuffer_write_advance (jvst->event_queue, sizeof (VstMidiEvent));
-}
-
-void *midireceiver(void *arg)
-{
- snd_seq_event_t *event;
- JackVST *jvst = (JackVST* )arg;
- int val;
-
- struct sched_param scp;
- scp.sched_priority = 50;
-
- // Try to set fifo priority...
- // this works, if we are root or newe sched-cap manegment is used...
- pthread_setschedparam( pthread_self(), SCHED_FIFO, &scp );
-
- while (1) {
-
- snd_seq_event_input (jvst->seq, &event);
-
- if (jvst->midiquit) {
- break;
- }
-
- switch(event->type){
- case SND_SEQ_EVENT_NOTEON:
- queue_midi(jvst,0x90+event->data.note.channel,event->data.note.note,event->data.note.velocity);
- //printf("Noteon, channel: %d note: %d vol: %d\n",event->data.note.channel,event->data.note.note,event->data.note.velocity);
- break;
- case SND_SEQ_EVENT_NOTEOFF:
- queue_midi(jvst,0x80+event->data.note.channel,event->data.note.note,0);
- //printf("Noteoff, channel: %d note: %d vol: %d\n",event->data.note.channel,event->data.note.note,event->data.note.velocity);
- break;
- case SND_SEQ_EVENT_KEYPRESS:
- //printf("Keypress, channel: %d note: %d vol: %d\n",event->data.note.channel,event->data.note.note,event->data.note.velocity);
- queue_midi(jvst,0xa0+event->data.note.channel,event->data.note.note,event->data.note.velocity);
- break;
- case SND_SEQ_EVENT_CONTROLLER:
- queue_midi(jvst,0xb0+event->data.control.channel,event->data.control.param,event->data.control.value);
- //printf("Control: %d %d %d\n",event->data.control.channel,event->data.control.param,event->data.control.value);
- break;
- case SND_SEQ_EVENT_PITCHBEND:
- val=event->data.control.value + 0x2000;
- queue_midi(jvst,0xe0+event->data.control.channel,val&127,val>>7);
- //printf("Pitch: %d %d %d\n",event->data.control.channel,event->data.control.param,event->data.control.value);
- break;
- case SND_SEQ_EVENT_CHANPRESS:
- //printf("chanpress: %d %d %d\n",event->data.control.channel,event->data.control.param,event->data.control.value);
- queue_midi(jvst,0xd0+event->data.control.channel,event->data.control.value,0);
- break;
- case SND_SEQ_EVENT_PGMCHANGE:
- //printf("pgmchange: %d %d %d\n",event->data.control.channel,event->data.control.param,event->data.control.value);
- queue_midi(jvst,0xc0+event->data.control.channel,event->data.control.value,0);
- break;
- default:
- //printf("Unknown type: %d\n",event->type);
- break;
- }
- }
-
- return NULL;
-}
-
-void stop_midireceiver (JackVST *jvst)
-{
- int err;
- snd_seq_event_t event;
- snd_seq_t *seq2 = create_sequencer ("jfstquit", true);
-
- jvst->midiquit = 1;
-
- snd_seq_connect_to (seq2, 0, snd_seq_client_id (jvst->seq),0);
- snd_seq_ev_clear (&event);
- snd_seq_ev_set_direct (&event);
- snd_seq_ev_set_subs (&event);
- snd_seq_ev_set_source (&event, 0);
- snd_seq_ev_set_controller (&event,1,0x80,50);
-
- if ((err = snd_seq_event_output (seq2, &event)) < 0) {
- fst_error ("cannot send stop event to midi thread: %s\n",
- snd_strerror (err));
- }
-
- snd_seq_drain_output (seq2);
- snd_seq_close (seq2);
- pthread_join (jvst->midi_thread,NULL);
- snd_seq_close (jvst->seq);
-}
-#endif
-
-
diff --git a/libs/fst/vstwin.c b/libs/fst/vstwin.c
index 67ae03986e..27fb3cbead 100644
--- a/libs/fst/vstwin.c
+++ b/libs/fst/vstwin.c
@@ -1,860 +1,632 @@
#include <stdio.h>
-#include <jack/jack.h>
-#include <jack/thread.h>
-#include <libgen.h>
+#include <string.h>
#include <windows.h>
+
+#define fst_error(...) fprintf(stderr, __VA_ARGS__)
+
+#ifdef PLATFORM_WINDOWS
+
+#include <pthread.h>
+static UINT_PTR idle_timer_id = 0;
+
+#else /* linux + wine */
+
+#include <linux/limits.h> // PATH_MAX
#include <winnt.h>
#include <wine/exception.h>
#include <pthread.h>
-#include <signal.h>
-#include <glib.h>
-
-#include "fst.h"
+static int gui_quit = 0;
+static unsigned int idle_id = 0;
-#include <X11/X.h>
-#include <X11/Xlib.h>
+#endif
extern char * strdup (const char *);
+#include <glib.h>
+#include "fst.h"
-struct ERect{
- short top;
- short left;
- short bottom;
- short right;
+struct ERect {
+ short top;
+ short left;
+ short bottom;
+ short right;
};
-static pthread_mutex_t plugin_mutex;
+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";
-/** Head of linked list of all FSTs */
-static VSTState* fst_first = NULL;
-const char magic[] = "FST Plugin State v002";
+static LRESULT WINAPI
+vstedit_wndproc (HWND w, UINT msg, WPARAM wp, LPARAM lp)
+{
+ switch (msg) {
+ case WM_KEYUP:
+ case WM_KEYDOWN:
+ break;
-DWORD gui_thread_id = 0;
-static int gui_quit = 0;
+ 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;
-static LRESULT WINAPI
-my_window_proc (HWND w, UINT msg, WPARAM wp, LPARAM lp)
-{
-#if 0
- if (msg != WM_TIMER) {
- fst_error ("window callback handler, msg = 0x%x win=%p\n", msg, w);
- }
-#endif
+ case WM_DESTROY:
+ case WM_NCDESTROY:
+ /* we don't care about windows being destroyed ... */
+ return 0;
+ break;
- switch (msg) {
- case WM_KEYUP:
- case WM_KEYDOWN:
- break;
-
- case WM_CLOSE:
- /* we don't care about windows closing ... */
- return 0;
- break;
-
- case WM_DESTROY:
- case WM_NCDESTROY:
- /* we don't care about windows being destroyed ... */
- return 0;
- break;
-
- default:
- break;
+ default:
+ break;
}
return DefWindowProcA (w, msg, wp, lp );
}
-static VSTState *
-fst_new ()
-{
- VSTState* fst = (VSTState *) calloc (1, sizeof (VSTState));
- 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;
- fst->want_chunk = 0;
- fst->n_pending_keys = 0;
- fst->has_editor = 0;
- fst->program_set_without_editor = 0;
- return fst;
-}
-
-static VSTHandle*
-fst_handle_new ()
-{
- VSTHandle* fst = (VSTHandle*) calloc (1, sizeof (VSTHandle));
- return fst;
-}
-void
+static void
maybe_set_program (VSTState* fst)
{
if (fst->want_program != -1) {
if (fst->vst_version >= 2) {
- fst->plugin->dispatcher (fst->plugin, 67 /* effBeginSetProgram */, 0, 0, NULL, 0);
+ fst->plugin->dispatcher (fst->plugin, effBeginSetProgram, 0, 0, NULL, 0);
}
-
+
fst->plugin->dispatcher (fst->plugin, effSetProgram, 0, fst->want_program, NULL, 0);
-
+
if (fst->vst_version >= 2) {
- fst->plugin->dispatcher (fst->plugin, 68 /* effEndSetProgram */, 0, 0, NULL, 0);
+ fst->plugin->dispatcher (fst->plugin, effEndSetProgram, 0, 0, NULL, 0);
}
- fst->want_program = -1;
+ fst->want_program = -1;
}
-
+
if (fst->want_chunk == 1) {
+ // XXX check
+ // 24 == audioMasterGetAutomationState,
+ // 48 == audioMasterGetChunkFile
fst->plugin->dispatcher (fst->plugin, 24 /* effSetChunk */, 1, fst->wanted_chunk_size, fst->wanted_chunk, 0);
fst->want_chunk = 0;
}
}
-DWORD WINAPI gui_event_loop (LPVOID param)
+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
{
- MSG msg;
VSTState* fst;
- HMODULE hInst;
- HWND window;
- int i;
-
- gui_thread_id = GetCurrentThreadId ();
- /* create a dummy window for timer events */
-
- if ((hInst = GetModuleHandleA (NULL)) == NULL) {
- fst_error ("can't get module handle");
- return 1;
- }
-
- if ((window = CreateWindowExA (0, "FST", "dummy",
- WS_OVERLAPPEDWINDOW & ~WS_THICKFRAME & ~WS_MAXIMIZEBOX,
- 9999, 9999,
- 1, 1,
- NULL, NULL,
- hInst,
- NULL )) == NULL) {
- fst_error ("cannot create dummy timer window");
- }
+ pthread_mutex_lock (&plugin_mutex);
- if (!SetTimer (window, 1000, 20, NULL)) {
- fst_error ("cannot set timer on dummy window");
- }
+ 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);
- while (!gui_quit) {
+ if (fst->wantIdle) {
+ fst->wantIdle = fst->plugin->dispatcher (fst->plugin, effIdle, 0, 0, NULL, 0);
+ }
+ }
- if (!GetMessageA (&msg, NULL, 0,0)) {
- if (!gui_quit) {
- fprintf (stderr, "QUIT message received by Windows GUI thread - ignored\n");
- continue;
+ pthread_mutex_lock (&fst->lock);
+#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;
} else {
- break;
+ msg.message = WM_CHAR;
+ msg.wParam = fst->pending_keys[i].character;
}
+ msg.hwnd = GetFocus ();
+ msg.lParam = 0;
+ DispatchMessageA (&msg);
}
- TranslateMessage( &msg );
- DispatchMessageA (&msg);
+ fst->n_pending_keys = 0;
+#endif
- if (msg.message != WM_TIMER) {
- continue;
+ /* See comment for maybe_set_program call below */
+ maybe_set_program (fst);
+ 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) {
+ maybe_set_program (fst);
+ fst->program_set_without_editor = 1;
}
- pthread_mutex_lock (&plugin_mutex);
-
- /* Do things that are appropriate for plugins which have open editor windows:
- handle window creation requests, destroy requests,
- and run idle callbacks
- */
-
-again:
- for (fst = fst_first; fst; fst = fst->next) {
-
- pthread_mutex_lock (&fst->lock);
-
- if (fst->has_editor == 1) {
-
- if (fst->destroy) {
- fprintf (stderr, "%s scheduled for destroy\n", fst->handle->name);
- if (fst->windows_window) {
- fst->plugin->dispatcher( fst->plugin, effEditClose, 0, 0, NULL, 0.0 );
- CloseWindow (fst->windows_window);
- fst->windows_window = NULL;
- fst->destroy = FALSE;
- }
- fst_event_loop_remove_plugin (fst);
- fst->been_activated = FALSE;
- pthread_cond_signal (&fst->window_status_change);
- pthread_mutex_unlock (&fst->lock);
- goto again;
- }
-
- if (fst->windows_window == NULL) {
- if (fst_create_editor (fst)) {
- fst_error ("cannot create editor for plugin %s", fst->handle->name);
- fst_event_loop_remove_plugin (fst);
- pthread_cond_signal (&fst->window_status_change);
- pthread_mutex_unlock (&fst->lock);
- goto again;
- } else {
- /* condition/unlock: it was signalled & unlocked in fst_create_editor() */
- }
- }
-
- if (fst->dispatcher_wantcall) {
- 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);
- }
-
- fst->plugin->dispatcher (fst->plugin, effEditIdle, 0, 0, NULL, 0);
-
- if (fst->wantIdle) {
- fst->plugin->dispatcher (fst->plugin, 53, 0, 0, NULL, 0);
- }
-
- /* Dispatch messages to send keypresses to the plugin */
-
- for (i = 0; i < fst->n_pending_keys; ++i) {
- /* 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;
- } else {
- msg.message = WM_CHAR;
- msg.wParam = fst->pending_keys[i].character;
- }
- msg.hwnd = GetFocus ();
- msg.lParam = 0;
- DispatchMessageA (&msg);
- }
-
- fst->n_pending_keys = 0;
-
- /* See comment for maybe_set_program call below */
- maybe_set_program (fst);
- fst->want_program = -1;
- fst->want_chunk = 0;
- }
+ pthread_mutex_unlock (&fst->lock);
+ }
- /* 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) {
- maybe_set_program (fst);
- fst->program_set_without_editor = 1;
- }
+ 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);
+}
- pthread_mutex_unlock (&fst->lock);
+static void
+fst_idle_timer_remove_plugin (VSTState* fst)
+{
+ VSTState* p;
+ VSTState* prev;
+
+ 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;
}
+ }
- pthread_mutex_unlock (&plugin_mutex);
+ if (fst_first == fst) {
+ fst_first = fst_first->next;
}
- return 0;
+ pthread_mutex_unlock (&plugin_mutex);
+}
+
+static VSTState*
+fst_new (void)
+{
+ VSTState* fst = (VSTState*) calloc (1, sizeof (VSTState));
+ pthread_mutex_init (&fst->lock, NULL);
+ pthread_cond_init (&fst->window_status_change, NULL); // unused ?? -> TODO check gtk2ardour
+ pthread_cond_init (&fst->plugin_dispatcher_called, NULL); // unused ??
+ fst->want_program = -1;
+ fst->want_chunk = 0;
+ fst->n_pending_keys = 0;
+ fst->has_editor = 0;
+#ifdef PLATFORM_WINDOWS
+ fst->voffset = 50;
+ fst->hoffset = 0;
+#else /* linux + wine */
+ fst->voffset = 24;
+ fst->hoffset = 6;
+#endif
+ fst->program_set_without_editor = 0;
+ 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;
}
+#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
+
+
int
fst_init (void* possible_hmodule)
{
- WNDCLASSEX wclass;
+ if (host_initialized) return 0;
HMODULE hInst;
-
+
if (possible_hmodule) {
+#ifdef PLATFORM_WINDOWS
+ fst_error ("Error in fst_init(): (module handle is unnecessary for Win32 build)");
+ return -1;
+#else /* linux + wine */
hInst = (HMODULE) possible_hmodule;
+#endif
} else if ((hInst = GetModuleHandleA (NULL)) == NULL) {
fst_error ("can't get module handle");
return -1;
}
+ if (!hInst) {
+ fst_error ("Cannot initialise VST host");
+ return -1;
+ }
+
+ WNDCLASSEX wclass;
+
wclass.cbSize = sizeof(WNDCLASSEX);
+#ifdef PLATFORM_WINDOWS
+ wclass.style = (CS_HREDRAW | CS_VREDRAW);
+ wclass.hIcon = NULL;
+ wclass.hCursor = LoadCursor(0, IDC_ARROW);
+#else /* linux + wine */
wclass.style = 0;
- wclass.lpfnWndProc = my_window_proc;
+ wclass.hIcon = LoadIcon(hInst, "FST");
+ wclass.hCursor = LoadCursor(0, IDI_APPLICATION);
+#endif
+ wclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
+ wclass.lpfnWndProc = vstedit_wndproc;
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;
+ pthread_mutex_init (&plugin_mutex, NULL);
+ host_initialized = -1;
if (!RegisterClassExA(&wclass)){
- printf( "Class register failed :(\n" );
+ fst_error ("Error in fst_init(): (class registration failed");
return -1;
}
+ return 0;
+}
- 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;
+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);
}
-
-#ifdef HAVE_JACK_SET_THREAD_CREATOR
- jack_set_thread_creator (wine_pthread_create);
#endif
-
- return 0;
}
void
-fst_exit ()
-{
- gui_quit = 1;
- PostQuitMessage (0);
+fst_stop_threading(void) {
+#ifndef PLATFORM_WINDOWS /* linux + wine */
+ if (idle_id != 0) {
+ gui_quit = 1;
+ PostQuitMessage (0);
+ g_main_context_iteration(NULL, FALSE);
+ //g_source_remove(idle_id);
+ idle_id = 0;
+ }
+#endif
}
-int
-fst_run_editor (VSTState* fst)
+void
+fst_exit (void)
{
- /* wait for the plugin editor window to be created (or not) */
-
- pthread_mutex_lock (&fst->lock);
+ if (!host_initialized) return;
+ VSTState* fst;
+ // If any plugins are still open at this point, close them!
+ while ((fst = fst_first))
+ fst_close (fst);
- fst->has_editor = 1;
-
- if (!fst->windows_window) {
- pthread_cond_wait (&fst->window_status_change, &fst->lock);
+#ifdef PLATFORM_WINDOWS
+ if (idle_timer_id != 0) {
+ KillTimer(NULL, idle_timer_id);
}
- pthread_mutex_unlock (&fst->lock);
-
- if (!fst->windows_window) {
- return -1;
+#else /* linux + wine */
+ if (idle_id) {
+ gui_quit = 1;
+ PostQuitMessage (0);
}
+#endif
- return 0;
+ host_initialized = FALSE;
+ pthread_mutex_destroy (&plugin_mutex);
}
-int
-fst_call_dispatcher (VSTState* 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 (VSTState * fst)
+fst_run_editor (VSTState* fst, void* window_parent)
{
- HMODULE hInst;
- HWND window;
- struct ERect* er;
+ if (fst->windows_window == NULL) {
+ HMODULE hInst;
+ HWND window;
+ struct ERect* er;
+
+ if (!(fst->plugin->flags & effFlagsHasEditor)) {
+ fst_error ("Plugin \"%s\" has no editor", fst->handle->name);
+ return -1;
+ }
- /* "guard point" to trap errors that occur during plugin loading */
+ if ((hInst = GetModuleHandleA (NULL)) == NULL) {
+ fst_error ("fst_create_editor() can't get module handle");
+ return 1;
+ }
- /* Note: fst->lock is held while this function is called */
+ 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;
+ }
- if (!(fst->plugin->flags & effFlagsHasEditor)) {
- fst_error ("Plugin \"%s\" has no editor", fst->handle->name);
- return -1;
- }
+ if (!SetPropA (window, "fst_ptr", fst)) {
+ fst_error ("fst_create_editor() cannot set fst_ptr on window");
+ }
- 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;
- }
+ fst->windows_window = window;
- if (!SetPropA (window, "fst_ptr", fst)) {
- fst_error ("cannot set fst_ptr on window");
- }
+ 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
+ }
- fst->windows_window = window;
-// fst->xid = (int) GetPropA (window, "__wine_x11_whole_window");
+ // 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 );
+ fst->width = er->right-er->left;
+ fst->height = er->bottom-er->top;
- //printf( "effEditOpen......\n" );
- 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;
- //printf( "get rect ses... %d,%d\n", fst->width, fst->height );
+ fst->been_activated = TRUE;
- //SetWindowPos (fst->window, 0, 9999, 9999, er->right-er->left+8, er->bottom-er->top+26, 0);
- SetWindowPos (fst->windows_window, 0, 9999, 9999, 2, 2, 0);
- ShowWindow (fst->windows_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");
- fst->been_activated = TRUE;
- pthread_cond_signal (&fst->window_status_change);
- pthread_mutex_unlock (&fst->lock);
+ }
- return 0;
-}
+ 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
-void
-fst_move_window_into_view (VSTState* fst)
-{
- if (fst->windows_window) {
- SetWindowPos (fst->windows_window, 0, 0, 0, fst->width, fst->height + 24, 0);
- ShowWindow (fst->windows_window, SW_SHOWNA);
+ fst_idle_timer_add_plugin (fst);
}
+
+ return fst->windows_window == NULL ? -1 : 0;
}
void
fst_destroy_editor (VSTState* fst)
{
- pthread_mutex_lock (&fst->lock);
if (fst->windows_window) {
- fprintf (stderr, "mark %s for destroy\n", fst->handle->name);
- 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);
- fprintf (stderr, "%s editor destroyed\n", fst->handle->name);
- fst->has_editor = 0;
- }
- pthread_mutex_unlock (&fst->lock);
-}
+ fprintf (stderr, "%s destroying edit window\n", fst->handle->name);
-void
-fst_event_loop_remove_plugin (VSTState* fst)
-{
- VSTState* p;
- VSTState* prev;
+ fst_idle_timer_remove_plugin (fst);
+ fst->plugin->dispatcher( fst->plugin, effEditClose, 0, 0, NULL, 0.0 );
- for (p = fst_first, prev = NULL; p->next; prev = p, p = p->next) {
- if (p == fst) {
- if (prev) {
- prev->next = p->next;
- }
- }
- }
+ DestroyWindow ((HWND)(fst->windows_window));
- if (fst_first == fst) {
- fst_first = fst_first->next;
+ fst->windows_window = NULL;
}
+ fst->been_activated = FALSE;
}
-HMODULE
-fst_load_vst_library(const char * path)
+void
+fst_move_window_into_view (VSTState* fst)
{
- 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, ":");
+ if (fst->windows_window) {
+#ifdef PLATFORM_WINDOWS
+ 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->hoffset, fst->height + fst->voffset, 0);
+#endif
+ ShowWindow ((HWND)(fst->windows_window), SW_SHOWNA);
}
+}
- free(envdup);
-
- return dll;
+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) );
}
VSTHandle *
fst_load (const char *path)
{
- char* buf;
- VSTHandle* fhandle;
- char* period;
-
- fhandle = fst_handle_new ();
-
- // XXX: Would be nice to find the correct call for this.
- // if the user does not configure Z: to be / we are doomed :(
-
- if (strstr (path, ".dll") == NULL) {
-
- buf = (char *) malloc (strlen (path) + 7);
-
- if( path[0] == '/' ) {
- sprintf (buf, "Z:%s.dll", path);
- } else {
- sprintf (buf, "%s.dll", path);
+ VSTHandle* fhandle = NULL;
+
+ if ((strlen(path)) && (NULL != (fhandle = fst_handle_new ())))
+ {
+ char* period;
+ fhandle->path = strdup (path);
+ fhandle->name = g_path_get_basename(path);
+ if ((period = strrchr (fhandle->name, '.'))) {
+ *period = '\0';
}
- fhandle->nameptr = strdup (path);
-
- } else {
-
- buf = (char *) malloc (strlen (path) + 3);
-
- if( path[0] == '/' ) {
- sprintf (buf, "Z:%s", path);
- } else {
- sprintf (buf, "%s", path);
+ // See if we can load the plugin DLL
+ if ((fhandle->dll = (HMODULE)fst_load_vst_library (path)) == NULL) {
+ fst_unload (&fhandle);
+ return NULL;
}
- fhandle->nameptr = strdup (path);
- }
-
- fhandle->name = basename (fhandle->nameptr);
-
- /* strip off .dll */
+ fhandle->main_entry = (main_entry_t) GetProcAddress ((HMODULE)fhandle->dll, "main");
- if ((period = strrchr (fhandle->name, '.')) != NULL) {
- *period = '\0';
- }
-
- if ((fhandle->dll = fst_load_vst_library (buf)) == NULL) {
- fst_unload (fhandle);
- return NULL;
- }
+ if (fhandle->main_entry == 0) {
+ 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;
+ }
+ }
- if ((fhandle->main_entry = (main_entry_t) GetProcAddress (fhandle->dll, "main")) == NULL) {
- fst_unload (fhandle);
- return NULL;
+ if (fhandle->main_entry == 0) {
+ fst_unload (&fhandle);
+ return NULL;
+ }
}
-
return fhandle;
}
int
-fst_unload (VSTHandle* fhandle)
+fst_unload (VSTHandle** fhandle)
{
- if (fhandle->plugincnt) {
+ if (!(*fhandle)) {
return -1;
}
- if (fhandle->dll) {
- FreeLibrary (fhandle->dll);
- fhandle->dll = NULL;
+ if ((*fhandle)->plugincnt) {
+ return -1;
+ }
+
+ if ((*fhandle)->dll) {
+ FreeLibrary ((HMODULE)(*fhandle)->dll);
+ (*fhandle)->dll = NULL;
+ }
+
+ if ((*fhandle)->path) {
+ free ((*fhandle)->path);
+ (*fhandle)->path = NULL;
}
- if (fhandle->nameptr) {
- free (fhandle->nameptr);
- fhandle->name = NULL;
+ if ((*fhandle)->name) {
+ free ((*fhandle)->name);
+ (*fhandle)->name = NULL;
}
-
- free (fhandle);
+
+ free (*fhandle);
+ *fhandle = NULL;
+
return 0;
}
VSTState*
fst_instantiate (VSTHandle* fhandle, audioMasterCallback amc, void* userptr)
{
- VSTState* fst = fst_new ();
+ VSTState* fst = NULL;
- 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);
-
if( fhandle == NULL ) {
- fst_error( "the handle was NULL\n" );
- return NULL;
+ fst_error( "fst_instantiate(): (the handle was NULL)\n" );
+ return NULL;
}
+ fst = fst_new ();
+
if ((fst->plugin = fhandle->main_entry (amc)) == NULL) {
- fst_error ("%s could not be instantiated\n", fhandle->name);
+ fst_error ("fst_instantiate: %s could not be instantiated\n", fhandle->name);
free (fst);
return NULL;
}
-
+
fst->handle = fhandle;
fst->plugin->user = userptr;
-
+
if (fst->plugin->magic != kEffectMagic) {
- fst_error ("%s is not a VST plugin\n", fhandle->name);
- free (fst);
+ fst_error ("fst_instantiate: %s is not a vst plugin\n", fhandle->name);
+ fst_close(fst);
return NULL;
}
-
- fst->plugin->dispatcher (fst->plugin, effOpen, 0, 0, 0, 0);
- //fst->plugin->dispatcher (fst->plugin, effMainsChanged, 0, 0, NULL, 0);
+ fst->plugin->dispatcher (fst->plugin, effOpen, 0, 0, 0, 0);
fst->vst_version = fst->plugin->dispatcher (fst->plugin, effGetVstVersion, 0, 0, 0, 0);
-
+
fst->handle->plugincnt++;
fst->wantIdle = 0;
return fst;
}
-void
-fst_close (VSTState* fst)
-{
- fst_destroy_editor (fst);
-
- fst->plugin->dispatcher (fst->plugin, effMainsChanged, 0, 0, NULL, 0);
- fst->plugin->dispatcher (fst->plugin, effClose, 0, 0, 0, 0);
-
- if (fst->handle->plugincnt) {
- --fst->handle->plugincnt;
- }
-}
-
-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;
+void fst_audio_master_idle(void) {
+ while(g_main_context_iteration(NULL, FALSE)) ;
}
-#if 0
-int fst_load_state (FST * fst, char * filename)
+void
+fst_close (VSTState* fst)
{
- 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;
- }
+ if (fst != NULL) {
+ fst_destroy_editor (fst);
- 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;
+ 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;
}
- 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;
- }
+ if (fst->handle) {
+ if (fst->handle->plugincnt && --fst->handle->plugincnt == 0) {
- 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;
+ fst->handle->main_entry = NULL;
+ fst_unload (&fst->handle); // XXX
}
- } 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;
+ /* 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);
}
- return TRUE;
-
}
-#endif
-int
-fst_save_state (VSTState * fst, char * filename)
+#if 0 // ?? who needs this, where?
+float htonf (float v)
{
- FILE * f = fopen (filename, "wb");
- int j;
-
- if (f) {
- int bytelen;
- int numParams = fst->plugin->numParams;
- char productString[64];
- char effectName[64];
- char vendorString[64];
- int success;
-
- // 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 (j = 0; j < numParams; ++j) {
- float val;
-
- pthread_mutex_lock( &fst->lock );
- val = fst->plugin->getParameter (fst->plugin, j);
- pthread_mutex_unlock( &fst->lock );
- fprintf( f, " <param index=\"%d\" value=\"%f\"/>\n", j, 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;
+ 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;
}
-
+#endif
diff --git a/libs/fst/wscript b/libs/fst/wscript
new file mode 100644
index 0000000000..91273f3d79
--- /dev/null
+++ b/libs/fst/wscript
@@ -0,0 +1,86 @@
+#!/usr/bin/env python
+from waflib.extras import autowaf as autowaf
+from waflib import Options, TaskGen
+import waflib.Logs as Logs, waflib.Utils as Utils
+import os
+import shutil
+import sys
+import re
+import time
+from waflib.Task import Task
+
+# Mandatory variables
+top = '.'
+out = 'build'
+
+scanner_app_src = [
+ 'scanner.cc',
+ ]
+
+# needed for code used from libardour
+I18N_PACKAGE = 'ardour3'
+
+def options(opt):
+ autowaf.set_options(opt)
+
+def configure(conf):
+ conf.load('misc')
+ conf.load('compiler_cxx')
+ autowaf.configure(conf)
+ if conf.env['WINDOWS_VST_SUPPORT'] == True and Options.options.dist_target == 'mingw':
+ conf.check(compiler='cxx',
+ lib='gdi32',
+ mandatory=True,
+ uselib_store='GDI32')
+
+# Add a waf `feature' to allow compilation of things using winegcc
+from waflib.TaskGen import feature
+@feature("wine")
+def set_winegcc(self):
+ self.env.LINK_CXX = self.env.LINK_CC = 'wineg++'
+ self.env.CC = 'winegcc'
+
+def build(bld):
+ VERSION = "%s.%s" % (bld.env['MAJOR'], bld.env['MINOR'])
+ if not (bld.is_defined('WINDOWS_VST_SUPPORT') or bld.is_defined('LXVST_SUPPORT')):
+ return
+
+ if bld.is_defined('WINDOWS_VST_SUPPORT') and bld.env['build_target'] != 'mingw':
+ # wine exec wrapper script
+ obj = bld(features = 'subst', rule= 'chmod 0755 ${TGT}')
+ obj.source = 'scanner.wine'
+ obj.target = 'ardour-vst-scanner'
+ obj.chmod = Utils.O755
+ obj.install_path = os.path.join(bld.env['LIBDIR'], 'fst')
+ obj.dict = {
+ 'VERSION' : bld.env['VERSION'],
+ }
+
+ obj = bld (features = 'c cxx cxxprogram wine')
+ obj.source = (
+ 'scanner.cc',
+ 'vstwin.c',
+ )
+ obj.linkflags = ['-mwindows', '-Wl,--export-dynamic']
+ obj.target = 'ardour-vst-scanner.exe.so'
+ obj.uselib = ['GIOMM', 'DL']
+ obj.use = [ 'libpbd' ]
+ else:
+ obj = bld (features = 'cxx c cxxprogram')
+ if bld.is_defined('WINDOWS_VST_SUPPORT'):
+ obj.source = ( 'scanner.cc', 'vstwin.c' )
+ obj.uselib = ['GIOMM', 'DL', 'GDI32']
+ else:
+ obj.source = ( 'scanner.cc' )
+ obj.uselib = ['GIOMM', 'DL']
+ obj.target = 'ardour-vst-scanner'
+ obj.use = [ 'libpbd' ]
+
+ obj.includes = [ '../pbd/', '../ardour/', '.' ]
+ obj.defines = [
+ '_POSIX_SOURCE',
+ 'USE_WS_PREFIX',
+ 'VST_SCANNER_APP',
+ 'PACKAGE="' + I18N_PACKAGE + '"',
+ ]
+ obj.install_path = os.path.join(bld.env['LIBDIR'], 'fst')