VSTPlugin-osx.mm 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*****************************************************************************
  2. Copyright (C) 2016-2017 by Colin Edwards.
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. *****************************************************************************/
  14. #include "../headers/VSTPlugin.h"
  15. AEffect *VSTPlugin::loadEffect()
  16. {
  17. AEffect *newEffect = NULL;
  18. // Create a path to the bundle
  19. CFStringRef pluginPathStringRef = CFStringCreateWithCString(NULL, pluginPath.c_str(), kCFStringEncodingUTF8);
  20. CFURLRef bundleUrl =
  21. CFURLCreateWithFileSystemPath(kCFAllocatorDefault, pluginPathStringRef, kCFURLPOSIXPathStyle, true);
  22. if (bundleUrl == NULL) {
  23. CFRelease(pluginPathStringRef);
  24. blog(LOG_WARNING, "Couldn't make URL reference for VST plug-in");
  25. return NULL;
  26. }
  27. // Open the bundle
  28. bundle = CFBundleCreate(kCFAllocatorDefault, bundleUrl);
  29. if (bundle == NULL) {
  30. blog(LOG_WARNING, "Couldn't create VST bundle reference.");
  31. CFRelease(pluginPathStringRef);
  32. CFRelease(bundleUrl);
  33. return NULL;
  34. }
  35. vstPluginMain mainEntryPoint = NULL;
  36. mainEntryPoint = (vstPluginMain) CFBundleGetFunctionPointerForName(bundle, CFSTR("VSTPluginMain"));
  37. // VST plugins previous to the 2.4 SDK used main_macho for the
  38. // entry point name.
  39. if (mainEntryPoint == NULL) {
  40. mainEntryPoint = (vstPluginMain) CFBundleGetFunctionPointerForName(bundle, CFSTR("main_macho"));
  41. }
  42. if (mainEntryPoint == NULL) {
  43. blog(LOG_WARNING, "Couldn't get a pointer to plug-in's main()");
  44. CFRelease(pluginPathStringRef);
  45. CFRelease(bundleUrl);
  46. CFRelease(bundle);
  47. bundle = NULL;
  48. return NULL;
  49. }
  50. newEffect = mainEntryPoint(hostCallback_static);
  51. if (newEffect == NULL) {
  52. blog(LOG_WARNING, "VST Plug-in's main() returns null.");
  53. CFRelease(pluginPathStringRef);
  54. CFRelease(bundleUrl);
  55. CFRelease(bundle);
  56. bundle = NULL;
  57. return NULL;
  58. }
  59. newEffect->user = this;
  60. // Clean up
  61. CFRelease(pluginPathStringRef);
  62. CFRelease(bundleUrl);
  63. return newEffect;
  64. }
  65. void VSTPlugin::unloadLibrary()
  66. {
  67. if (bundle) {
  68. CFRelease(bundle);
  69. bundle = NULL;
  70. }
  71. }
  72. bool VSTPlugin::vstLoaded()
  73. {
  74. return (bundle != NULL);
  75. }