EchoMap 2026-07-25 6d3977c
An experimental cross-platform digital signal processing application for sound-source localisation.
Loading...
Searching...
No Matches
Project.cpp
1//
2// Created by owd on 25/06/2026.
3//
4
5#include "Project.hpp"
6
7#include <format>
8
9#include "Sensor.hpp"
10#include "Signal.hpp"
11
12namespace echomap
13{
14
16 const std::string_view project_name
17) :
18 Object(project_name)
19{
20}
21
22Project::~Project() = default;
23
26)
27{
28 const auto [it, success] = signals.emplace(signal->get_id(), std::move(signal));
29 if (!success)
30 return nullptr;
31
32 return it->second ? it->second.get() : nullptr;
33}
34
37)
38{
39 const auto [it, success] = sensors.emplace(sensor->get_id(), std::move(sensor));
40 if (!success)
41 return nullptr;
42
43 return it->second ? it->second.get() : nullptr;
44}
45
47 const Signal& signal,
48 const Sensor& sensor
49)
50{
51 if (!signals.contains(signal.get_id()))
52 throw std::runtime_error(std::format("{} does not exist in the project.", signal.get_name()));
53
54 if (!sensors.contains(sensor.get_id()))
55 throw std::runtime_error(std::format("{} does not exist in the project.", sensor.get_name()));
56
57 if (!requested_channel_mapping.emplace(signal.get_id(), sensor.get_id()).second)
60 "Could not associate {} with {}: a component is already mapped.",
61 signal.get_name(),
62 sensor.get_name()
63 )
64 );
65}
66
68 const id_type signal_id,
69 const id_type sensor_id
70)
71{
72 if (!requested_channel_mapping.emplace(signal_id, sensor_id).second)
75 "Could not associate Signal with ID {} to Sensor with ID {}: a component is already mapped.",
76 signal_id,
77 sensor_id
78 )
79 );
80}
81
83{
84 return sensors.size();
85}
86
87ImPlot3DPoint Project::get_sensor_point(
88 const int idx,
89 const void* const project_instance
90) noexcept
91{
92 const auto* const project_ptr = static_cast<const Project*>(project_instance);
93 const auto [x, y, z] = project_ptr->sensors.values()[idx]->position;
94
95 return { x, y, z };
96}
97
99 const id_type sensor_id
100)
101{
102 const auto sensor_it = sensors.find(sensor_id);
103 if (sensor_it == sensors.end())
104 throw std::runtime_error(std::format("No Sensor with ID {} belongs to {}.", sensor_id, get_name()));
105
106 return *sensor_it->second;
107}
108
110 const Signal&,
111 const Sensor&>>
113 const id_type signal_id,
114 const id_type sensor_id
115) const
116{
117 /*
118 * For the exception messages here, the best we can manage is the ID. Logging the display names would require
119 * resolving the full Object, which we can't do if we can't find the thing!
120 */
121
122 const auto signal_it = signals.find(signal_id);
123 if (signal_it == signals.end())
124 return {};
125
126 const auto sensor_it = sensors.find(sensor_id);
127 if (sensor_it == sensors.end())
128 return {};
129
130 assert(signal_it->second != nullptr);
131 assert(sensor_it->second != nullptr);
132
133 return {{*signal_it->second, *sensor_it->second}};
134}
135
136} // namespace echomap
Audio signal class specification.
Project(std::string_view project_name={})
Creates a new named Project.
Definition Project.cpp:15
const Sensor * add_sensor(std::unique_ptr< Sensor > &&sensor)
Transfers ownership of a Sensor into the Project.
Definition Project.cpp:35
const Signal * add_signal(std::shared_ptr< Signal > &&signal)
Transfers ownership of a Signal into the Project.
Definition Project.cpp:24
std::optional< std::pair< const Signal &, const Sensor & > > resolve_pair(id_type signal_id, id_type sensor_id) const
Convenience function to simultaneously resolve observing references to a Signal and a Sensor from the...
Definition Project.cpp:112
BidirectionalUnorderedMapping< id_type, id_type > requested_channel_mapping
Mapping between Signal objects and Sensor objects (identified by their numerical IDs).
Definition Project.hpp:215
size_t get_sensors_count() const noexcept
Checks if any Sensor objects are owned by the Project.
Definition Project.cpp:82
void add_association(const Signal &signal, const Sensor &sensor)
Creates a new association between a Signal and Sensor.
Definition Project.cpp:46
Sensor & get_mutable_sensor(id_type sensor_id)
Retrieve a mutable reference to the Sensor with the given ID.
Definition Project.cpp:98
A single channel of discretely sampled audio data.
Definition Signal.hpp:40
T format(T... args)
The main EchoMap outermost namespace for all non-exported symbols.