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.

juce_ios_MessageManager.mm 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. The code included in this file is provided under the terms of the ISC license
  8. http://www.isc.org/downloads/software-support-policy/isc-license. Permission
  9. To use, copy, modify, and/or distribute this software for any purpose with or
  10. without fee is hereby granted provided that the above copyright notice and
  11. this permission notice appear in all copies.
  12. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  13. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  14. DISCLAIMED.
  15. ==============================================================================
  16. */
  17. namespace juce
  18. {
  19. void MessageManager::runDispatchLoop()
  20. {
  21. jassert (isThisTheMessageThread()); // must only be called by the message thread
  22. while (quitMessagePosted.get() == 0)
  23. {
  24. JUCE_AUTORELEASEPOOL
  25. {
  26. [[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode
  27. beforeDate: [NSDate dateWithTimeIntervalSinceNow: 0.001]];
  28. }
  29. }
  30. }
  31. void MessageManager::stopDispatchLoop()
  32. {
  33. if (! SystemStats::isRunningInAppExtensionSandbox())
  34. [[[UIApplication sharedApplication] delegate] applicationWillTerminate: [UIApplication sharedApplication]];
  35. exit (0); // iOS apps get no mercy..
  36. }
  37. #if JUCE_MODAL_LOOPS_PERMITTED
  38. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  39. {
  40. JUCE_AUTORELEASEPOOL
  41. {
  42. jassert (isThisTheMessageThread()); // must only be called by the message thread
  43. uint32 startTime = Time::getMillisecondCounter();
  44. NSDate* endDate = [NSDate dateWithTimeIntervalSinceNow: millisecondsToRunFor * 0.001];
  45. while (quitMessagePosted.get() == 0)
  46. {
  47. JUCE_AUTORELEASEPOOL
  48. {
  49. [[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode
  50. beforeDate: endDate];
  51. if (millisecondsToRunFor >= 0
  52. && Time::getMillisecondCounter() >= startTime + (uint32) millisecondsToRunFor)
  53. break;
  54. }
  55. }
  56. return quitMessagePosted.get() == 0;
  57. }
  58. }
  59. #endif
  60. //==============================================================================
  61. static std::unique_ptr<MessageQueue> messageQueue;
  62. void MessageManager::doPlatformSpecificInitialisation()
  63. {
  64. if (messageQueue == nullptr)
  65. messageQueue.reset (new MessageQueue());
  66. }
  67. void MessageManager::doPlatformSpecificShutdown()
  68. {
  69. messageQueue = nullptr;
  70. }
  71. bool MessageManager::postMessageToSystemQueue (MessageManager::MessageBase* const message)
  72. {
  73. if (messageQueue != nullptr)
  74. messageQueue->post (message);
  75. return true;
  76. }
  77. void MessageManager::broadcastMessage (const String&)
  78. {
  79. // N/A on current iOS
  80. }
  81. } // namespace juce