20namespace fs = std::filesystem;
26 bool require_portal(
const char* caller)
30 "{}: Portal::System not initialized", caller);
36 const std::vector<Portal::System::Dialog::ChooserFilter> k_audio_open_filters {
37 { .name =
"Audio", .extensions = {
"wav",
"aiff",
"aif",
"flac",
"ogg",
"mp3",
"m4a",
"wma" } },
38 { .name =
"All Files", .extensions = {
"*" } }
41 const std::vector<Portal::System::Dialog::ChooserFilter> k_audio_save_filters {
42 { .name =
"Audio", .extensions = {
"wav",
"flac",
"ogg",
"mp3" } },
43 { .name =
"All Files", .extensions = {
"*" } }
46 const std::vector<Portal::System::Dialog::ChooserFilter> k_video_filters {
47 { .name =
"Video", .extensions = {
"mp4",
"mkv",
"mov",
"webm",
"avi" } },
48 { .name =
"All Files", .extensions = {
"*" } }
51 const std::vector<Portal::System::Dialog::ChooserFilter> k_image_filters {
52 { .name =
"Image", .extensions = {
"png",
"jpg",
"jpeg",
"bmp",
"tga",
"psd",
"gif",
"hdr",
"pic",
"pnm",
"exr" } },
53 { .name =
"All Files", .extensions = {
"*" } }
56 const std::vector<Portal::System::Dialog::ChooserFilter> k_mesh_filters {
57 { .name =
"3D Model", .extensions = {
"glb",
"gltf",
"fbx",
"obj",
"ply",
"stl",
"dae" } },
58 { .name =
"All Files", .extensions = {
"*" } }
61 const std::vector<Portal::System::Dialog::ChooserFilter> k_image_save_filters {
62 { .name =
"Image", .extensions = {
"png",
"jpg",
"jpeg",
"bmp",
"tga",
"exr",
"hdr" } },
63 { .name =
"All Files", .extensions = {
"*" } }
68 if (!fs::exists(filepath) || !fs::is_regular_file(filepath))
71 auto ext = filepath.extension().string();
75 std::ranges::transform(ext, ext.begin(), [](
unsigned char c) { return std::tolower(c); });
76 const std::string_view bare { ext.data() + 1, ext.size() - 1 };
78 return std::ranges::any_of(filter.extensions,
79 [&](
const std::string& e) { return e == bare; });
87 const std::shared_ptr<Kakshya::SoundFileContainer>& container)
91 "prepare_audio_buffers failed: null container");
95 uint32_t num_channels = container->get_num_channels();
96 std::vector<std::shared_ptr<Buffers::SoundContainerBuffer>> created_buffers;
98 for (uint32_t ch = 0; ch < num_channels; ++ch) {
99 auto buf = std::make_shared<Buffers::SoundContainerBuffer>(
102 created_buffers.push_back(std::move(buf));
105 return created_buffers;
110 return check_extension(filepath, k_image_filters[0]);
115 return check_extension(filepath, k_audio_open_filters[0]);
124 if (!require_portal(
"choose_audio"))
127 return Portal::System::Dialog::open_file<std::shared_ptr<Kakshya::SoundFileContainer>>(
128 [](
const fs::path& p) {
return get_io_manager()->load_audio(p.string()); },
130 k_audio_open_filters);
135 if (!require_portal(
"choose_video"))
138 return Portal::System::Dialog::open_file<std::shared_ptr<Kakshya::VideoFileContainer>>(
139 [](
const fs::path& p) {
return get_io_manager()->load_video(p.string()); },
146 if (!require_portal(
"choose_image"))
149 return Portal::System::Dialog::open_file<std::shared_ptr<Buffers::TextureBuffer>>(
150 [](
const fs::path& p) {
return get_io_manager()->load_image(p.string()); },
157 if (!require_portal(
"choose_mesh"))
160 return Portal::System::Dialog::open_file<std::vector<std::shared_ptr<Buffers::MeshBuffer>>>(
161 [](
const fs::path& p) {
return get_io_manager()->load_mesh(p.string()); },
168 if (!require_portal(
"choose_mesh_network"))
171 return Portal::System::Dialog::open_file<std::shared_ptr<Nodes::Network::MeshNetwork>>(
172 [r = std::move(resolver)](
const fs::path& p)
mutable {
173 return get_io_manager()->load_mesh_network(p.string(), std::move(r));
184 const std::shared_ptr<Kakshya::SoundStreamContainer>& container,
185 const std::string& suggested_name)
187 if (!require_portal(
"save_audio"))
193 "save_audio: IOManager unavailable");
197 return Portal::System::Dialog::save_file<bool>(
198 [&iom, &container](
const fs::path& p) {
199 iom->write(container, p.string());
204 k_audio_save_filters);
208 const std::shared_ptr<Buffers::TextureBuffer>& buffer,
209 const std::string& suggested_name)
211 if (!require_portal(
"save_image"))
217 "save_image: IOManager unavailable");
221 return Portal::System::Dialog::save_file<bool>(
222 [&iom, &buffer](
const fs::path& p) {
227 k_image_save_filters);
231 const std::shared_ptr<Buffers::TextureBuffer>& buffer,
232 const std::string& suggested_name,
235 if (!require_portal(
"save_image"))
241 "save_image: IOManager unavailable");
245 return Portal::System::Dialog::save_file<bool>(
246 [&iom, &buffer, &options](
const fs::path& p) {
247 return iom->save_image(buffer, p.string(), options);
251 k_image_save_filters);
262 "Attempted to access IOManager before engine initialization");
#define MF_ERROR(comp, ctx,...)
Core engine lifecycle and configuration API.
Audio file loading and container management API.
std::shared_ptr< IO::IOManager > get_io_manager()
Gets the IO manager.
uint32_t get_buffer_size()
Gets the buffer size from the default engine.
SystemDialogError
Failure modes for OS dialog operations.
std::function< std::shared_ptr< Core::VKImage >(const std::string &)> TextureResolver
Callable that maps a raw material texture path to a GPU image.
@ Runtime
General runtime operations (default fallback)
@ API
MayaFlux/API Wrapper and convenience functions.
Core::SystemFileFilter ChooserFilter
A named group of accepted file extensions.
bool is_initialized()
Return true if Portal::System has been initialized.
bool is_engine_configured()
Checks if the default engine has currently accepted all configurations and initialized all managers.
bool is_image(const fs::path &filepath)
std::shared_ptr< Kakshya::VideoFileContainer > choose_video()
Present a native open-file dialog filtered to video formats and load the chosen file via IOManager::l...
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...
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...
bool is_audio(const fs::path &filepath)
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...
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...
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().
Core::Engine & get_context()
Gets the default engine instance.
std::shared_ptr< IO::IOManager > get_io_manager()
Retrieves the global IOManager instance for file loading and buffer management.
std::shared_ptr< Buffers::TextureBuffer > choose_image()
Present a native open-file dialog filtered to image formats and load the chosen file via IOManager::l...
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.
Main namespace for the Maya Flux audio engine.
Configuration for image writing.