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

9 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. void MessageManager::runDispatchLoop()
  18. {
  19. jassert (isThisTheMessageThread()); // must only be called by the message thread
  20. while (! quitMessagePosted)
  21. {
  22. JUCE_AUTORELEASEPOOL
  23. {
  24. [[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode
  25. beforeDate: [NSDate dateWithTimeIntervalSinceNow: 0.001]];
  26. }
  27. }
  28. }
  29. void MessageManager::stopDispatchLoop()
  30. {
  31. [[[UIApplication sharedApplication] delegate] applicationWillTerminate: [UIApplication sharedApplication]];
  32. exit (0); // iOS apps get no mercy..
  33. }
  34. #if JUCE_MODAL_LOOPS_PERMITTED
  35. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  36. {
  37. JUCE_AUTORELEASEPOOL
  38. {
  39. jassert (isThisTheMessageThread()); // must only be called by the message thread
  40. uint32 startTime = Time::getMillisecondCounter();
  41. NSDate* endDate = [NSDate dateWithTimeIntervalSinceNow: millisecondsToRunFor * 0.001];
  42. while (! quitMessagePosted)
  43. {
  44. JUCE_AUTORELEASEPOOL
  45. {
  46. [[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode
  47. beforeDate: endDate];
  48. if (millisecondsToRunFor >= 0
  49. && Time::getMillisecondCounter() >= startTime + (uint32) millisecondsToRunFor)
  50. break;
  51. }
  52. }
  53. return ! quitMessagePosted;
  54. }
  55. }
  56. #endif
  57. //==============================================================================
  58. static ScopedPointer<MessageQueue> messageQueue;
  59. void MessageManager::doPlatformSpecificInitialisation()
  60. {
  61. if (messageQueue == nullptr)
  62. messageQueue = new MessageQueue();
  63. }
  64. void MessageManager::doPlatformSpecificShutdown()
  65. {
  66. messageQueue = nullptr;
  67. }
  68. bool MessageManager::postMessageToSystemQueue (MessageManager::MessageBase* const message)
  69. {
  70. if (messageQueue != nullptr)
  71. messageQueue->post (message);
  72. return true;
  73. }
  74. void MessageManager::broadcastMessage (const String&)
  75. {
  76. // N/A on current iOS
  77. }