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.

CarlaMainLoop.hpp 2.2KB

3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Carla Main-Loop utils
  3. * Copyright (C) 2017 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. #ifndef CARLA_MAIN_LOOP_HPP_INCLUDED
  18. #define CARLA_MAIN_LOOP_HPP_INCLUDED
  19. #include "CarlaBackend.h"
  20. #include "CarlaUtils.hpp"
  21. #ifdef CARLA_OS_MAC
  22. # import <Cocoa/Cocoa.h>
  23. #endif
  24. // ---------------------------------------------------------------------------------------------------------------------
  25. CARLA_BACKEND_START_NAMESPACE
  26. static inline
  27. bool runMainLoopOnce()
  28. {
  29. #if defined(CARLA_OS_MAC)
  30. NSAutoreleasePool* const pool = [[NSAutoreleasePool alloc] init];
  31. NSDate* const date = [NSDate distantPast];
  32. NSEvent* event;
  33. for (;;)
  34. {
  35. event = [NSApp
  36. #ifdef __MAC_10_12
  37. nextEventMatchingMask:NSEventMaskAny
  38. #else
  39. nextEventMatchingMask:NSAnyEventMask
  40. #endif
  41. untilDate:date
  42. inMode:NSDefaultRunLoopMode
  43. dequeue:YES];
  44. if (event == nil)
  45. break;
  46. [NSApp sendEvent: event];
  47. }
  48. [pool release];
  49. #elif defined(CARLA_OS_WIN)
  50. MSG msg;
  51. if (! ::PeekMessage(&msg, nullptr, 0, 0, PM_NOREMOVE))
  52. return true;
  53. if (::GetMessage(&msg, nullptr, 0, 0) >= 0)
  54. {
  55. if (msg.message == WM_QUIT)
  56. return false;
  57. //TranslateMessage(&msg);
  58. DispatchMessage(&msg);
  59. }
  60. #endif
  61. return true;
  62. }
  63. CARLA_BACKEND_END_NAMESPACE
  64. // ---------------------------------------------------------------------------------------------------------------------
  65. #endif // CARLA_MAIN_LOOP_HPP_INCLUDED