EchoMap 2026-07-25 6d3977c
An experimental cross-platform digital signal processing application for sound-source localisation.
Loading...
Searching...
No Matches
EchoMap.hpp
Go to the documentation of this file.
1
7
8#ifndef ECHOMAP_ECHOMAP_HPP
9#define ECHOMAP_ECHOMAP_HPP
10
11#include <GLFW/glfw3.h>
12#include <imgui.h>
13#include <sigc++/scoped_connection.h>
14#include <webgpu/webgpu_cpp.h>
15
16#include "async/Worker.hpp"
19#include "panels/ErrorModal.hpp"
20
24namespace echomap
25{
26
27class IProjectPanel;
28class Project;
29
35{
36public:
46 EchoMap();
47
54 virtual void run_event_loop() = 0;
55
59 virtual ~EchoMap() noexcept;
60
61 void change_active_project(std::unique_ptr<Project> new_project) noexcept;
62
70 void notify(const Notification& notification);
71
81 void increment_forced_frames(unsigned int count = 4) noexcept;
82
83 EchoMap(const EchoMap&) = delete;
84 EchoMap& operator=(const EchoMap&) = delete;
85 EchoMap(EchoMap&&) = delete;
86 EchoMap& operator=(EchoMap&&) = delete;
87
88protected:
95 {
96 // clang-format off
98 [this](const AddChannelMappingNotification& n) { handle_notification(n); },
99 [this](const ModifySensorColourNotification& n) { handle_notification(n); },
100 [this](const ModifySensorPositionNotification& n) { handle_notification(n); },
101 [this](const ProjectSelectionCompleteNotification& n) { handle_notification(n); },
102 [this](const ClearErrorNotification& n) { handle_notification(n); },
103 };
104 // clang-format on
105 }
106
115 virtual void visit_notification(Notification& notification) = 0;
116
123 void render() noexcept;
124
125 static constexpr auto operation_timeout = std::numeric_limits<std::uint64_t>::max();
126
135 static GLFWwindow* create_window(
136 int width,
137 int height
138 );
139
154 static void configure_surface(
155 const wgpu::Surface& surface,
156 const wgpu::Device& device,
157 const wgpu::SurfaceCapabilities& capabilities,
158 std::uint32_t viewport_width,
159 std::uint32_t viewport_height
160 ) noexcept;
161
168 void setup_subscriptions();
169
175 wgpu::Future request_adapter() noexcept;
176
182 wgpu::Future request_device() noexcept;
183
189 void setup_imgui();
190
191 void setup_dockspace();
192
199 bool handle_window_resize() noexcept;
200
205
210
211 void raise_error(std::string_view message);
212 void raise_error(
213 std::string_view message,
214 const std::runtime_error& exception
215 );
216
217 void handle_notification(const AddChannelMappingNotification& notification) const;
218 void handle_notification(const ModifySensorColourNotification& notification) const;
219 void handle_notification(const ModifySensorPositionNotification& notification) const;
220 void handle_notification(const ProjectSelectionCompleteNotification& notification);
221 void handle_notification(const ClearErrorNotification& notification);
222
223 virtual void handle_result(LoadProjectResult&& result);
224 virtual void handle_result(LoadSignalFileResult&& result);
225
226 // NOLINTBEGIN(*-non-private-member-variables-in-classes)
227
228 std::uint32_t viewport_width = 1024;
229 std::uint32_t viewport_height = 1024;
230
231 wgpu::Instance instance;
232 wgpu::Adapter adapter;
233 wgpu::Device device;
234 wgpu::Surface surface;
235 wgpu::SurfaceCapabilities surface_capabilities;
236 GLFWwindow* window = nullptr;
237
240 std::vector<sigc::scoped_connection> connections;
241
242 std::vector<std::unique_ptr<IProjectPanel>> panels;
244 std::vector<Notification> notification_queue;
245 std::unique_ptr<Project> project;
246 std::unique_ptr<IPanel> active_modal;
247
248 ImGuiID dockspace_id;
249 bool dockspace_configured = false;
250 unsigned int forced_frames = 0;
251
252 // NOLINTEND(*-non-private-member-variables-in-classes)
253};
254
255} // namespace echomap
256
257#endif // ECHOMAP_ECHOMAP_HPP
AllNotificationsFwd specification.
EchoMap modal error panel specification.
WorkerResultDespatcher specification.
Worker specification.
virtual void run_event_loop()=0
Runs the platform-dependent event loop to manage and propagate interaction with the EchoMap applicati...
std::unique_ptr< Project > project
Owning container for the active Project.
Definition EchoMap.hpp:245
void increment_forced_frames(unsigned int count=4) noexcept
Indicate to the renderer that the following frames should always be rendered, regardless of whether t...
Definition EchoMap.cpp:622
void notify(const Notification &notification)
Submit a new Notification to the application queue.
Definition EchoMap.cpp:604
std::vector< sigc::scoped_connection > connections
RAII lifetime manager for signal connections.
Definition EchoMap.hpp:240
EchoMap()
Initialise a EchoMap application instance.
Definition EchoMap.cpp:41
void setup_subscriptions()
Configure the core signals for the application instance.
Definition EchoMap.cpp:166
void render() noexcept
Perform a render cycle on the configured Surface and Device.
Definition EchoMap.cpp:256
wgpu::Future request_device() noexcept
Produce a WebGPU Future for requesting an accelerator device.
Definition EchoMap.cpp:208
std::unique_ptr< IPanel > active_modal
The current active non-ErrorModal modal panel.
Definition EchoMap.hpp:246
auto make_common_notification_visitors()
Produce an overload set for std::visit for all platform-independent Notification objects.
Definition EchoMap.hpp:94
virtual void visit_notification(Notification &notification)=0
Uses std::visit on the given notification to invoke the corresponding handler.
static void configure_surface(const wgpu::Surface &surface, const wgpu::Device &device, const wgpu::SurfaceCapabilities &capabilities, std::uint32_t viewport_width, std::uint32_t viewport_height) noexcept
Configure a WebGPU Surface from a static context given metadata and Adapter capabilities.
Definition EchoMap.cpp:140
void process_notifications()
Handle any unconsumed Notification objects from the queue.
Definition EchoMap.cpp:470
bool handle_window_resize() noexcept
Check if the window has been resized compared with the stored dimensions, updating member variables a...
Definition EchoMap.cpp:439
static GLFWwindow * create_window(int width, int height)
Create a new GLFW window of the specified dimensions from a static context.
Definition EchoMap.cpp:118
std::vector< std::unique_ptr< IProjectPanel > > panels
Individual display components.
Definition EchoMap.hpp:242
void setup_imgui()
Create a context for Dear ImGui and ImPlot, and configure the plain GLFW and WebGPU backends.
Definition EchoMap.cpp:336
void process_worker_results()
Handle any unconsumed events from the Worker.
Definition EchoMap.cpp:492
wgpu::Future request_adapter() noexcept
Produce a WebGPU Future for requesting an Adapter.
Definition EchoMap.cpp:186
Worker worker
Multi-threaded worker for scheduling heavy computation tasks.
Definition EchoMap.hpp:238
std::optional< ErrorModal > error_modal
Persistent panel to indicate errors over all other panels.
Definition EchoMap.hpp:243
virtual ~EchoMap() noexcept
Clean up all persistent state registered by the application instance.
Definition EchoMap.cpp:91
WorkerResultDespatcher despatcher
Despatcher to manage Worker result channels.
Definition EchoMap.hpp:239
Provides a persistent ImGui state to raise errors as a modal.
Represents a panel or window on the GUI.
Definition IPanel.hpp:27
An IPanel which can receive updates to the application-wide active Project.
Denotes a loaded Project completed by a LoadProjectTask job.
Manages channels for WorkerResult message routing.
A Worker provides an encapsulated thread-safe despatch model for submitting work and reviewing result...
Definition Worker.hpp:45
std::variant< AddChannelMappingNotification, ModifySensorColourNotification, ModifySensorPositionNotification, ProjectSelectionCompleteNotification, ClearErrorNotification, RaiseFileChooserNotification, RegisterVFSMappingNotification, CompleteProjectLoadNotification, CancelProjectLoadNotification > Notification
A Notification is a trivial message sent exclusively to the EchoMap controller.
The main EchoMap outermost namespace for all non-exported symbols.
STL namespace.
A notification indicating that a new channel mapping should be established.
A notification indicating that any error state visible to the user should be reset.
A notification indicating that the colour of a Sensor should be changed.
A notification indicating that the position of a Sensor should be changed.
A notification indicating that a new Project file has been selected by the user, or the load operatio...
A helper type for succinctly specifying callable visitors over a variant alternative.