Anklang-0.3.0.dev712+gdc4e642f anklang-0.3.0.dev712+gdc4e642f
ASE — Anklang Sound Engine (C++)

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce-linux.cc
Go to the documentation of this file.
1 // This Source Code Form is licensed MPL-2.0: http://mozilla.org/MPL/2.0
2#include "trkn/juce.hh" // PCH include must come first
3
4#include "utils.hh"
5#include "main.hh"
6#include "internal.hh"
7#include "loop.hh"
8
9/* Linux support for Juce. Notes on the original juce-linux setup.
10 * JUCEApplicationBase::main() does:
11 * - It calls JUCEApplicationBase::createInstance() to create the JUCEApplication singleton
12 * - The JUCEApplicationBase ctor assigns appInstance for JUCEApplicationBase::getInstance()
13 * - It calls the JUCEApplicationBase initialiseApp() and shutdownApp() methods
14 * - It also runs the "message" loop via MessageManager::getInstance()->runDispatchLoop()
15 * - It tries to catch and handle any exceptions bubbeling up
16 * Then MessageManager::runDispatchLoop() does:
17 * - It asserts to be run on isThisTheMessageThread()
18 * - It ends upon quitMessageReceived
19 * - It runs detail::dispatchNextMessageOnSystemQueue() and sleeps for 1ms
20 * - There is also a variant runDispatchLoopUntil(), only present if JUCE_MODAL_LOOPS_PERMITTED
21 * Then dispatchNextMessageOnSystemQueue() does:
22 * - Call JUCEApplicationBase::quit() on SIGINT
23 * - Dispatches all pending events
24 * - Will poll the fds for 2000ms if no events were pending
25 */
26
27// TODO: disable JUCE_MODAL_LOOPS_PERMITTED
28
29namespace juce {
30
31namespace detail {
32bool dispatchNextMessageOnSystemQueue (bool returnIfNoPendingMessages);
33bool
34dispatchNextMessageOnSystemQueue (bool returnIfNoPendingMessages)
35{ // trkn/juce_events/messages/juce_MessageManager.cpp
36 Ase::warning ("%s: -ENOIMPL\n", __func__);
37 return false;
38}
39} // detail
40
41// == juce::MessageManager ==
42static CriticalSection message_lock;
43static ReferenceCountedArray<MessageManager::MessageBase> message_queue;
44
45void
46MessageManager::broadcastMessage (const String &messageText)
47{
48 // send a message to all other running juce applications; unimplemented in JUCE-7.0.12
49 Ase::warning ("%s: -ENOIMPL\n", __func__);
50}
51
52bool
53MessageManager::postMessageToSystemQueue (MessageManager::MessageBase *const message)
54{
55 // Must be thread safe
56 ScopedLock sl (message_lock);
57 message_queue.add (message);
59 return true;
60}
61
62static bool
63juce_loop_dispatcher (const Ase::LoopState &state)
64{
65 switch (state.phase)
66 {
67 case Ase::LoopState::PREPARE:
68 case Ase::LoopState::CHECK: {
69 ScopedLock sl (message_lock); // TODO: use atomic counter
70 return message_queue.size() > 0;
71 }
72 case Ase::LoopState::DISPATCH: {
73 MessageManager::MessageBase::Ptr msg;
74 {
75 ScopedLock sl (message_lock);
76 msg = message_queue.removeAndReturn (0);
77 }
78 // TODO: catch exceptions
79 msg->messageCallback();
80 return true; // keep alive
81 }
82 default: ;
83 }
84 return false;
85}
86
87void
88MessageManager::doPlatformSpecificInitialisation()
89{
90 Ase::main_loop->exec_dispatcher (juce_loop_dispatcher, Ase::LoopPriority::RTAUDIO);
91}
92
93void
94MessageManager::doPlatformSpecificShutdown()
95{
96 // undo doPlatformSpecificInitialisation
97}
98
99namespace LinuxEventLoop {
100
101void
102registerFdCallback (int fd, std::function<void(int)> func, short evmask)
103{
104 // Must be thread safe
105 Ase::warning ("%s: -ENOIMPL\n", __func__);
106}
107
108void
110{
111 // Must be thread safe
112 Ase::warning ("%s: -ENOIMPL\n", __func__);
113}
114
115} // LinuxEventLoop
116
117} // juce
void registerFdCallback(int fd, std::function< void(int)> func, short evmask)
Register event loop callback for fd events, uses <poll.h> constants.
void unregisterFdCallback(int fd)
Unregister fd and its callback.
void main_loop_wakeup()
Wake up the event loop.
Definition main.cc:350
@ RTAUDIO
Threshold for priorization across different loops.
CriticalSection::ScopedLockType ScopedLock