EchoMap 2026-07-25 6d3977c
An experimental cross-platform digital signal processing application for sound-source localisation.
Loading...
Searching...
No Matches
echomap::EchoMapWeb Class Reference

EchoMap application implementation for WebAssembly/Emscripten platforms. More...

#include <EchoMapWeb.hpp>

Inheritance diagram for echomap::EchoMapWeb:
[legend]

Public Member Functions

void run_event_loop () override
 Runs the platform-dependent event loop to manage and propagate interaction with the EchoMap application.
Public Member Functions inherited from echomap::EchoMap
 EchoMap ()
 Initialise a EchoMap application instance.
virtual ~EchoMap () noexcept
 Clean up all persistent state registered by the application instance.
void change_active_project (std::unique_ptr< Project > new_project) noexcept
void notify (const Notification &notification)
 Submit a new Notification to the application queue.
void increment_forced_frames (unsigned int count=4) noexcept
 Indicate to the renderer that the following frames should always be rendered, regardless of whether there are any new events to process.
 EchoMap (const EchoMap &)=delete
EchoMapoperator= (const EchoMap &)=delete
 EchoMap (EchoMap &&)=delete
EchoMapoperator= (EchoMap &&)=delete

Protected Member Functions

void visit_notification (Notification &notification) override
 Uses std::visit on the given notification to invoke the corresponding handler.
void handle_result (LoadProjectResult &&result) override
void handle_result (LoadSignalFileResult &&result) override
Protected Member Functions inherited from echomap::EchoMap
auto make_common_notification_visitors ()
 Produce an overload set for std::visit for all platform-independent Notification objects.
void render () noexcept
 Perform a render cycle on the configured Surface and Device.
void setup_subscriptions ()
 Configure the core signals for the application instance.
wgpu::Future request_adapter () noexcept
 Produce a WebGPU Future for requesting an Adapter.
wgpu::Future request_device () noexcept
 Produce a WebGPU Future for requesting an accelerator device.
void setup_imgui ()
 Create a context for Dear ImGui and ImPlot, and configure the plain GLFW and WebGPU backends.
void setup_dockspace ()
bool handle_window_resize () noexcept
 Check if the window has been resized compared with the stored dimensions, updating member variables and reconfiguring the WebGPU surface if necessary.
void process_notifications ()
 Handle any unconsumed Notification objects from the queue.
void process_worker_results ()
 Handle any unconsumed events from the Worker.
void raise_error (std::string_view message)
void raise_error (std::string_view message, const std::runtime_error &exception)
void handle_notification (const AddChannelMappingNotification &notification) const
void handle_notification (const ModifySensorColourNotification &notification) const
void handle_notification (const ModifySensorPositionNotification &notification) const
void handle_notification (const ProjectSelectionCompleteNotification &notification)
void handle_notification (const ClearErrorNotification &notification)

Private Member Functions

void handle_notification (const CancelProjectLoadNotification &notification)
void handle_notification (const CompleteProjectLoadNotification &notification)
void handle_notification (RegisterVFSMappingNotification &notification) const

Static Private Member Functions

static void render_shim (void *echomap_instance)
 Invokes the renderer from a static context given an untyped mutable pointer to the EchoMap object instance.

Private Attributes

std::unique_ptr< PartialProjectunloaded_project
 Owning container for the unloaded Project.

Additional Inherited Members

Static Protected Member Functions inherited from echomap::EchoMap
static GLFWwindow * create_window (int width, int height)
 Create a new GLFW window of the specified dimensions from a static context.
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.
Protected Attributes inherited from echomap::EchoMap
std::uint32_t viewport_width = 1024
std::uint32_t viewport_height = 1024
wgpu::Instance instance
wgpu::Adapter adapter
wgpu::Device device
wgpu::Surface surface
wgpu::SurfaceCapabilities surface_capabilities
GLFWwindow * window = nullptr
Worker worker
 Multi-threaded worker for scheduling heavy computation tasks.
WorkerResultDespatcher despatcher
 Despatcher to manage Worker result channels.
std::vector< sigc::scoped_connection > connections
 RAII lifetime manager for signal connections.
std::vector< std::unique_ptr< IProjectPanel > > panels
 Individual display components.
std::optional< ErrorModalerror_modal
 Persistent panel to indicate errors over all other panels.
std::vector< Notificationnotification_queue
std::unique_ptr< Projectproject
 Owning container for the active Project.
std::unique_ptr< IPanelactive_modal
 The current active non-ErrorModal modal panel.
ImGuiID dockspace_id
bool dockspace_configured = false
unsigned int forced_frames = 0
Static Protected Attributes inherited from echomap::EchoMap
static constexpr auto operation_timeout = std::numeric_limits<std::uint64_t>::max()

Detailed Description

EchoMap application implementation for WebAssembly/Emscripten platforms.

Definition at line 25 of file EchoMapWeb.hpp.

Member Function Documentation

◆ handle_notification() [1/3]

void echomap::EchoMapWeb::handle_notification ( const CancelProjectLoadNotification & notification)
private

Definition at line 103 of file EchoMapWeb.cpp.

106{
107 notification.verify_project(unloaded_project.get());
108
109 active_modal.reset();
110 unloaded_project.reset();
111}
std::unique_ptr< PartialProject > unloaded_project
Owning container for the unloaded Project.
std::unique_ptr< IPanel > active_modal
The current active non-ErrorModal modal panel.
Definition EchoMap.hpp:246

◆ handle_notification() [2/3]

void echomap::EchoMapWeb::handle_notification ( const CompleteProjectLoadNotification & notification)
private

Definition at line 113 of file EchoMapWeb.cpp.

116{
117 notification.verify_project(unloaded_project.get());
118
119 // For each group, create a worker notification to load the corresponding file.
120
121 for (auto&& [vfs_path, factories] : unloaded_project->take_unloaded_factories()) {
122
123 if (!vfs_path.has_value())
124 throw std::runtime_error("Refusing CompleteProjectLoadNotification due to an incomplete VFS mapping.");
125
126 // Once these notifications return, if everything is loaded correctly, we'll change the active project.
127 worker.submit(
128 std::make_unique<LoadSignalFileTask>(unloaded_project->get_id(), *vfs_path, std::move(factories))
129 );
130 }
131
132 active_modal.reset();
133}
Worker worker
Multi-threaded worker for scheduling heavy computation tasks.
Definition EchoMap.hpp:238
T make_unique(T... args)

◆ handle_notification() [3/3]

void echomap::EchoMapWeb::handle_notification ( RegisterVFSMappingNotification & notification) const
private

Definition at line 135 of file EchoMapWeb.cpp.

138{
139 notification.verify_project(unloaded_project.get());
140
141 try {
142 unloaded_project->add_vfs_mapping_for_unavailable_signal(
143 notification.external,
144 std::move(notification.internal)
145 );
146 } catch (const std::runtime_error&) {
147 throw IgnoredWarning(
149 "Dropping RegisterVFSMappingNotification since we don't need a mapping for {}.",
150 notification.external.c_str()
151 )
152 );
153 }
154}
T format(T... args)

◆ handle_result() [1/2]

void echomap::EchoMapWeb::handle_result ( LoadProjectResult && result)
overrideprotectedvirtual

Reimplemented from echomap::EchoMap.

Definition at line 51 of file EchoMapWeb.cpp.

54{
55 if (active_modal != nullptr) {
56 LOG_WARN("Ignoring request to change active Project since there is an active modal.");
57 return;
58 }
59
60 auto&& new_project = std::move(result).take_project();
61
62 if (!new_project->observe_unloaded_signals().empty()) {
63 // Raise the modal to query for the sources.
64 active_modal = std::make_unique<MapSourcesModal>(this, new_project.get());
65 unloaded_project = std::move(new_project);
66 } else
67 change_active_project(std::move(new_project));
68}
#define LOG_WARN(msg)
Logs an unformatted warning-level message using echomap::Logger::log.
Definition Logger.hpp:162

◆ handle_result() [2/2]

void echomap::EchoMapWeb::handle_result ( LoadSignalFileResult && result)
overrideprotectedvirtual

Reimplemented from echomap::EchoMap.

Definition at line 70 of file EchoMapWeb.cpp.

73{
74 Project* target = nullptr;
75
76 // Determine whether the result relates to a Signal bound to the active Project or the unloaded Project.
77
78 if (project != nullptr && result.get_project_id() == project->get_id())
79 target = project.get();
80 else if (unloaded_project != nullptr && result.get_project_id() == unloaded_project->get_id())
81 target = unloaded_project.get();
82
83 if (target == nullptr) {
85 "Dropping LoadSignalFileResult, which was intended for the unavailable Project with ID {}.",
86 result.get_project_id()
87 );
88
89 return;
90 }
91
92 // Add the signals to the target Project.
93
94 for (auto&& signals = std::move(result).take_signals(); auto signal : signals | std::views::as_rvalue)
95 target->add_signal(std::move(signal));
96
97 // If it was an unloaded Project, and all signals are now loaded, it can become the active Project.
98
99 if (target == unloaded_project.get() && unloaded_project->observe_unloaded_signals().empty())
100 change_active_project(std::move(unloaded_project));
101}
#define LOG_F_WARN(msg,...)
Logs a formatted warning-level message using echomap::Logger::log_f.
Definition Logger.hpp:115
std::unique_ptr< Project > project
Owning container for the active Project.
Definition EchoMap.hpp:245
T signal(T... args)

◆ render_shim()

void echomap::EchoMapWeb::render_shim ( void * echomap_instance)
staticprivate

Invokes the renderer from a static context given an untyped mutable pointer to the EchoMap object instance.

This function is intended to be used as a callback from the Emscripten C API.

Parameters
echomap_instanceThe EchoMapWeb application instance on which to invoke the renderer.

Definition at line 156 of file EchoMapWeb.cpp.

159{
160 auto* instance = static_cast<EchoMapWeb*>(echomap_instance);
161 instance->render();
162}

◆ run_event_loop()

void echomap::EchoMapWeb::run_event_loop ( )
overridevirtual

Runs the platform-dependent event loop to manage and propagate interaction with the EchoMap application.

This function returns only once GLFW indicates that the window should close. Following closure, the event loop could be re-run, or the application could clean up by calling the destructor.

Implements echomap::EchoMap.

Definition at line 164 of file EchoMapWeb.cpp.

165{
166 emscripten_set_main_loop_arg(&EchoMapWeb::render_shim, this, 0, true);
167}
static void render_shim(void *echomap_instance)
Invokes the renderer from a static context given an untyped mutable pointer to the EchoMap object ins...

◆ visit_notification()

void echomap::EchoMapWeb::visit_notification ( Notification & notification)
overrideprotectedvirtual

Uses std::visit on the given notification to invoke the corresponding handler.

This function is virtual, since the overload set can be platform-dependent in addition to the base handlers provided by make_common_notification_visitors.

Parameters
notificationThe notification to visit.

Implements echomap::EchoMap.

Definition at line 32 of file EchoMapWeb.cpp.

35{
37 // clang-format off
38
39 variant_helpers::Overloaded{
41 [this](const CancelProjectLoadNotification& n) { handle_notification(n); },
42 [this](const CompleteProjectLoadNotification& n) { handle_notification(n); },
43 [this](RegisterVFSMappingNotification& n) { handle_notification(n); },
44 },
45
46 // clang-format on
47 notification
48 );
49}
auto make_common_notification_visitors()
Produce an overload set for std::visit for all platform-independent Notification objects.
Definition EchoMap.hpp:94
T visit(T... args)

Member Data Documentation

◆ unloaded_project

std::unique_ptr<PartialProject> echomap::EchoMapWeb::unloaded_project
private

Owning container for the unloaded Project.

Definition at line 53 of file EchoMapWeb.hpp.


The documentation for this class was generated from the following files: