Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CarlaMacUtils.cpp 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Carla macOS utils
  3. * Copyright (C) 2018 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the doc/GPL.txt file.
  16. */
  17. #ifdef CARLA_OS_MAC
  18. #include "CarlaMacUtils.hpp"
  19. #include "CarlaString.hpp"
  20. #import <Foundation/Foundation.h>
  21. CARLA_BACKEND_START_NAMESPACE
  22. // --------------------------------------------------------------------------------------------------------------------
  23. const char* findBinaryInBundle(const char* const bundleDir)
  24. {
  25. const CFURLRef urlRef = CFURLCreateFromFileSystemRepresentation(0, (const UInt8*)bundleDir, (CFIndex)strlen(bundleDir), true);
  26. CARLA_SAFE_ASSERT_RETURN(urlRef != nullptr, nullptr);
  27. const CFBundleRef bundleRef = CFBundleCreate(kCFAllocatorDefault, urlRef);
  28. CARLA_SAFE_ASSERT_RETURN(bundleRef != nullptr, nullptr);
  29. const CFURLRef exeRef = CFBundleCopyExecutableURL(bundleRef);
  30. CARLA_SAFE_ASSERT_RETURN(exeRef != nullptr, nullptr);
  31. const CFURLRef absoluteURL = CFURLCopyAbsoluteURL(exeRef);
  32. CARLA_SAFE_ASSERT_RETURN(absoluteURL != nullptr, nullptr);
  33. const NSString* strRef = (NSString*)CFURLCopyFileSystemPath(absoluteURL, kCFURLPOSIXPathStyle);
  34. CARLA_SAFE_ASSERT_RETURN(strRef != nullptr, nullptr);
  35. static CarlaString ret;
  36. ret = [strRef UTF8String];
  37. CFRelease(absoluteURL);
  38. CFRelease(exeRef);
  39. CFRelease(bundleRef);
  40. CFRelease(urlRef);
  41. return ret.buffer();
  42. }
  43. // --------------------------------------------------------------------------------------------------------------------
  44. AutoNSAutoreleasePool::AutoNSAutoreleasePool()
  45. : pool([NSAutoreleasePool new]) {}
  46. AutoNSAutoreleasePool::~AutoNSAutoreleasePool()
  47. {
  48. NSAutoreleasePool* rpool = (NSAutoreleasePool*)pool;
  49. [rpool drain];
  50. }
  51. // --------------------------------------------------------------------------------------------------------------------
  52. CARLA_BACKEND_END_NAMESPACE
  53. #endif // CARLA_OS_MAC