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.7KB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Carla macOS utils
  3. * Copyright (C) 2018-2021 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. #include <sys/xattr.h>
  21. #import <Cocoa/Cocoa.h>
  22. #import <Foundation/Foundation.h>
  23. CARLA_BACKEND_START_NAMESPACE
  24. // --------------------------------------------------------------------------------------------------------------------
  25. void initStandaloneApplication()
  26. {
  27. [NSApplication sharedApplication];
  28. [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
  29. [NSApp activateIgnoringOtherApps:YES];
  30. }
  31. const char* findBinaryInBundle(const char* const bundleDir)
  32. {
  33. const CFURLRef urlRef = CFURLCreateFromFileSystemRepresentation(0, (const UInt8*)bundleDir, (CFIndex)strlen(bundleDir), true);
  34. CARLA_SAFE_ASSERT_RETURN(urlRef != nullptr, nullptr);
  35. const CFBundleRef bundleRef = CFBundleCreate(kCFAllocatorDefault, urlRef);
  36. CARLA_SAFE_ASSERT_RETURN(bundleRef != nullptr, nullptr);
  37. const CFURLRef exeRef = CFBundleCopyExecutableURL(bundleRef);
  38. CARLA_SAFE_ASSERT_RETURN(exeRef != nullptr, nullptr);
  39. const CFURLRef absoluteURL = CFURLCopyAbsoluteURL(exeRef);
  40. CARLA_SAFE_ASSERT_RETURN(absoluteURL != nullptr, nullptr);
  41. const NSString* strRef = (NSString*)CFURLCopyFileSystemPath(absoluteURL, kCFURLPOSIXPathStyle);
  42. CARLA_SAFE_ASSERT_RETURN(strRef != nullptr, nullptr);
  43. static CarlaString ret;
  44. ret = [strRef UTF8String];
  45. CFRelease(absoluteURL);
  46. CFRelease(exeRef);
  47. CFRelease(bundleRef);
  48. CFRelease(urlRef);
  49. return ret.buffer();
  50. }
  51. bool removeFileFromQuarantine(const char* const filename)
  52. {
  53. return removexattr(filename, "com.apple.quarantine", 0) == 0;
  54. }
  55. // --------------------------------------------------------------------------------------------------------------------
  56. AutoNSAutoreleasePool::AutoNSAutoreleasePool()
  57. : pool([NSAutoreleasePool new]) {}
  58. AutoNSAutoreleasePool::~AutoNSAutoreleasePool()
  59. {
  60. NSAutoreleasePool* rpool = (NSAutoreleasePool*)pool;
  61. [rpool drain];
  62. }
  63. // --------------------------------------------------------------------------------------------------------------------
  64. CARLA_BACKEND_END_NAMESPACE
  65. #endif // CARLA_OS_MAC