libAlgAudio  v1.99-440-g08538e5-dirty
The development library for AlgAudio framework.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SDLMain.hpp
Go to the documentation of this file.
1 #ifndef SDLMAIN_HPP
2 #define SDLMAIN_HPP
3 /*
4 This file is part of AlgAudio.
5 
6 AlgAudio, Copyright (C) 2015 CeTA - Audiovisual Technology Center
7 
8 AlgAudio is free software: you can redistribute it and/or modify
9 it under the terms of the GNU Lesser General Public License as
10 published by the Free Software Foundation, either version 3 of the
11 License, or (at your option) any later version.
12 
13 AlgAudio is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU Lesser General Public License for more details.
17 
18 You should have received a copy of the GNU Lesser General Public License
19 along with AlgAudio. If not, see <http://www.gnu.org/licenses/>.
20 */
21 #include <map>
22 #include <memory>
23 #include <atomic>
24 
25 #include "Window.hpp"
26 
27 union SDL_Event;
28 
29 namespace AlgAudio{
30 
34 class SDLMain{
35 private:
36  SDLMain() = delete; // static class
37 public:
39  static void Init();
41  static void Quit();
47  static void Loop();
49  static void Step();
57  static void RegisterWindow(std::shared_ptr<Window>);
61  static void UnregisterWindow(std::shared_ptr<Window>);
63  static void UnregisterAll();
65  static unsigned int GetWindowNum() {return registered_windows.size();}
66 
74 
75  // These two funcitions are used by i/o threads to notify the main loop that
76  // there is some input ready to be processed. These functions are thread-safe.
77  // They send a custom SDL_UserEvent to the main event queue, effectivelly
78  // waking up the main thread.
79  static void PushNotifySubprocessEvent();
80  static void PushNotifyOSCEvent();
81  static std::atomic<int> notify_event_id;
82 
83  static void SetTextInput(bool);
84 
85  static std::atomic_bool running;
86 
91  };
92 private:
93  static std::map<unsigned int, std::shared_ptr<Window>> registered_windows;
94  static void ProcessEvent(const SDL_Event&);
95  static int last_draw_time;
96 
97  // These flags indicate whether a notify event is already in SDL queue.
98  // This allows limiting the number of such events in queue to 1, to avoid
99  // flooding the queue with same events, in case multile osc messages arrive
100  // simultaneously.
101  static std::atomic_flag ev_flag_notify_osc_already_pushed;
102  static std::atomic_flag ev_flag_notify_subprocess_already_pushed;
103 };
104 
105 } // namespace AlgAudio
106 
107 #endif // SDLMAIN_HPP
Definition: SDLMain.hpp:88
CustomEventCodes
Definition: SDLMain.hpp:87
static void UnregisterAll()
static std::atomic< int > notify_event_id
Definition: SDLMain.hpp:81
static void Init()
static std::atomic_bool running
Definition: SDLMain.hpp:85
static void RegisterWindow(std::shared_ptr< Window >)
static unsigned int GetWindowNum()
Definition: SDLMain.hpp:65
Definition: SDLMain.hpp:89
static void Quit()
static void UnregisterWindow(std::shared_ptr< Window >)
static Signal< float > on_before_frame
Definition: SDLMain.hpp:73
Definition: SDLMain.hpp:90
static void PushNotifyOSCEvent()
Definition: SDLMain.hpp:34
static void Loop()
static void Step()
Definition: Alertable.hpp:26
static void PushNotifySubprocessEvent()
static void SetTextInput(bool)