EchoMap
2026-07-25 6d3977c
An experimental cross-platform digital signal processing application for sound-source localisation.
Toggle main menu visibility
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
12
namespace
echomap
13
{
14
15
Project::Project
(
16
const
std::string_view
project_name
17
) :
18
Object(project_name)
19
{
20
}
21
22
Project::~Project() =
default
;
23
24
const
Signal
*
Project::add_signal
(
25
std::shared_ptr<Signal>
&& signal
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
35
const
Sensor
*
Project::add_sensor
(
36
std::unique_ptr<Sensor>
&& sensor
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
46
void
Project::add_association
(
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)
58
throw
std::runtime_error
(
59
std::format
(
60
"Could not associate {} with {}: a component is already mapped."
,
61
signal.get_name(),
62
sensor.get_name()
63
)
64
);
65
}
66
67
void
Project::add_association
(
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)
73
throw
std::runtime_error
(
74
std::format
(
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
82
std::size_t
Project::get_sensors_count
() const noexcept
83
{
84
return
sensors.size();
85
}
86
87
ImPlot3DPoint 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
98
Sensor
&
Project::get_mutable_sensor
(
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
109
std::optional
<
std::pair
<
110
const
Signal
&,
111
const
Sensor
&>>
112
Project::resolve_pair
(
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
Signal.hpp
Audio signal class specification.
std::string_view
echomap::Project
Definition
Project.hpp:26
echomap::Project::Project
Project(std::string_view project_name={})
Creates a new named Project.
Definition
Project.cpp:15
echomap::Project::add_sensor
const Sensor * add_sensor(std::unique_ptr< Sensor > &&sensor)
Transfers ownership of a Sensor into the Project.
Definition
Project.cpp:35
echomap::Project::add_signal
const Signal * add_signal(std::shared_ptr< Signal > &&signal)
Transfers ownership of a Signal into the Project.
Definition
Project.cpp:24
echomap::Project::resolve_pair
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
echomap::Project::requested_channel_mapping
BidirectionalUnorderedMapping< id_type, id_type > requested_channel_mapping
Mapping between Signal objects and Sensor objects (identified by their numerical IDs).
Definition
Project.hpp:215
echomap::Project::get_sensors_count
size_t get_sensors_count() const noexcept
Checks if any Sensor objects are owned by the Project.
Definition
Project.cpp:82
echomap::Project::add_association
void add_association(const Signal &signal, const Sensor &sensor)
Creates a new association between a Signal and Sensor.
Definition
Project.cpp:46
echomap::Project::get_mutable_sensor
Sensor & get_mutable_sensor(id_type sensor_id)
Retrieve a mutable reference to the Sensor with the given ID.
Definition
Project.cpp:98
echomap::Sensor
Definition
Sensor.hpp:16
echomap::Signal
A single channel of discretely sampled audio data.
Definition
Signal.hpp:40
std::format
T format(T... args)
echomap
The main EchoMap outermost namespace for all non-exported symbols.
Definition
ActionController.hpp:20
std::optional
std::pair
std::runtime_error
std::shared_ptr
std::size_t
std::unique_ptr
src
objects
Project.cpp
Generated by
1.17.0