VST3: fetch midi mappings all at once, use it for note/sound-off
[carla.git] / source / utils / CarlaMainLoop.hpp
blob9b9bf90536c2a9b886ee78d506fdad873b59dae1
1 /*
2 * Carla Main-Loop utils
3 * Copyright (C) 2017 Filipe Coelho <falktx@falktx.com>
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.
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.
15 * For a full copy of the GNU General Public License see the doc/GPL.txt file.
18 #ifndef CARLA_MAIN_LOOP_HPP_INCLUDED
19 #define CARLA_MAIN_LOOP_HPP_INCLUDED
21 #include "CarlaBackend.h"
22 #include "CarlaUtils.hpp"
24 #ifdef CARLA_OS_MAC
25 # import <Cocoa/Cocoa.h>
26 #endif
28 // ---------------------------------------------------------------------------------------------------------------------
30 CARLA_BACKEND_START_NAMESPACE
32 static inline
33 bool runMainLoopOnce()
35 #if defined(CARLA_OS_MAC)
36 NSAutoreleasePool* const pool = [[NSAutoreleasePool alloc] init];
37 NSDate* const date = [NSDate distantPast];
38 NSEvent* event;
40 for (;;)
42 event = [NSApp
43 #ifdef __MAC_10_12
44 nextEventMatchingMask:NSEventMaskAny
45 #else
46 nextEventMatchingMask:NSAnyEventMask
47 #endif
48 untilDate:date
49 inMode:NSDefaultRunLoopMode
50 dequeue:YES];
52 if (event == nil)
53 break;
55 [NSApp sendEvent: event];
58 [pool release];
59 #elif defined(CARLA_OS_WIN)
60 MSG msg;
61 if (! ::PeekMessage(&msg, nullptr, 0, 0, PM_NOREMOVE))
62 return true;
64 if (::GetMessage(&msg, nullptr, 0, 0) >= 0)
66 if (msg.message == WM_QUIT)
67 return false;
69 //TranslateMessage(&msg);
70 DispatchMessage(&msg);
72 #endif
74 return true;
77 CARLA_BACKEND_END_NAMESPACE
79 // ---------------------------------------------------------------------------------------------------------------------
81 #endif // CARLA_MAIN_LOOP_HPP_INCLUDED