MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
BufferQuery.cpp
Go to the documentation of this file.
1#include "Inspector.hpp"
2
8
11
13
15
16// -----------------------------------------------------------------------------
17// Single buffer + processing chain
18// -----------------------------------------------------------------------------
19
21 const std::shared_ptr<Buffers::Buffer>& buf,
22 Surface& surface,
23 LayoutCursor& cursor,
24 float x_min, float x_max, float row_h, int depth)
25{
26 if (!buf)
27 return {};
28
29 const float ind = x_min + static_cast<float>(depth) * k_inspect_indent;
30 const std::string header_label = Reflect::short_dynamic_type_name(*buf);
31
32 std::vector<EntrySpec> entrys {
33 EntrySpec {
34 .label = "default_proc",
35 .reader = [buf] {
36 auto p = buf->get_default_processor();
37 return p ? std::string(Reflect::short_dynamic_type_name(*p)) : "-";
38 },
39 },
40 };
41
42 auto chain = buf->get_processing_chain();
43 if (chain) {
44 auto pre = chain->get_preprocessor(buf);
45 entrys.push_back(EntrySpec {
46 .label = "pre",
47 .reader = [pre] {
48 return pre ? std::string(Reflect::short_dynamic_type_name(*pre)) : "-";
49 },
50 });
51
52 const auto& processors = chain->get_processors(buf);
53 for (size_t i = 0; i < processors.size(); ++i) {
54 auto p = processors[i];
55 entrys.push_back(EntrySpec {
56 .label = "chain[" + std::to_string(i) + "]",
57 .reader = [p] {
58 return p ? std::string(Reflect::short_dynamic_type_name(*p)) : "-";
59 },
60 });
61 }
62
63 auto post = chain->get_postprocessor(buf);
64 entrys.push_back(EntrySpec {
65 .label = "post",
66 .reader = [post] {
67 return post ? std::string(Reflect::short_dynamic_type_name(*post)) : "-";
68 },
69 });
70
71 auto final_p = chain->get_final_processor(buf);
72 entrys.push_back(EntrySpec {
73 .label = "final",
74 .reader = [final_p] {
75 return final_p ? std::string(Reflect::short_dynamic_type_name(*final_p)) : "-";
76 },
77 });
78 }
79
80 auto hbuf = make_header_buffer(surface.window());
81 auto rbufs = make_row_buffers(surface.window(), entrys.size());
82 auto group = make_entry_group(entrys, header_label, std::move(hbuf), rbufs,
83 surface, cursor, ind, x_max, row_h, false);
84
85 InspectResult result;
86 result.group = std::move(group);
87 return result;
88}
89
90// -----------------------------------------------------------------------------
91// Root audio buffer: single channel
92// -----------------------------------------------------------------------------
93
95 Buffers::ProcessingToken token, uint32_t channel,
96 Surface& surface,
97 LayoutCursor& cursor,
98 float x_min, float x_max, float row_h, int depth)
99{
100 auto root = m_bm.get_root_audio_buffer(token, channel);
101 if (!root)
102 return {};
103
104 const auto children = root->get_child_buffers();
105
106 const float ind = x_min + static_cast<float>(depth) * k_inspect_indent;
107 const std::string header_label = "ch " + std::to_string(channel);
108
109 std::vector<EntrySpec> entrys {
110 EntrySpec {
111 .label = "samples",
112 .reader = [root] { return std::to_string(root->get_num_samples()); },
113 },
114 EntrySpec {
115 .label = "children",
116 .reader = [root] { return std::to_string(root->get_num_children()); },
117 },
118 };
119
120 auto hbuf = make_header_buffer(surface.window());
121 auto rbufs = make_row_buffers(surface.window(), entrys.size());
122 auto group = make_entry_group(entrys, header_label, std::move(hbuf), rbufs,
123 surface, cursor, ind, x_max, row_h, false);
124
125 InspectResult result;
126 result.group = std::move(group);
127
128 auto root_result = buffer(
129 root, surface, cursor,
130 x_min, x_max, row_h, depth + 1);
131 surface.layer().relate(result.group.header.header_id, root_result.group.header.header_id);
132 result.children.push_back(std::move(root_result));
133
134 for (const auto& child : children) {
135 auto child_result = buffer(
136 child, surface, cursor,
137 x_min, x_max, row_h, depth + 2);
138 surface.layer().relate(result.group.header.header_id, child_result.group.header.header_id);
139 result.children.push_back(std::move(child_result));
140 }
141
142 return result;
143}
144
145// -----------------------------------------------------------------------------
146// Root audio buffer: all channels
147// -----------------------------------------------------------------------------
148
151 Surface& surface,
152 LayoutCursor& cursor,
153 float x_min, float x_max, float row_h, int depth)
154{
155 const uint32_t ch_count = m_bm.get_num_channels(token);
156
157 const float ind = x_min + static_cast<float>(depth) * k_inspect_indent;
158 const std::string header_label = std::string(Reflect::enum_to_string(token))
159 + " [" + std::to_string(ch_count) + " ch]";
160
161 auto& bm = m_bm;
162 std::vector<EntrySpec> entrys {
163 EntrySpec {
164 .label = "channels",
165 .reader = [&bm, token] { return std::to_string(bm.get_num_channels(token)); },
166 },
167 };
168
169 auto hbuf = make_header_buffer(surface.window());
170 auto rbufs = make_row_buffers(surface.window(), entrys.size());
171 auto group = make_entry_group(entrys, header_label, std::move(hbuf), rbufs,
172 surface, cursor, ind, x_max, row_h, false);
173
174 InspectResult result;
175 result.group = std::move(group);
176
177 for (uint32_t ch = 0; ch < ch_count; ++ch) {
178 auto ch_result = root_audio_buffer(
179 token, ch,
180 surface, cursor,
181 x_min, x_max, row_h, depth + 1);
182 surface.layer().relate(result.group.header.header_id, ch_result.group.header.header_id);
183 result.children.push_back(std::move(ch_result));
184 }
185
186 return result;
187}
188
189// -----------------------------------------------------------------------------
190// Root graphics buffer
191// -----------------------------------------------------------------------------
192
195 Surface& surface,
196 LayoutCursor& cursor,
197 float x_min, float x_max, float row_h, int depth)
198{
199 auto root = m_bm.get_root_graphics_buffer(token);
200 if (!root)
201 return {};
202
203 const auto children = root->get_child_buffers();
204
205 const float ind = x_min + static_cast<float>(depth) * k_inspect_indent;
206 const std::string header_label = "graphics ["
207 + std::string(Reflect::enum_to_string(token)) + "]";
208
209 std::vector<EntrySpec> entrys {
210 EntrySpec {
211 .label = "vk_buffers",
212 .reader = [root] { return std::to_string(root->get_buffer_count()); },
213 },
214 };
215
216 auto hbuf = make_header_buffer(surface.window());
217 auto rbufs = make_row_buffers(surface.window(), entrys.size());
218 auto group = make_entry_group(entrys, header_label, std::move(hbuf), rbufs,
219 surface, cursor, ind, x_max, row_h, false);
220
221 InspectResult result;
222 result.group = std::move(group);
223
224 auto root_result = buffer(
225 root, surface, cursor,
226 x_min, x_max, row_h, depth + 1);
227 surface.layer().relate(result.group.header.header_id, root_result.group.header.header_id);
228 result.children.push_back(std::move(root_result));
229
230 for (const auto& child : children) {
231 auto child_result = buffer(
232 child, surface, cursor,
233 x_min, x_max, row_h, depth + 2);
234 surface.layer().relate(result.group.header.header_id, child_result.group.header.header_id);
235 result.children.push_back(std::move(child_result));
236 }
237
238 return result;
239}
240
241// -----------------------------------------------------------------------------
242// BufferManager aggregate
243// -----------------------------------------------------------------------------
244
246 Surface& surface,
247 LayoutCursor& cursor,
248 float x_min, float x_max, float row_h)
249{
250 if (m_buffer_result) {
251 return *m_buffer_result;
252 }
253
254 const auto tokens = m_bm.get_active_tokens();
255 const uint32_t in_count = m_bm.get_num_input_channels();
256 const std::string header_label = "BufferManager";
257 auto& bm = m_bm;
258 std::vector<EntrySpec> entrys {
259 EntrySpec {
260 .label = "tokens",
261 .reader = [&bm] { return std::to_string(bm.get_active_tokens().size()); },
262 },
263 EntrySpec {
264 .label = "inputs",
265 .reader = [&bm] { return std::to_string(bm.get_num_input_channels()); },
266 },
267 };
268
269 auto hbuf = make_header_buffer(surface.window());
270 auto rbufs = make_row_buffers(surface.window(), entrys.size());
271
272 auto group = make_entry_group(entrys, header_label, std::move(hbuf), rbufs,
273 surface, cursor, x_min, x_max, row_h, false);
274
275 InspectResult& result = m_buffer_result.emplace();
276 result.group = std::move(group);
277
278 for (const auto tok : tokens) {
281 InspectResult tok_result = is_audio
282 ? root_audio_buffer(tok, surface, cursor, x_min, x_max, row_h, 1)
283 : root_graphics_buffer(tok, surface, cursor, x_min, x_max, row_h, 1);
284 surface.layer().relate(result.group.header.header_id, tok_result.group.header.header_id);
285 result.children.push_back(std::move(tok_result));
286 }
287
288 if (in_count > 0) {
289 const std::string in_label = "inputs [" + std::to_string(in_count) + "]";
290 auto in_hbuf = make_header_buffer(surface.window());
291 auto in_group = make_entry_group({}, in_label, std::move(in_hbuf), {},
292 surface, cursor, x_min + k_inspect_indent, x_max, row_h, false);
293
294 InspectResult in_result;
295 in_result.group = std::move(in_group);
296 surface.layer().relate(result.group.header.header_id, in_result.group.header.header_id);
297
298 for (uint32_t ch = 0; ch < in_count; ++ch) {
299 auto buf = m_bm.get_input_buffer(ch);
300 auto buf_result = buffer(
301 std::dynamic_pointer_cast<Buffers::Buffer>(buf), surface, cursor,
302 x_min, x_max, row_h, 2);
303 surface.layer().relate(in_result.group.header.header_id, buf_result.group.header.header_id);
304 in_result.children.push_back(std::move(buf_result));
305 }
306
307 result.children.push_back(std::move(in_result));
308 }
309
310 return result;
311}
312
313} // namespace MayaFlux::Portal::Forma
std::shared_ptr< NetworkGeometryBuffer > buffer
BufferProcessingChain * chain
uint32_t depth
std::shared_ptr< RootAudioBuffer > get_root_audio_buffer(ProcessingToken token, uint32_t channel=0)
Gets a root buffer for a specific token and channel (audio-specific due to channels)
std::shared_ptr< Buffers::InputAudioBuffer > get_input_buffer(uint32_t channel) const
uint32_t get_num_channels(ProcessingToken token) const
Gets the number of channels for a token (audio-specific)
std::shared_ptr< RootGraphicsBuffer > get_root_graphics_buffer(ProcessingToken token)
Gets a root graphics buffer for a specific token.
std::vector< ProcessingToken > get_active_tokens() const
Gets all currently active processing tokens.
std::shared_ptr< Buffers::FormaBuffer > make_header_buffer(const std::shared_ptr< Core::Window > &window) const
A "text"-slotted buffer, registered with the BufferManager.
Definition Inspector.cpp:11
InspectResult & buffer_manager(Surface &surface, LayoutCursor &cursor, float x_min=-0.95F, float x_max=0.95F, float row_h=0.05F)
Inspect the full BufferManager state across all active tokens.
std::vector< EntryBuffer > make_row_buffers(const std::shared_ptr< Core::Window > &window, size_t count) const
count row targets, slices of one "text"-slotted buffer, for make_entry_group's rows.
Definition Inspector.cpp:24
InspectResult root_audio_buffer(Buffers::ProcessingToken token, uint32_t channel, Surface &surface, LayoutCursor &cursor, float x_min=-0.95F, float x_max=0.95F, float row_h=0.05F, int depth=0)
Inspect the root audio buffer for a specific token and channel.
InspectResult root_graphics_buffer(Buffers::ProcessingToken token, Surface &surface, LayoutCursor &cursor, float x_min=-0.95F, float x_max=0.95F, float row_h=0.05F, int depth=0)
Inspect the root graphics buffer for a token.
InspectResult buffer(const std::shared_ptr< Buffers::Buffer > &buf, Surface &surface, LayoutCursor &cursor, float x_min=-0.95F, float x_max=0.95F, float row_h=0.05F, int depth=0)
Inspect a single Buffer: default processor and full processing chain.
Buffers::BufferManager & m_bm
std::optional< InspectResult > m_buffer_result
bool relate(uint32_t primary_id, uint32_t related_id)
Record that related_id belongs with primary_id.
Definition Layer.cpp:205
Reactive Y-position accumulator for vertical primitive stacking.
const std::shared_ptr< Core::Window > & window() const noexcept
Access the rendering target window.
Definition Surface.hpp:178
Layer & layer() noexcept
Access the spatial registry.
Definition Surface.hpp:159
Named owner of a (Window, Layer, Context) triple: the Forma canvas.
Definition Surface.hpp:121
ProcessingToken
Bitfield enum defining processing characteristics and backend requirements for buffer operations.
@ AUDIO_BACKEND
Standard audio processing backend configuration.
@ AUDIO_PARALLEL
High-performance audio processing with GPU acceleration.
EntryGroup make_entry_group(std::span< const EntrySpec > entrys, std::string_view header_label, FormaTarget header_buf, std::span< const EntryBuffer > row_bufs, Surface &surface, LayoutCursor &cursor, float x_min, float x_max, float row_h, bool initially_open)
Construct a collapsible header followed by N entry rows under it.
Definition Entry.cpp:104
constexpr float k_inspect_indent
constexpr std::string_view enum_to_string(EnumType value) noexcept
Universal enum to string converter using magic_enum (original case)
std::string short_dynamic_type_name(const T &obj) noexcept
Returns the unqualified dynamic type name of obj.
Definition TypeInfo.hpp:95
bool is_audio(const fs::path &filepath)
Definition Depot.cpp:141
uint32_t header_id
Element id of the header strip. Valid after place().
A single entry to display in a EntryGroup body row.
Definition Entry.hpp:29
std::vector< InspectResult > children
Result of an introspect call.