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

3 years ago
3 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. nextEventMatchingMask:NSAnyEventMask
  37. untilDate:date
  38. inMode:NSDefaultRunLoopMode
  39. dequeue:YES];
  40. if (event == nil)
  41. break;
  42. [NSApp sendEvent: event];
  43. }
  44. [pool release];
  45. #elif defined(CARLA_OS_WIN)
  46. MSG msg;
  47. if (! ::PeekMessage(&msg, nullptr, 0, 0, PM_NOREMOVE))
  48. return true;
  49. if (::GetMessage(&msg, nullptr, 0, 0) >= 0)
  50. {
  51. if (msg.message == WM_QUIT)
  52. return false;
  53. //TranslateMessage(&msg);
  54. DispatchMessage(&msg);
  55. }
  56. #endif
  57. return true;
  58. }
  59. CARLA_BACKEND_END_NAMESPACE
  60. // ---------------------------------------------------------------------------------------------------------------------
  61. #endif // CARLA_MAIN_LOOP_HPP_INCLUDED