Created
October 6, 2020 10:07
-
-
Save kyab/462fa787cbe780ca1b21462d680a37da to your computer and use it in GitHub Desktop.
Creating VST3 Host failed ........
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define BUNDLE_PATH @"/Library/Audio/Plug-Ins/VST3/TDR VOS SlickEQ.vst3" | |
- (IBAction)testVST:(id)sender { | |
NSBundle *bundle = [NSBundle bundleWithPath:BUNDLE_PATH]; | |
[bundle load]; | |
NSLog(@"bundle name = %@", bundle); | |
tresult res = 0; | |
{ | |
NSString *bundlePath = BUNDLE_PATH; | |
NSURL *bundleURL = [NSURL fileURLWithPath:bundlePath]; | |
CFBundleRef cfBundle = NULL; | |
cfBundle = CFBundleCreate(kCFAllocatorDefault, (CFURLRef)bundleURL); | |
BundleEntryFunc entryFunc = (BundleEntryFunc)CFBundleGetFunctionPointerForName(cfBundle,CFSTR("bundleEntry")); | |
if (!entryFunc){ | |
NSLog(@"Bundle does not export the required 'bundleEntry' function"); | |
return; | |
} | |
bool ret = entryFunc(cfBundle); | |
NSLog(@"bundleEntry return %d", ret); | |
THEAPI func = (THEAPI)CFBundleGetFunctionPointerForName(cfBundle, CFSTR("GetPluginFactory")); | |
if(!func){ | |
NSLog(@"GetPluginFactory() not found. Maybe not VST3 Plugin"); | |
return; | |
} | |
IPluginFactory *pluginFactory = func(); | |
if (!pluginFactory){ | |
NSLog(@"failed with get IPluginFactory"); | |
return; | |
} | |
NSLog(@"pluginFactory has %d classes.", pluginFactory->countClasses()); | |
int32 classNum = pluginFactory->countClasses(); | |
for (int i = 0; i < classNum; i++){ | |
PClassInfo classInfo; | |
pluginFactory->getClassInfo(i, &classInfo); | |
NSLog(@"class[%d],%s,category=%s", i, classInfo.name, classInfo.category); | |
if (0 == strncmp(classInfo.category, kVstAudioEffectClass, strlen(kVstAudioEffectClass))){ | |
FUnknown *iUnknown; | |
res = pluginFactory->createInstance(classInfo.cid, FUnknown::iid, (void **)&iUnknown); | |
if (res != kResultOk){ | |
NSLog(@"createInstance failed with %d", res); | |
continue; | |
} | |
Vst::IAudioProcessor *iAudioProcessor = NULL; | |
res = iUnknown->queryInterface(Vst::IAudioProcessor::iid, (void **)(&iAudioProcessor)); | |
if (iAudioProcessor){ | |
Vst::SpeakerArrangement sa = Vst::SpeakerArr::kStereo; | |
res = iAudioProcessor->setBusArrangements(&sa, 1, &sa, 1); | |
NSLog(@"setBusArrangements returns %d", res); | |
Vst::ProcessSetup processSetup; | |
processSetup.maxSamplesPerBlock =32; | |
processSetup.processMode = Vst::kRealtime; | |
processSetup.sampleRate = 44100; | |
processSetup.symbolicSampleSize = Vst::kSample32; | |
res = iAudioProcessor->setupProcessing(processSetup); | |
NSLog(@"setupProcessing returns %d", res); | |
// g_audioProcessor = iAudioProcessor; | |
}else{ | |
NSLog(@"failed for queryInterface IAudioProcessor"); | |
} | |
}else if (0 == strncmp(classInfo.category, kVstComponentControllerClass, strlen(kVstComponentControllerClass))){ | |
FUnknown *iUnknown = NULL; | |
res = pluginFactory->createInstance(classInfo.cid, FUnknown::iid, (void **)&iUnknown); | |
if (iUnknown){ | |
Vst::IEditController *editController = NULL; | |
res = iUnknown->queryInterface(Vst::IEditController::iid, (void **)&editController); | |
if (editController){ | |
[self IEditorControllerObtained:editController]; | |
} | |
} | |
} | |
} | |
} | |
} | |
-(void)IEditorControllerObtained:(Vst::IEditController *)editorController{ | |
tresult res = 0; | |
res = editorController->initialize(&hostApplication); | |
res = editorController->setComponentHandler(&componentHandler); | |
if(res != kResultOk){ | |
NSLog(@" failed with setComponentHandler"); | |
return; | |
}else{ | |
NSLog(@" OK to setComponentHandler"); | |
} | |
int32 c = editorController->getParameterCount(); | |
NSLog(@" has %d parameters",c); | |
for (int i=0; i < c; i++){ | |
Vst::ParameterInfo paramInfo = Vst::ParameterInfo(); | |
res = editorController->getParameterInfo(i, paramInfo); | |
NSString *title = [[NSString alloc] initWithCharacters:(const unichar *)paramInfo.title length:128]; | |
NSString *units = [[NSString alloc] initWithCharacters:(const unichar *)paramInfo.units length:128]; | |
Vst::ParamID paramId = paramInfo.id; | |
Vst::ParamValue defNormalizedValue = paramInfo.defaultNormalizedValue; | |
NSLog(@" parameter[%d]:%@(%d)=%f%@", i, title, paramId,defNormalizedValue,units); | |
} | |
IPlugView *view = editorController->createView("editor"); | |
NSLog(@" view = %p", view); | |
if(view){ | |
res = view->isPlatformTypeSupported(kPlatformTypeNSView); | |
NSLog(@" isPlatformTypeSupported(NSView) res = %d", res); | |
res = view->attached((__bridge void *)_pluginEditorSuperView, kPlatformTypeNSView); | |
NSLog(@" attached res = %d",res); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
どーしてもgetParameterCount()で0が返る。。