Exemplo n.º 1
0
INT_PTR CALLBACK EditorProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	
	AEffect* effect;
	switch(msg)
	{
	case WM_INITDIALOG :
		{
			SetWindowLongPtr(hwnd,GWLP_USERDATA,lParam);
			effect = (AEffect*)lParam;
			SetWindowText (hwnd, L"VST Editor");
			SetTimer (hwnd, 1, 20, 0);
			if(effect)
			{
				effect->dispatcher (effect, effEditOpen, 0, 0, hwnd, 0);
				ERect* eRect = 0;
				effect->dispatcher (effect, effEditGetRect, 0, 0, &eRect, 0);
				if(eRect)
				{
					int width = eRect->right - eRect->left;
					int height = eRect->bottom - eRect->top;
					if(width < 50)
						width = 50;
					if(height < 50)
						height = 50;
					RECT wRect;
					SetRect (&wRect, 0, 0, width, height);
					AdjustWindowRectEx (&wRect, GetWindowLong (hwnd, GWL_STYLE), FALSE, GetWindowLong (hwnd, GWL_EXSTYLE));
					width = wRect.right - wRect.left;
					height = wRect.bottom - wRect.top;
					SetWindowPos (hwnd, HWND_TOP, 0, 0, width, height, SWP_NOMOVE);
				}
			}
		}
		break;
	case WM_TIMER :
		effect = (AEffect*)GetWindowLongPtr(hwnd,GWLP_USERDATA);
		if(effect)
			effect->dispatcher (effect, effEditIdle, 0, 0, 0, 0);
		break;
	case WM_CLOSE :
		{
			effect = (AEffect*)GetWindowLongPtr(hwnd,GWLP_USERDATA);
			KillTimer (hwnd, 1);
			if(effect)
			{
				effect->dispatcher (effect, effEditClose, 0, 0, 0, 0);
			}

			EndDialog (hwnd, IDOK);
		}
		break;
	}

	return 0;
}
Exemplo n.º 2
0
//-------------------------------------------------------------------------------------------------------
int main (int argc, char* argv[])
{
	if (!checkPlatform ())
	{
		printf ("Platform verification failed! Please check your Compiler Settings!\n");
		return -1;
	}

	const char* fileName = "again.dll";
	//const char* fileName = "adelay.dll";
	//const char* fileName = "surrounddelay.dll";
	//const char* fileName = "vstxsynth.dll";
	//const char* fileName = "drawtest.dll";

	if (argc > 1)
		fileName = argv[1];

	printf ("HOST> Load library...\n");
	PluginLoader loader;
	if (!loader.loadLibrary (fileName))
	{
		printf ("Failed to load VST Plugin library!\n");
		return -1;
	}

	PluginEntryProc mainEntry = loader.getMainEntry ();
	if (!mainEntry)
	{
		printf ("VST Plugin main entry not found!\n");
		return -1;
	}

	printf ("HOST> Create effect...\n");
	AEffect* effect = mainEntry (HostCallback);
	if (!effect)
	{
		printf ("Failed to create effect instance!\n");
		return -1;
	}

	printf ("HOST> Init sequence...\n");
	effect->dispatcher (effect, effOpen, 0, 0, 0, 0);
	effect->dispatcher (effect, effSetSampleRate, 0, 0, 0, kSampleRate);
	effect->dispatcher (effect, effSetBlockSize, 0, kBlockSize, 0, 0);

	checkEffectProperties (effect);
	checkEffectProcessing (effect);
	checkEffectEditor (effect);

	printf ("HOST> Close effect...\n");
	effect->dispatcher (effect, effClose, 0, 0, 0, 0);
	return 0;
}
Exemplo n.º 3
0
static int fst_can_midi( FST *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;

}
Exemplo n.º 4
0
static FSTInfo *fst_info_from_plugin( FST *fst ) {
    FSTInfo *info = (FSTInfo *) malloc( sizeof( FSTInfo ) );
    AEffect *plugin;
    int i;

    if( ! fst ) {
	fst_error( "fst is NULL\n" );
	return NULL;
    }

    if( ! info ) return NULL;
    
    plugin = fst->plugin;
    

    info->name = strdup(fst->handle->name ); 
    info->UniqueID = 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);
		
		plugin->dispatcher (plugin,
				    effGetParamLabel,
				    i, 0, label, 0);

	info->ParamNames[i] = strdup( name );
	info->ParamLabels[i] = strdup( label );
    }
    return info;
}
Exemplo n.º 5
0
static void set_plugin_type_data(AudioPluginInstance *audio_instance, SoundPluginType *plugin_type){
  TypeData *type_data = (struct TypeData*)plugin_type->data;

  if (audio_instance->hasEditor()==false) {
    plugin_type->show_gui = NULL;
    plugin_type->hide_gui = NULL;
  }
  
  plugin_type->num_inputs = audio_instance->getNumInputChannels();
  plugin_type->num_outputs = audio_instance->getNumOutputChannels();
    
  plugin_type->plugin_takes_care_of_savable_values = true;

  const char *wrapper_info = "";
  
  if (type_data->wrapper_type == AudioProcessor::wrapperType_VST) {
    AEffect *aeffect = (AEffect*)audio_instance->getPlatformSpecificData();
    {
      char vendor[1024] = {0};
      aeffect->dispatcher(aeffect, effGetVendorString, 0, 0, vendor, 0.0f);
      char product[1024] = {0};
      aeffect->dispatcher(aeffect, effGetProductString, 0, 0, product, 0.0f);

      if(strlen(vendor)>0 || strlen(product)>0)
        wrapper_info = talloc_format("Vendor: %s\nProduct: %s\n",vendor,product);
    }
  }

  plugin_type->info = strdup(talloc_format("%sAccepts MIDI: %s\nProduces MIDI: %s\n",wrapper_info, audio_instance->acceptsMidi()?"Yes":"No", audio_instance->producesMidi()?"Yes":"No"));
        
  plugin_type->is_instrument = audio_instance->acceptsMidi(); // doesn't seem like this field ("is_instrument") is ever read...

  plugin_type->num_effects = audio_instance->getNumParameters();

  type_data->effect_names = (const char**)calloc(sizeof(char*),plugin_type->num_effects);
  for(int i = 0 ; i < plugin_type->num_effects ; i++)
    type_data->effect_names[i] = strdup(audio_instance->getParameterName(i).toRawUTF8());
}
Exemplo n.º 6
0
void* VstSynth::instantiate()
      {
      ++_instances;
      QString n;
      n.setNum(_instances);
      QString instanceName = baseName() + "-" + n;
      doSetuid();
      QByteArray ba = info.filePath().toLatin1();
      const char* path = ba.constData();

      fstHandle = fst_load(path);
      if (fstHandle == 0) {
            printf("Synth::instantiate: cannot load vst plugin %s\n", path);
            undoSetuid();
            return 0;
            }
      FST* fst = fst_instantiate(fstHandle, vstHostCallback, 0);
      if (fst == 0) {
            printf("Synth::instantiate:: cannot instantiate plugin %s\n", path);
            undoSetuid();
            return 0;
            }
      AEffect* plugin = fst->plugin;
      plugin->dispatcher (plugin, effMainsChanged, 0, 1, 0, 0.0f);

      /* set program to zero */

      plugin->dispatcher (plugin, effSetProgram, 0, 0, NULL, 0.0f);

      if (fst_run_editor(fst)) {
            printf("Synth::instantiate: cannot create gui");
            undoSetuid();
            return 0;
            }

      undoSetuid();
      return fst;
      }
Exemplo n.º 7
0
bool VstSynthIF::putEvent(const MidiPlayEvent& ev)
      {
      if (midiOutputTrace)
            ev.dump();
      AEffect* plugin = _fst->plugin;
      static struct VstEvents events;
      static struct VstMidiEvent event;
      events.numEvents = 1;
      events.reserved  = 0;
      events.events[0] = (VstEvent*)(&event);

      event.type         = kVstMidiType;
      event.byteSize     = 24;
      event.deltaFrames  = 0;
      event.flags        = 0;
      event.detune       = 0;
      event.noteLength   = 0;
      event.noteOffset   = 0;
      event.reserved1    = 0;
      event.reserved2    = 0;
      event.noteOffVelocity = 0;
      switch (ev.type()) {
            case ME_PITCHBEND:
                  {
                  int a = ev.dataA() + 8192;
                  int b = a >> 7;
                  event.midiData[0]  = (ev.type() | ev.channel()) & 0xff;
                  event.midiData[1]  = a & 0x7f;
                  event.midiData[2]  = b & 0x7f;
                  event.midiData[3]  = 0;
                  }
                  break;

            case ME_CONTROLLER:
            case ME_NOTEON:
            default:
                  event.midiData[0]  = (ev.type() | ev.channel()) & 0xff;
                  event.midiData[1]  = ev.dataA() & 0xff;
                  event.midiData[2]  = ev.dataB() & 0xff;
                  event.midiData[3]  = 0;
                  break;
            }
      int rv = plugin->dispatcher(plugin, effProcessEvents, 0, 0, &events, 0.0f);
      return false;
      }
Exemplo n.º 8
0
void CVST2KSPIModule::DoScanDirectory(const std::string& sPathName)
{
	// Scan the system for plug-ins
	CAutoDelete<IFileSearch> pFileSearch(IFileSearch::Create());
	pFileSearch->Init(sPathName.c_str());
	
	tchar pszName[256];
	tbool bDirectory;
	while (pFileSearch->GetNext(pszName, bDirectory)) {
		std::string sPlugInPath = sPathName;

		std::string sName(pszName);

#ifdef WIN32
		if (bDirectory) {
#else	// WIN32
		std::string sEnding = sName.substr(sName.size() - 4);
		if (sEnding != ".vst" && sEnding != ".VST" && sName.size() > 4) {
#endif	
			sPlugInPath += sName;
			sPlugInPath += ":";
			DoScanDirectory(sPlugInPath);
			continue;
		}

		std::string sPathName = sPlugInPath + sName;

#ifdef WIN32
		// Load the plug-in to get info
		{
			HMODULE hDLL;

			std::string sEnding = sName.substr(sName.size() - 4);
			if (sEnding != ".dll" && sEnding != ".DLL" && sEnding != ".Dll" && sName.size() > 4) {
				continue;
			}

			// Load plug-in
			std::string s2 = sPathName;
			ModifyPathName(s2);
			hDLL = LoadLibrary(s2.c_str());
			if (hDLL == NULL) {
				continue;
			}
			
			VSTMainFunc mainFunc = (VSTMainFunc)(void*)GetProcAddress(hDLL, "VSTPluginMain");
			//			VSTMainFunc mainFunc = (VSTMainFunc)CFBundleGetFunctionPointerForName(BundleRef, CFSTR("main") );
			if (mainFunc == NULL) {
				continue;
			}
			
			AEffect* pEffect = NULL;
			try {
				pEffect = mainFunc(audioMasterCallbackModule);
				// Note: Call setSampleRate and setBlockSize also (part of initialization sequence).
				pEffect->dispatcher(pEffect, effOpen, 0, 0, 0, 0.0);
				
				// We don't really need the name now, but we want to just try something to see if it crashes. Would be better to get some info about VST version and required host VST version.
				char pszProductName[1042];
				pEffect->dispatcher(pEffect, effGetEffectName, 0, 0, pszProductName, 0.0);
			}
			catch(...) {
				// Plug-in crashed
				//				CFBundleUnloadExecutable(BundleRef);
				//				CFRelease(BundleRef);
				continue;
			}
			
			// Effect appears ok, put it in list
			msEffectPathNames.push_back(sPathName);
			
			// Unload it
			pEffect->dispatcher(pEffect, effClose, 0, 0, 0, 0.0);
			//			CFBundleUnloadExecutable(BundleRef);
			//			CFRelease(BundleRef);
		}
#else	// WIN32
		// Load the plug-in to get info
		{
			CFBundleRef BundleRef;
			
			// Make a CFURLRef from the CFString representation of the bundle's path.
			tchar pszPathName[1024];
			strcpy(pszPathName, sPathName.c_str());
			ToUnix(pszPathName);
			CFURLRef bundleURL = CFURLCreateWithFileSystemPath( 
															   kCFAllocatorDefault, 
															   __CFStringMakeConstantString(pszPathName),
															   kCFURLPOSIXPathStyle,
															   true );
			if ( !bundleURL ) continue;
			
			// Make a bundle instance using the URLRef.
			BundleRef = CFBundleCreate( kCFAllocatorDefault, bundleURL );
			
			// We don't need the URL anymore
			CFRelease( bundleURL );	
			
			if ( !BundleRef ) {
				continue;
			}
			
			if ( !CFBundleLoadExecutable( BundleRef ) )
			{
				CFRelease( BundleRef );
				BundleRef = NULL;
				continue;
			}
			
			VSTMainFunc mainFunc = (VSTMainFunc)CFBundleGetFunctionPointerForName(BundleRef, CFSTR("VSTPluginMain") );
			//			VSTMainFunc mainFunc = (VSTMainFunc)CFBundleGetFunctionPointerForName(BundleRef, CFSTR("main") );
			if (mainFunc == NULL) {
				continue;
			}
			
			AEffect* pEffect = NULL;
			try {
				pEffect = mainFunc(audioMasterCallbackModule);
				// Note: Call setSampleRate and setBlockSize also (part of initialization sequence).
				pEffect->dispatcher(pEffect, effOpen, 0, 0, 0, 0.0);
				
				// We don't really need the name now, but we want to just try something to see if it crashes. Would be better to get some info about VST version and required host VST version.
				char pszProductName[1042];
				pEffect->dispatcher(pEffect, effGetEffectName, 0, 0, pszProductName, 0.0);
			}
			catch(...) {
				// Plug-in crashed
				//				CFBundleUnloadExecutable(BundleRef);
				//				CFRelease(BundleRef);
				continue;
			}
			
			// Effect appears ok, put it in list
			msEffectPathNames.push_back(sPathName);
			
			// Unload it
			pEffect->dispatcher(pEffect, effClose, 0, 0, 0, 0.0);
			//			CFBundleUnloadExecutable(BundleRef);
			//			CFRelease(BundleRef);
		}
#endif	// WIN32 / else
	}
}

void CVST2KSPIModule::Init()
{
/*	short sVolRef;
	long lDirID;
	tchar pszPlugInPath[1024];
	::FindFolder(kOnSystemDisk, kVolumeRootFolderType, kDontCreateFolder, &sVolRef, &lDirID);
	PathNameFromDirID(lDirID, sVolRef, (char*)pszPlugInPath);
	std::string sPlugInPath(pszPlugInPath);
	sPlugInPath += std::string("Library:Audio:Plug-Ins:VST:");*/
	// Note: This is hardcoded, and needs to change
#ifdef WIN32
	std::string sPlugInPath(":C:VSTPlugIns:");
	DoScanDirectory(sPlugInPath);
#else	// WIN32
//	std::string sPlugInPath(":Macintosh HD:Library:Audio:Plug-Ins:VST:");
	tchar pszPath[1024];
	IFile::GetSystemDirectory(IFile::SystemDirLibrary, pszPath);
	strcat(pszPath, "Audio:Plug-Ins:VST:");
	std::string sPlugInPath(pszPath);
	DoScanDirectory(sPlugInPath);

	IFile::GetSystemDirectory(IFile::SystemDirUser, pszPath);
	strcat(pszPath, "Library:Audio:Plug-Ins:VST:");
	sPlugInPath = std::string(pszPath);
	DoScanDirectory(sPlugInPath);
#endif	// WIN32 / else
}
Exemplo n.º 9
0
//-------------------------------------------------------------------------------------------------------
pascal void idleTimerProc (EventLoopTimerRef inTimer, void *inUserData)
{
	AEffect* effect = (AEffect*)inUserData;
	effect->dispatcher (effect, effEditIdle, 0, 0, 0, 0);
}
Exemplo n.º 10
0
//-------------------------------------------------------------------------------------------------------
INT_PTR CALLBACK EditorProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	AEffect* effect = theEffect;

	switch(msg)
	{
		//-----------------------
		case WM_INITDIALOG :
		{
			SetWindowText (hwnd, "VST Editor");
			SetTimer (hwnd, 1, 20, 0);

			if (effect)
			{
				printf ("HOST> Open editor...\n");
				effect->dispatcher (effect, effEditOpen, 0, 0, hwnd, 0);

				printf ("HOST> Get editor rect..\n");
				ERect* eRect = 0;
				effect->dispatcher (effect, effEditGetRect, 0, 0, &eRect, 0);
				if (eRect)
				{
					int width = eRect->right - eRect->left;
					int height = eRect->bottom - eRect->top;
					if (width < 100)
						width = 100;
					if (height < 100)
						height = 100;

					RECT wRect;
					SetRect (&wRect, 0, 0, width, height);
					AdjustWindowRectEx (&wRect, GetWindowLong (hwnd, GWL_STYLE), FALSE, GetWindowLong (hwnd, GWL_EXSTYLE));
					width = wRect.right - wRect.left;
					height = wRect.bottom - wRect.top;

					SetWindowPos (hwnd, HWND_TOP, 0, 0, width, height, SWP_NOMOVE);
				}
			}
		}	break;

		//-----------------------
		case WM_TIMER :
			if (effect)
				effect->dispatcher (effect, effEditIdle, 0, 0, 0, 0);
			break;

		//-----------------------
		case WM_CLOSE :
		{
			KillTimer (hwnd, 1);

			printf ("HOST> Close editor..\n");
			if (effect)
				effect->dispatcher (effect, effEditClose, 0, 0, 0, 0);

			EndDialog (hwnd, IDOK);
		}	break;
	}

	return 0;
}
Exemplo n.º 11
0
//
//  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  PURPOSE:  Processes messages for the main window.
//
//  WM_PAINT    - Paint the main window
//  WM_DESTROY  - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    PAINTSTRUCT ps;
    HDC hdc;

    switch (message)
    {
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
	//-----------------------
	case WM_CREATE :
	{
		SetWindowText (hWnd, "VST Editor");

		CREATESTRUCT* createStruct = (CREATESTRUCT*)lParam;
		Plugin* plugin = static_cast<Plugin*>(createStruct->lpCreateParams);
		AEffect* effect = plugin->GetVstEffect();

		if (effect)
		{
			windowPluginMap[hWnd] = plugin;

			printf ("HOST> Open editor...\n");
			effect->dispatcher (effect, effEditOpen, 0, 0, hWnd, 0);

			printf ("HOST> Get editor rect..\n");
			ERect* eRect = 0;
			effect->dispatcher (effect, effEditGetRect, 0, 0, &eRect, 0);
			if (eRect)
			{
				int width = eRect->right - eRect->left;
				int height = eRect->bottom - eRect->top;
				if (width < 100)
					width = 100;
				if (height < 100)
					height = 100;

				RECT wRect;
				SetRect (&wRect, 0, 0, width, height);
				AdjustWindowRectEx (&wRect, GetWindowLong (hWnd, GWL_STYLE), FALSE, GetWindowLong (hWnd, GWL_EXSTYLE));
				width = wRect.right - wRect.left;
				height = wRect.bottom - wRect.top;

				SetWindowPos (hWnd, HWND_TOP, 0, 0, width, height, SWP_NOMOVE);
			}
		}
	}	break;

	//-----------------------
	/*case WM_TIMER :
		if (effect)
			effect->dispatcher (effect, effEditIdle, 0, 0, 0, 0);
		break;*/

	//-----------------------
	case WM_CLOSE :
	{
		Plugin* plugin = windowPluginMap[hWnd];
		AEffect* effect = plugin->GetVstEffect();

		printf ("HOST> Close editor..\n");
		if (effect)
			effect->dispatcher (effect, effEditClose, 0, 0, 0, 0);

		DestroyWindow(hWnd);
	}	break;
    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
        break;
    }

    return 0;
}
Exemplo n.º 12
0
int jack_initialize (jack_client_t *client, const char *string){
  struct Data *data;
  AEffect *effect;
  snd_seq_t *seq;

  int lokke;

  char pluginname[500];
  char *seqname;

  bool dontconnectjackports=false;

  sprintf(pluginname,"%s",string);
  seqname=&pluginname[0];

  if(strstr(string,":")){
    seqname=strstr(pluginname,":")+1;
    strstr(pluginname,":")[0]=0;
    if(strstr(seqname,":")){
      strstr(seqname,":")[0]=0;
      dontconnectjackports=true;
    }
  }
  
  printf("plugname: %s, seqname: %s, dontconnect: %s\n",pluginname,seqname,dontconnectjackports==true?"true":"false");
     
  //printf("rate: %f, blocksize: %d\n",(float)jack_get_sample_rate(client),jack_get_buffer_size(client));
  
  /*****************************
       VST Init
  *****************************/

  effect=VSTLIB_new(pluginname);
  if(effect==NULL) return 1;

  effect->dispatcher (effect,
		      effOpen,
		      0, 0, NULL, 0);

  effect->dispatcher(
		     effect,
		     effSetSampleRate,
		     0,0,NULL,(float)jack_get_sample_rate(client));

  effect->dispatcher(effect,
		     effSetBlockSize,
		     0, jack_get_buffer_size(client), NULL, 0);

  effect->dispatcher(effect,
		     effMainsChanged,
		     0, 1, NULL, 0);

  effect->dispatcher (effect,
		      effEditOpen,
		      0, 0, NULL, 0);
  

  /*****************************
       MIDI init
  *****************************/

  seq=create_alsa_seq(seqname,true);
  if(seq==NULL){
    VSTLIB_delete(effect);
    return 2;
  }

  data=calloc(1,sizeof(struct Data));
  data->seq=seq;
  data->client=client;
  data->effect=effect;
  data->toquit=false;

  pthread_create(&data->midithread,NULL,midireceiver,data);
  {
    struct sched_param rt_param={0};
    int err;
    rt_param.sched_priority = 1; // This is not an important thread.
    err=pthread_setschedparam(data->midithread,SCHED_FIFO, &rt_param);
    if(err){
      fprintf(stderr,"Could not set realtime priority for midi thread.\n");
    }
  }


  /*****************************
       Jack init
  *****************************/

  jack_set_process_callback(client,process,data);
  jack_set_buffer_size_callback(client,buffersizecallback,data);

  data->num_inputs=data->effect->numInputs;
  data->num_outputs=data->effect->numOutputs;

  data->input_ports=calloc(sizeof(jack_port_t*),data->num_inputs);
  data->output_ports=calloc(sizeof(jack_port_t*),data->num_outputs);

  for(lokke=0;lokke<data->num_inputs;lokke++){
    char temp[500];
    sprintf(temp,"in%d",lokke);
    data->input_ports[lokke]=jack_port_register(client,temp, JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0);
  }
  for(lokke=0;lokke<data->num_outputs;lokke++){
    char temp[500];
    sprintf(temp,"out%d",lokke);
    data->output_ports[lokke]=jack_port_register(client,temp, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
  }

  
  jack_activate (client);


  if(dontconnectjackports==false){
    for(lokke=0;lokke<data->num_inputs;lokke++){
      char temp[500];
      sprintf(temp,"alsa_pcm:capture_%d",lokke+1);
      jack_connect(client,temp,jack_port_name(data->input_ports[lokke]));
    }
    for(lokke=0;lokke<data->num_outputs;lokke++){
      char temp[500];
      sprintf(temp,"alsa_pcm:playback_%d",lokke+1);
      jack_connect(client,jack_port_name(data->output_ports[lokke]),temp);
    }
  }


  return 0;
}
Exemplo n.º 13
0
static void loadPluginLib(QFileInfo* fi, const PluginType t)
{
    if (debugMsg)
        qWarning("looking up %s", fi->filePath().toAscii().constData());

    void* handle = lib_open(fi->filePath().toAscii().constData());
	if (handle == 0)
	{
		fprintf(stderr, "dlopen(%s) failed: %s\n",
				fi->filePath().toAscii().constData(), dlerror());
		return;
	}

    if (t == PLUGIN_LADSPA)
	{
        LADSPA_Descriptor_Function ladspa = (LADSPA_Descriptor_Function) lib_symbol(handle, "ladspa_descriptor");
		if (!ladspa)
		{
			const char *txt = dlerror();
			if (txt)
			{
				fprintf(stderr,
						"Unable to find ladspa_descriptor() function in plugin "
						"library file \"%s\": %s.\n"
						"Are you sure this is a LADSPA plugin file?\n",
						fi->filePath().toAscii().constData(),
						txt);
			}
            lib_close(handle);
			return;
		}

		const LADSPA_Descriptor* descr;
		for (int i = 0;; ++i)
		{
			descr = ladspa(i);
			if (descr == NULL)
				break;

			// Make sure it doesn't already exist.
			if (plugins.find(fi->completeBaseName(), QString(descr->Label)) != 0)
				continue;

#ifdef PLUGIN_DEBUGIN
			fprintf(stderr, "loadPluginLib: ladspa effect name:%s inPlaceBroken:%d\n", descr->Name, LADSPA_IS_INPLACE_BROKEN(descr->Properties));
#endif
            plugins.add(PLUGIN_LADSPA, fi->absoluteFilePath(), QString(descr->Label), descr);
		}
	}
    else if (t == PLUGIN_VST)
    {
        VST_Function vstfn = (VST_Function) lib_symbol(handle, "VSTPluginMain");

        if (! vstfn)
        {
            vstfn = (VST_Function) lib_symbol(handle, "main");

    #ifdef TARGET_API_MAC_CARBON
            if (! vstfn)
                vstfn = (VST_Function)lib_symbol(lib_handle, "main_macho");
    #endif
        }

        if (! vstfn)
        {
            const char *txt = dlerror();
            if (txt)
            {
                fprintf(stderr,
                        "Unable to find vst entry function in plugin "
                        "library file \"%s\": %s.\n"
                        "Are you sure this is a VST plugin file?\n",
                        fi->filePath().toAscii().constData(),
                        txt);
            }
            lib_close(handle);
            return;
        }

        AEffect* effect = vstfn(VstHostCallback);

        if (effect && (effect->flags & effFlagsCanReplacing) > 0)
        {
            QString PluginLabel = fi->baseName();

            char buf_str[255] = { 0 };
            effect->dispatcher(effect, effOpen, 0, 0, 0, 0.0f);
            effect->dispatcher(effect, effGetProductString, 0, 0, buf_str, 0.0f);

            if (buf_str[0] != 0)
                PluginLabel = QString(buf_str);

            // Make sure it doesn't already exist.
            if (plugins.find(fi->completeBaseName(), QString(PluginLabel)) == 0)
            {
                plugins.add(PLUGIN_VST, fi->absoluteFilePath(), PluginLabel, effect);
            }

            effect->dispatcher(effect, effClose, 0, 0, 0, 0.0f);
        }
    }

    lib_close(handle);
}
Exemplo n.º 14
0
// Add a plugin to the list of known plugins.
VSTPluginLib *CVstPluginManager::AddPlugin(const mpt::PathString &dllPath, bool fromCache, const bool checkFileExistence, std::wstring *const errStr)
//---------------------------------------------------------------------------------------------------------------------------------------------------
{
	const mpt::PathString fileName = dllPath.GetFileName();

	if(checkFileExistence && (PathFileExistsW(dllPath.AsNative().c_str()) == FALSE))
	{
		if(errStr)
		{
			*errStr += L"\nUnable to find ";
			*errStr += dllPath.ToWide();
		}
	}

	// Check if this is already a known plugin.
	for(const_iterator dupePlug = begin(); dupePlug != end(); dupePlug++)
	{
		if(!dllPath.CompareNoCase(dllPath, (**dupePlug).dllPath)) return *dupePlug;
	}

	// Look if the plugin info is stored in the PluginCache
	if(fromCache)
	{
		SettingsContainer & cacheFile = theApp.GetPluginCache();
		const std::string IDs = cacheFile.Read<std::string>(cacheSectionW, fileName.ToWide(), "");

		if(IDs.length() >= 16)
		{
			// Get path from cache file
			mpt::PathString realPath = cacheFile.Read<mpt::PathString>(cacheSection, IDs, MPT_PATHSTRING(""));
			realPath = theApp.RelativePathToAbsolute(realPath);

			if(!realPath.empty() && !dllPath.CompareNoCase(realPath, dllPath))
			{
				VSTPluginLib *plug = new (std::nothrow) VSTPluginLib(dllPath, fileName);
				if(plug == nullptr)
				{
					return nullptr;
				}
				pluginList.push_back(plug);

				// Extract plugin IDs
				for (int i = 0; i < 16; i++)
				{
					VstInt32 n = IDs[i] - '0';
					if (n > 9) n = IDs[i] + 10 - 'A';
					n &= 0x0f;
					if (i < 8)
					{
						plug->pluginId1 = (plug->pluginId1 << 4) | n;
					} else
					{
						plug->pluginId2 = (plug->pluginId2 << 4) | n;
					}
				}

				const std::string flagKey = IDs + ".Flags";
				plug->DecodeCacheFlags(cacheFile.Read<int32>(cacheSection, flagKey, 0));

#ifdef VST_LOG
				Log("Plugin \"%s\" found in PluginCache\n", plug->libraryName.ToLocale().c_str());
#endif // VST_LOG
				return plug;
			} else
			{
#ifdef VST_LOG
				Log("Plugin \"%s\" mismatch in PluginCache: \"%s\" [%s]=\"%s\"\n", s, dllPath, (LPCTSTR)IDs, (LPCTSTR)strFullPath);
#endif // VST_LOG
			}
		}
	}

	// If this key contains a file name on program launch, a plugin previously crashed OpenMPT.
	theApp.GetSettings().Write<mpt::PathString>("VST Plugins", "FailedPlugin", dllPath);

	AEffect *pEffect;
	HINSTANCE hLib;
	bool validPlug = false;

	VSTPluginLib *plug = new (std::nothrow) VSTPluginLib(dllPath, fileName);
	if(plug == nullptr)
	{
		return nullptr;
	}

	try
	{
		pEffect = LoadPlugin(dllPath, hLib);

		if(pEffect != nullptr && pEffect->magic == kEffectMagic && pEffect->dispatcher != nullptr)
		{
			pEffect->dispatcher(pEffect, effOpen, 0, 0, 0, 0);

			plug->pluginId1 = pEffect->magic;
			plug->pluginId2 = pEffect->uniqueID;

			GetPluginInformation(pEffect, *plug);

#ifdef VST_LOG
			int nver = pEffect->dispatcher(pEffect, effGetVstVersion, 0,0, nullptr, 0);
			if (!nver) nver = pEffect->version;
			Log("%-20s: v%d.0, %d in, %d out, %2d programs, %2d params, flags=0x%04X realQ=%d offQ=%d\n",
				plug->libraryName.ToLocale().c_str(), nver,
				pEffect->numInputs, pEffect->numOutputs,
				pEffect->numPrograms, pEffect->numParams,
				pEffect->flags, pEffect->realQualities, pEffect->offQualities);
#endif // VST_LOG

			pEffect->dispatcher(pEffect, effClose, 0, 0, 0, 0);

			validPlug = true;
		}

		FreeLibrary(hLib);
	} catch(...)
	{
		CVstPluginManager::ReportPlugException(mpt::String::PrintW(L"Exception while trying to load plugin \"%1\"!\n", plug->libraryName));
	}

	// Now it should be safe to assume that this plugin loaded properly. :)
	theApp.GetSettings().Remove("VST Plugins", "FailedPlugin");

	// If OK, write the information in PluginCache
	if(validPlug)
	{
		pluginList.push_back(plug);
		WriteToCache(*plug);
	} else
	{
		delete plug;
	}

	return (validPlug ? plug : nullptr);
}