MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Depot.hpp
Go to the documentation of this file.
1#pragma once
2
4
5/**
6 * @file API/Depot.hpp
7 * @brief Dialog-backed loading and file-type helpers
8 *
9 * This header provides the public API for working with IOManager,
10 * container creation, and file type checking within the MayaFlux engine.
11 * It includes:
12 * - `create_container<ContainerType>(args...)`: Template function to create signal source containers.
13 * - `is_audio(filepath)`, `is_image(filepath)`, and
14 * `is_composite(filepath)`: Check supported file categories.
15 * - `get_io_manager()`: Access the global IOManager instance for file loading and buffer management.
16 */
17
18namespace MayaFlux {
19
20namespace Core {
21 class VKImage;
22}
23
24namespace IO {
25 class IOManager;
26 struct VideoLoadConfig;
27 struct ImageWriteOptions;
28 struct VolumeWriteOptions;
29 struct ModelWriteOptions;
30 struct SpatialCaptureSource;
31 using TextureResolver = std::function<std::shared_ptr<Core::VKImage>(const std::string&)>;
32}
33
34namespace Kakshya {
35 class CameraContainer;
37 class CompositeLayout;
44}
45
46namespace Buffers {
49 class TextureBuffer;
50 class MeshBuffer;
51 class VolumeGridBuffer;
52}
53
54namespace Nodes::Network {
55 class MeshNetwork;
56}
57
58/**
59 * @brief creates a new container of the specified type
60 * @tparam ContainerType Type of container to create (must be derived from SignalSourceContainer)
61 * @tparam Args Constructor argument types
62 * @param args Constructor arguments for the container
63 * @return Shared pointer to the created container
64 */
65template <typename ContainerType, typename... Args>
66 requires std::derived_from<ContainerType, Kakshya::SignalSourceContainer>
67auto create_container(Args&&... args) -> std::shared_ptr<ContainerType>
68{
69 return std::make_shared<ContainerType>(std::forward<Args>(args)...);
70}
71
72/**
73 * @brief Constructs and initializes per-channel SoundContainerBuffers without registering them.
74 * @param container Source container.
75 * @return One buffer per channel, unregistered, ready for manual routing.
76 */
77MAYAFLUX_API std::vector<std::shared_ptr<Buffers::SoundContainerBuffer>>
78prepare_audio_buffers(const std::shared_ptr<Kakshya::SoundFileContainer>& container);
79
80/**
81 * @brief Checks if the given file is an audio file based on its extension
82 * @param filepath Path to the file to check
83 * @return true if the file is recognized as an audio file, false otherwise
84 */
85MAYAFLUX_API bool is_audio(const std::filesystem::path& filepath);
86
87/**
88 * @brief Checks if the given file is an image file based on its extension
89 * @param filepath Path to the file to check
90 * @return true if the file is recognized as an image file, false otherwise
91 */
92MAYAFLUX_API bool is_image(const std::filesystem::path& filepath);
93
94/**
95 * @brief Check whether an existing file has a supported Composite format.
96 * @param filepath Path to a CSV or TSV file.
97 * @return True for an existing regular file with a supported extension.
98 */
99MAYAFLUX_API bool is_composite(const std::filesystem::path& filepath);
100
101/**
102 * @brief The buffer a video or camera container was hooked to.
103 *
104 * Hooking happens through `| Graphics` or IOManager::hook_*. Returns nullptr
105 * when the container has not been hooked.
106 */
107MAYAFLUX_API std::shared_ptr<Buffers::VideoContainerBuffer> get_associated_buffer(
108 const std::shared_ptr<Kakshya::VideoStreamContainer>& container);
109
110/**
111 * @brief The per-channel buffers an audio container was hooked to.
112 *
113 * Empty when the container has not been hooked.
114 */
115MAYAFLUX_API std::vector<std::shared_ptr<Buffers::SoundContainerBuffer>> get_associated_buffers(
116 const std::shared_ptr<Kakshya::SoundFileContainer>& container);
117
118/**
119 * @brief The audio buffers of a video file's extracted sound track.
120 *
121 * Empty when the video was loaded without VideoReadOptions::EXTRACT_AUDIO,
122 * has no audio track, or has not been hooked.
123 */
124MAYAFLUX_API std::vector<std::shared_ptr<Buffers::SoundContainerBuffer>> get_associated_buffers(
125 const std::shared_ptr<Kakshya::VideoFileContainer>& container);
126
127// ─────────────────────────────────────────────────────────────────────────
128// Dialog-backed load — open
129// ─────────────────────────────────────────────────────────────────────────
130
131/**
132 * @brief Present a native open-file dialog filtered to audio formats and load
133 * the chosen file via IOManager::load_audio().
134 *
135 * Blocks until the user confirms or cancels. Returns nullptr on cancellation,
136 * backend error, or if Portal::System is not initialized.
137 */
138MAYAFLUX_API std::shared_ptr<Kakshya::SoundFileContainer> choose_audio();
139
140/**
141 * @brief Present a native open-file dialog filtered to audio formats and load
142 * the chosen file via IOManager::load_audio_bounded().
143 *
144 * Blocks until the user confirms or cancels. Returns nullptr on cancellation,
145 * backend error, or if Portal::System is not initialized.
146 *
147 * @param max_frames Upper bound on frame count. 0 loads five seconds.
148 * @param truncate If true, truncate files longer than max_frames.
149 */
150MAYAFLUX_API std::shared_ptr<Kakshya::DynamicSoundStream> choose_audio_bounded(
151 uint64_t max_frames = 0, bool truncate = false);
152
153/**
154 * @brief Present a native open-file dialog filtered to video formats and load
155 * the chosen file via IOManager::load_video(path, config).
156 *
157 * Returns IO::VideoLoadResult: the video container, then its audio. With
158 * VideoReadOptions::EXTRACT_AUDIO in config.video_options the audio track is
159 * decoded and returned; otherwise, or for a file with no audio track, the audio
160 * is nullptr.
161 *
162 * Blocks until the user confirms or cancels. Both are nullptr on cancellation,
163 * backend error, or if Portal::System is not initialized.
164 *
165 * @param config Load options forwarded to IOManager::load_video.
166 */
167MAYAFLUX_API std::pair<std::shared_ptr<Kakshya::VideoFileContainer>, std::shared_ptr<Kakshya::SoundFileContainer>>
168choose_video(const IO::VideoLoadConfig& config);
169
170/**
171 * @brief Let the user pick a camera, and optionally a capture mode, then open
172 * it via IOManager::open_camera().
173 *
174 * The pickers are Portal::Forma windows driven by the engine. Blocks until
175 * the user chooses or closes a window. Returns the opened container, ready for
176 * IOManager::hook_camera_to_buffer(), or nullptr on cancellation, when no
177 * camera is found, or if the camera fails to open. Portal::Forma must be
178 * initialized and the engine running.
179 *
180 * Modes come from the camera source's presets. A mode is a request: the
181 * source falls back to the nearest mode the device accepts.
182 *
183 * @param choose_mode If false, skip the mode picker and open with the
184 * default CameraConfig size and frame rate.
185 */
186MAYAFLUX_API std::shared_ptr<Kakshya::CameraContainer> choose_camera(
187 bool choose_mode = true);
188
189/**
190 * @brief Present a native open-file dialog filtered to image formats and load
191 * the chosen file via IOManager::load_image().
192 *
193 * Blocks until the user confirms or cancels. Returns nullptr on cancellation,
194 * backend error, or if Portal::System is not initialized.
195 * @param desired_channels Channel count passed to ImageReader (0 keeps the source layout).
196 * @param region Optional source-pixel rectangle with inclusive end coordinates.
197 */
198MAYAFLUX_API std::shared_ptr<Buffers::TextureBuffer> choose_image(
199 int desired_channels = 4,
200 std::optional<Kakshya::Region> region = std::nullopt);
201
202/**
203 * @brief Choose a CSV or TSV file and load it as a CompositeContainer.
204 *
205 * Every field is UTF-8 text. For bounded reading of large files, use
206 * IOManager directly.
207 *
208 * @return Loaded container, or nullptr on cancellation or failure.
209 */
210MAYAFLUX_API std::shared_ptr<Kakshya::CompositeContainer> choose_composite();
211
212/**
213 * @brief Choose a CSV or TSV file and load it with an exact field layout.
214 *
215 * Mirrors IOManager::load_composite(path, layout, batch_size).
216 *
217 * @param layout Field layout for typed CSV/TSV values.
218 * @param batch_size Container materialization batch size.
219 * @return Loaded container, or nullptr on cancellation or failure.
220 */
221MAYAFLUX_API std::shared_ptr<Kakshya::CompositeContainer> choose_composite(
222 const Kakshya::CompositeLayout& layout, size_t batch_size = 1);
223
224/**
225 * @brief Present a native open-file dialog filtered to 3D model formats and load
226 * the chosen file via IOManager::load_mesh().
227 *
228 * Blocks until the user confirms or cancels. Returns an empty vector on
229 * cancellation, backend error, or if Portal::System is not initialized.
230 */
231MAYAFLUX_API std::vector<std::shared_ptr<Buffers::MeshBuffer>> choose_mesh();
232
233/**
234 * @brief Present a native open-file dialog filtered to 3D model formats and load
235 * the chosen file as a MeshNetwork via IOManager::load_mesh_network().
236 *
237 * @param resolver Optional texture resolver; null uses the IOManager default.
238 *
239 * Blocks until the user confirms or cancels. Returns nullptr on cancellation,
240 * backend error, or if Portal::System is not initialized.
241 */
242MAYAFLUX_API std::shared_ptr<Nodes::Network::MeshNetwork>
243choose_mesh_network(IO::TextureResolver resolver = nullptr);
244
245/**
246 * @brief Present a native open-file dialog filtered to volume formats and
247 * load the chosen file via IOManager::load_volume().
248 *
249 * Blocks until the user confirms or cancels. Returns nullptr on cancellation,
250 * backend error, or if Portal::System is not initialized.
251 */
252MAYAFLUX_API std::shared_ptr<Buffers::VolumeGridBuffer> choose_volume();
253
254// ─────────────────────────────────────────────────────────────────────────
255// Dialog-backed save
256// ─────────────────────────────────────────────────────────────────────────
257
258/**
259 * @brief Present a native save-file dialog and write @p container to the
260 * chosen path via IOManager::write().
261 *
262 * Blocks until the user confirms or cancels. The encode task is queued
263 * asynchronously; this function returns once the path is chosen and the
264 * task is enqueued. Returns false on cancellation, backend error, or if
265 * Portal::System is not initialized.
266 *
267 * @param container Source container to encode.
268 * @param suggested_name Filename pre-filled in the dialog name field.
269 */
270MAYAFLUX_API bool save_audio(
271 const std::shared_ptr<Kakshya::SoundStreamContainer>& container,
272 const std::string& suggested_name = "output.wav");
273
274/**
275 * @brief Present a native save-file dialog filtered to image formats and save
276 * @p buffer to the chosen path via IOManager::save_image().
277 *
278 * Blocks until the user confirms or cancels. The encode task is queued
279 * asynchronously. Returns false on cancellation, backend error, or if
280 * Portal::System is not initialized.
281 *
282 * @param buffer Source TextureBuffer to encode.
283 * @param suggested_name Filename pre-filled in the dialog name field.
284 */
285MAYAFLUX_API bool save_image(
286 const std::shared_ptr<Buffers::TextureBuffer>& buffer,
287 const std::string& suggested_name = "output.png");
288
289/**
290 * @brief Present a native save-file dialog filtered to image formats and save
291 * @p buffer to the chosen path via IOManager::save_image().
292 *
293 * Blocks until the user confirms or cancels. The encode task is queued
294 * asynchronously. Returns false on cancellation, backend error, or if
295 * Portal::System is not initialized.
296 *
297 * @param buffer Source TextureBuffer to encode.
298 * @param suggested_name Filename pre-filled in the dialog name field.
299 * @param options Format-specific writer options forwarded to IOManager.
300 */
301MAYAFLUX_API bool save_image(
302 const std::shared_ptr<Buffers::TextureBuffer>& buffer,
303 const std::string& suggested_name,
304 const IO::ImageWriteOptions& options);
305
306/**
307 * @brief Choose a CSV or TSV destination and save a CompositeContainer.
308 *
309 * The dialog and write are synchronous. Returns false on cancellation,
310 * backend or write failure, or if Portal::System is not initialized.
311 *
312 * @param container Source container to encode.
313 * @param suggested_name Filename pre-filled in the dialog.
314 * @return True only when the complete file was written successfully.
315 */
316MAYAFLUX_API bool save_composite(
317 const std::shared_ptr<Kakshya::CompositeContainer>& container,
318 const std::string& suggested_name = "output.csv");
319
320/**
321 * @brief Present a native save-file dialog filtered to 3D model formats and
322 * save @p buffer to the chosen path via IOManager::save_mesh().
323 *
324 * Blocks until the user confirms or cancels. Synchronous: MeshBuffer's
325 * mesh data is always CPU-resident, so there is no download step to queue,
326 * unlike save_image/save_volume. Returns false on cancellation, backend
327 * error, or if Portal::System is not initialized.
328 *
329 * @param buffer Source MeshBuffer to encode.
330 * @param suggested_name Filename pre-filled in the dialog name field.
331 */
332MAYAFLUX_API bool save_mesh(
333 const std::shared_ptr<Buffers::MeshBuffer>& buffer,
334 const std::string& suggested_name = "output.gltf");
335
336/**
337 * @brief Present a native save-file dialog filtered to 3D model formats and
338 * save @p buffer to the chosen path via IOManager::save_mesh().
339 *
340 * @param buffer Source MeshBuffer to encode.
341 * @param suggested_name Filename pre-filled in the dialog name field.
342 * @param options Format-specific writer options forwarded to IOManager.
343 */
344MAYAFLUX_API bool save_mesh(
345 const std::shared_ptr<Buffers::MeshBuffer>& buffer,
346 const std::string& suggested_name,
347 const IO::ModelWriteOptions& options);
348
349/**
350 * @brief Present a native save-file dialog filtered to 3D model formats and
351 * save @p network to the chosen path via IOManager::save_mesh().
352 *
353 * Works directly on the MeshNetwork returned by choose_mesh_network(),
354 * whether or not it has ever been wrapped in a MeshNetworkBuffer or
355 * rendered: slot data lives on the network's own MeshWriterNodes. Each
356 * slot's vertices are baked into world space from its current
357 * world_transform, so an exploded or rotated network exports in the pose
358 * it is actually in. Blocks until the user confirms or cancels. Returns
359 * false on cancellation, backend error, or if Portal::System is not
360 * initialized.
361 *
362 * @param network Source MeshNetwork to encode.
363 * @param suggested_name Filename pre-filled in the dialog name field.
364 */
365MAYAFLUX_API bool save_mesh(
366 const std::shared_ptr<Nodes::Network::MeshNetwork>& network,
367 const std::string& suggested_name = "output.gltf");
368
369/**
370 * @brief Present a native save-file dialog filtered to 3D model formats and
371 * save @p network to the chosen path via IOManager::save_mesh().
372 *
373 * @param network Source MeshNetwork to encode.
374 * @param suggested_name Filename pre-filled in the dialog name field.
375 * @param options Format-specific writer options forwarded to IOManager.
376 */
377MAYAFLUX_API bool save_mesh(
378 const std::shared_ptr<Nodes::Network::MeshNetwork>& network,
379 const std::string& suggested_name,
380 const IO::ModelWriteOptions& options);
381
382/**
383 * @brief Present a native save-file dialog filtered to volume formats and save
384 * @p volume to the chosen path via IOManager::save_volume().
385 *
386 * Blocks until the user confirms or cancels. The download and encode task
387 * are queued asynchronously; this function returns once the path is chosen
388 * and the task is enqueued. Returns false on cancellation, backend error,
389 * or if Portal::System is not initialized.
390 *
391 * @param volume Source VolumeGridBuffer to download and encode.
392 * @param suggested_name Filename pre-filled in the dialog name field.
393 */
394MAYAFLUX_API bool save_volume(
395 const std::shared_ptr<Buffers::VolumeGridBuffer>& volume,
396 const std::string& suggested_name = "output.vdb");
397
398/**
399 * @brief Present a native save-file dialog filtered to volume formats and save
400 * @p volume to the chosen path via IOManager::save_volume().
401 *
402 * Blocks until the user confirms or cancels. The download and encode task
403 * are queued asynchronously. Returns false on cancellation, backend error,
404 * or if Portal::System is not initialized.
405 *
406 * @param volume Source VolumeGridBuffer to download and encode.
407 * @param suggested_name Filename pre-filled in the dialog name field.
408 * @param options Writer options forwarded to IOManager.
409 */
410MAYAFLUX_API bool save_volume(
411 const std::shared_ptr<Buffers::VolumeGridBuffer>& volume,
412 const std::string& suggested_name,
413 const IO::VolumeWriteOptions& options);
414
415/**
416 * @brief Present a native save-file dialog filtered to Alembic and write
417 * every source once via IOManager::save_spatial_snapshot().
418 *
419 * Blocks until the user confirms or cancels. The write itself is queued
420 * asynchronously; this function returns once the path is chosen and the
421 * task is enqueued. Returns false on cancellation, backend error, or if
422 * Portal::System is not initialized.
423 *
424 * @param sources Streams to write once. Build with
425 * IO::make_network_geometry_source() or a
426 * hand-written IO::SpatialCaptureSource.
427 * @param suggested_name Filename pre-filled in the dialog name field.
428 */
429MAYAFLUX_API bool save_spatial(
430 std::vector<IO::SpatialCaptureSource> sources,
431 const std::string& suggested_name = "output.abc");
432
433/**
434 * @brief Retrieves the global IOManager instance for file loading and buffer management
435 * @return Shared pointer to the IOManager instance
436 *
437 * Provides access to the central IOManager responsible for all file loading operations,
438 * container management, and buffer integration. This is the primary interface for
439 * performing file I/O tasks within the MayaFlux engine.
440 */
441MAYAFLUX_API std::shared_ptr<IO::IOManager> get_io_manager();
442
443}
Core::GlobalNetworkConfig network
Definition Config.cpp:43
std::shared_ptr< NetworkGeometryBuffer > buffer
VKBuffer subclass that owns a MeshData and manages its GPU upload.
AudioBuffer implementation backed by a StreamContainer.
A hybrid buffer managing both a textured quad geometry and its pixel data.
TextureBuffer implementation backed by a VideoStreamContainer.
GPU-resident state for multi-field simulations evaluated over a fixed 3D topology: incompressible flu...
Single-slot live video container for camera device streams.
Owns composite data and a bounded, independently owned window.
Shared field description and byte layout for a CompositeArray.
Definition Composite.hpp:52
Dynamic capacity streaming audio container with automatic resizing and circular buffering.
Data-driven interface for managing arbitrary processable signal sources.
File-backed audio container with complete streaming functionality.
Concrete base implementation for streaming audio containers.
File-backed video container — semantic marker over VideoStreamContainer.
Concrete base implementation for streaming video containers.
NodeNetwork subclass whose nodes are named, hierarchically transformable mesh slots.
std::function< std::shared_ptr< Core::VKImage >(const std::string &)> TextureResolver
Callable that maps a raw material texture path to a GPU image.
Definition Depot.hpp:31
@ Core
Core engine, backend, subsystems.
@ IO
Networking, file handling, streaming.
std::shared_ptr< Buffers::TextureBuffer > choose_image(int desired_channels, std::optional< Kakshya::Region > region)
Present a native open-file dialog filtered to image formats and load the chosen file via IOManager::l...
Definition Depot.cpp:228
bool is_image(const fs::path &filepath)
Definition Depot.cpp:136
bool save_volume(const std::shared_ptr< Buffers::VolumeGridBuffer > &volume, const std::string &suggested_name)
Present a native save-file dialog filtered to volume formats and save volume to the chosen path via I...
Definition Depot.cpp:503
std::shared_ptr< Buffers::VideoContainerBuffer > get_associated_buffer(const std::shared_ptr< Kakshya::VideoStreamContainer > &container)
The buffer a video or camera container was hooked to.
Definition Depot.cpp:151
bool save_image(const std::shared_ptr< Buffers::TextureBuffer > &buffer, const std::string &suggested_name)
Present a native save-file dialog filtered to image formats and save buffer to the chosen path via IO...
Definition Depot.cpp:371
std::shared_ptr< Nodes::Network::MeshNetwork > choose_mesh_network(IO::TextureResolver resolver)
Present a native open-file dialog filtered to 3D model formats and load the chosen file as a MeshNetw...
Definition Depot.cpp:278
bool save_spatial(std::vector< IO::SpatialCaptureSource > sources, const std::string &suggested_name)
Present a native save-file dialog filtered to Alembic and write every source once via IOManager::save...
Definition Depot.cpp:550
bool is_audio(const fs::path &filepath)
Definition Depot.cpp:141
bool save_mesh(const std::shared_ptr< Buffers::MeshBuffer > &buffer, const std::string &suggested_name)
Present a native save-file dialog filtered to 3D model formats and save buffer to the chosen path via...
Definition Depot.cpp:441
std::vector< std::shared_ptr< Buffers::MeshBuffer > > choose_mesh()
Present a native open-file dialog filtered to 3D model formats and load the chosen file via IOManager...
Definition Depot.cpp:267
std::shared_ptr< Kakshya::SoundFileContainer > choose_audio()
Present a native open-file dialog filtered to audio formats and load the chosen file via IOManager::l...
Definition Depot.cpp:193
std::shared_ptr< Kakshya::CompositeContainer > choose_composite()
Choose a CSV or TSV file and load it as a CompositeContainer.
Definition Depot.cpp:242
auto create_container(Args &&... args) -> std::shared_ptr< ContainerType >
creates a new container of the specified type
Definition Depot.hpp:67
std::shared_ptr< Kakshya::CameraContainer > choose_camera(bool choose_mode)
Let the user pick a camera, and optionally a capture mode, then open it via IOManager::open_camera().
Definition Depot.cpp:302
std::shared_ptr< Buffers::VolumeGridBuffer > choose_volume()
Present a native open-file dialog filtered to volume formats and load the chosen file via IOManager::...
Definition Depot.cpp:291
std::vector< std::shared_ptr< Buffers::SoundContainerBuffer > > get_associated_buffers(const std::shared_ptr< Kakshya::SoundFileContainer > &container)
The per-channel buffers an audio container was hooked to.
Definition Depot.cpp:166
bool save_audio(const std::shared_ptr< Kakshya::SoundStreamContainer > &container, const std::string &suggested_name)
Present a native save-file dialog and write container to the chosen path via IOManager::write().
Definition Depot.cpp:347
bool save_composite(const std::shared_ptr< Kakshya::CompositeContainer > &container, const std::string &suggested_name)
Choose a CSV or TSV destination and save a CompositeContainer.
Definition Depot.cpp:418
std::shared_ptr< IO::IOManager > get_io_manager()
Retrieves the global IOManager instance for file loading and buffer management.
Definition Depot.cpp:575
std::vector< std::shared_ptr< Buffers::SoundContainerBuffer > > prepare_audio_buffers(const std::shared_ptr< Kakshya::SoundFileContainer > &container)
Constructs and initializes per-channel SoundContainerBuffers without registering them.
Definition Depot.cpp:114
bool is_composite(const fs::path &filepath)
Definition Depot.cpp:146
std::shared_ptr< Kakshya::DynamicSoundStream > choose_audio_bounded(uint64_t max_frames, bool truncate)
Present a native open-file dialog filtered to audio formats and load the chosen file via IOManager::l...
Definition Depot.cpp:204
IO::VideoLoadResult choose_video(const IO::VideoLoadConfig &config)
Present a native open-file dialog filtered to video formats and load the chosen file via IOManager::l...
Definition Depot.cpp:217
Main namespace for the Maya Flux audio engine.
Definition Runtime.cpp:12
Configuration for image writing.
Configuration for model writing.
Configuration for volume writing.