MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Rigs.hpp
Go to the documentation of this file.
1#pragma once
2
3/**
4 * @file API/Rigs.hpp
5 * @brief Pre-assembled, purpose-built signal flow configurations.
6 *
7 * Each function in this file constructs, wires, and returns a fully built
8 * pipeline object ready for immediate use. The caller receives a live rig
9 * with no further assembly required: IO, buffering, scheduling, and output
10 * routing are resolved internally using engine globals.
11 *
12 * These are convenience entry points. Direct construction of the underlying
13 * types (SamplingPipeline, BufferPipeline, etc.) remains available for cases
14 * that require non-default configuration before build().
15 */
16
17namespace MayaFlux {
18
19namespace Kriya {
20 class SamplingPipeline;
21}
22
23namespace Kakshya {
24 class DynamicSoundStream;
25}
26
27/**
28 * @brief Construct a built SamplingPipeline from an audio file.
29 *
30 * Loads the file into a DynamicSoundStream via SoundFileReader::load_bounded,
31 * constructs a SamplingPipeline with engine globals (BufferManager,
32 * TaskScheduler, buffer size), calls build(), and returns the result.
33 *
34 * The returned sampler is ready for play() and play_continuous() calls.
35 * Voice slots are allocated on demand via load().
36 *
37 * @param filepath Path to the audio file (any FFmpeg-supported format).
38 * @param num_samples Number of samples to load from the file (default: 48000 * 5).
39 * @param truncate Truncate stream to num_samples if true (default: true).
40 * @param channel Output channel index (default: 0).
41 * @param max_dur_ms Optional maximum duration to build the pipeline for (in milliseconds).
42 Defaults to 0 which is infinite (the pipeline will run until the sampler is destroyed).
43 * @return Built SamplingPipeline, or nullptr if the file could not be loaded.
44 *
45 * @code
46 * auto kick = MayaFlux::create_sampler("kick.wav");
47 * kick->play(0, kick->slice_from_stream());
48 *
49 * auto pad = MayaFlux::create_sampler("pad.wav");
50 * pad->load(0, pad->slice_from_stream()).speed = 0.5;
51 * pad->play_continuous(0);
52 * @endcode
53 */
54MAYAFLUX_API std::shared_ptr<Kriya::SamplingPipeline> create_sampler(
55 const std::string& filepath, uint32_t num_samples = 48000 * 5, bool truncate = true,
56 uint32_t channel = 0, uint64_t max_dur_ms = 0);
57
58/**
59 * @brief Construct a built SamplingPipeline from an existing DynamicSoundStream.
60 *
61 * Allows multiple SamplingPipeline instances to share a single loaded stream,
62 * one per output channel, without re-reading the file. The stream is typically
63 * obtained from a previously created sampler via get_stream(), or loaded
64 * directly via get_io_manager()->load_audio_bounded().
65 *
66 * @code
67 * auto ch0 = MayaFlux::create_sampler("res/audio.wav", 48000 * 5);
68 * auto ch1 = MayaFlux::create_sampler_from_stream(ch0->get_stream(), 1);
69 * auto ch2 = MayaFlux::create_sampler_from_stream(ch0->get_stream(), 2);
70 * @endcode
71 *
72 * @param stream Loaded DynamicSoundStream to share.
73 * @param channel Output channel index (default: 0).
74 * @param max_dur_ms Optional maximum duration in milliseconds. 0 for infinite.
75 * @return Built SamplingPipeline, or nullptr if stream is null.
76 */
77MAYAFLUX_API std::shared_ptr<Kriya::SamplingPipeline> create_sampler_from_stream(
78 std::shared_ptr<Kakshya::DynamicSoundStream> stream,
79 uint32_t channel = 0, uint64_t max_dur_ms = 0);
80
81/**
82 * @brief Construct one built SamplingPipeline per channel from an audio file.
83 *
84 * Loads the file once into a shared DynamicSoundStream, then constructs one
85 * SamplingPipeline per channel. All pipelines share the same stream with no
86 * redundant IO. max_channels = 0 uses all channels available in the file.
87 *
88 * @code
89 * auto ch = MayaFlux::create_samplers("res/stereo.wav", 48000 * 5);
90 * ch[0]->play(0, ch[0]->slice_from_stream());
91 * ch[1]->play(0, ch[1]->slice_from_stream());
92 * @endcode
93 *
94 * @param filepath Path to the audio file (any FFmpeg-supported format).
95 * @param num_samples Number of samples to load (default: 48000 * 5).
96 * @param truncate Truncate stream to num_samples if true (default: true).
97 * @param max_dur_ms Optional maximum duration in milliseconds. 0 for infinite.
98 * @param max_channels Maximum channels to create pipelines for. 0 = all available.
99 * @return Vector of built SamplingPipelines, one per channel. Empty on load failure.
100 */
101MAYAFLUX_API std::vector<std::shared_ptr<Kriya::SamplingPipeline>> create_samplers(
102 const std::string& filepath, uint32_t num_samples = 48000 * 5, bool truncate = true,
103 uint64_t max_dur_ms = 0, uint32_t max_channels = 0);
104
105} // namespace MayaFlux
uint32_t channel
@ Kakshya
Containers[Signalsource, Stream, File], Regions, DataProcessors.
@ Kriya
Automatable tasks and fluent scheduling api for Nodes and Buffers.
std::shared_ptr< Kriya::SamplingPipeline > create_sampler(const std::string &filepath, uint32_t num_samples, bool truncate, uint32_t channel, uint64_t max_dur_ms)
Construct a built SamplingPipeline from an audio file.
Definition Rigs.cpp:15
std::shared_ptr< Kriya::SamplingPipeline > create_sampler_from_stream(std::shared_ptr< Kakshya::DynamicSoundStream > stream, uint32_t channel, uint64_t max_dur_ms)
Construct a built SamplingPipeline from an existing DynamicSoundStream.
Definition Rigs.cpp:43
std::vector< std::shared_ptr< Kriya::SamplingPipeline > > create_samplers(const std::string &filepath, uint32_t num_samples, bool truncate, uint64_t max_dur_ms, uint32_t max_channels)
Construct one built SamplingPipeline per channel from an audio file.
Definition Rigs.cpp:66
Main namespace for the Maya Flux audio engine.
Definition Runtime.cpp:12