diff options
author | Robin Gareus <robin@gareus.org> | 2014-02-23 05:51:58 +0100 |
---|---|---|
committer | Robin Gareus <robin@gareus.org> | 2014-02-23 05:51:58 +0100 |
commit | bcf6c764625ab4b98e486977ef477deb4f1d64c4 (patch) | |
tree | 8a87224ccaa169e9065544e8ab0529fb0722f101 /libs/fst | |
parent | 7f714ca0366acccd1c9e6d3cc67c5573e4ea1d43 (diff) |
consolidate lxVST & winVST file-info code into libardour
first step and clennup before adding support for
VST shell-plugins (collections) and external scanner app...
Diffstat (limited to 'libs/fst')
-rw-r--r-- | libs/fst/fst.h | 2 | ||||
-rw-r--r-- | libs/fst/fstinfofile.c | 287 | ||||
-rw-r--r-- | libs/fst/jackvst.h | 43 | ||||
-rw-r--r-- | libs/fst/vsti.c | 192 | ||||
-rw-r--r-- | libs/fst/vstwin.c | 2 |
5 files changed, 1 insertions, 525 deletions
diff --git a/libs/fst/fst.h b/libs/fst/fst.h index 10ccda4d41..ba7fb42c0f 100644 --- a/libs/fst/fst.h +++ b/libs/fst/fst.h @@ -45,8 +45,6 @@ extern int fst_run_editor (VSTState *, void* window_parent); 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 void fst_start_threading(void); extern void fst_stop_threading(void); diff --git a/libs/fst/fstinfofile.c b/libs/fst/fstinfofile.c deleted file mode 100644 index acfefbe324..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/vsti.c b/libs/fst/vsti.c deleted file mode 100644 index a1a9a8be72..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 58ce0fd235..d37c5dffbb 100644 --- a/libs/fst/vstwin.c +++ b/libs/fst/vstwin.c @@ -608,7 +608,7 @@ fst_close (VSTState* fst) if (fst->handle->plugincnt && --fst->handle->plugincnt == 0) { fst->handle->main_entry = NULL; - fst_unload (&fst->handle); + fst_unload (&fst->handle); // XXX } } |