MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Rigs.cpp
Go to the documentation of this file.
1#include "Rigs.hpp"
2
7
15
17
18namespace MayaFlux {
19
20std::shared_ptr<Kriya::SamplingPipeline> create_sampler(
21 const std::string& filepath, uint32_t num_samples, bool truncate,
22 uint32_t channel, uint64_t max_dur_ms)
23{
24 auto stream = get_io_manager()->load_audio_bounded(filepath, num_samples, truncate);
25
26 if (!stream) {
28 "create_sampler: failed to load '{}'", filepath);
29 return nullptr;
30 }
31
32 auto& mgr = *get_buffer_manager();
33 auto& sched = *get_scheduler();
34 const uint32_t buf_size = Config::get_buffer_size();
35
36 auto sampler = std::make_shared<Kriya::SamplingPipeline>(
37 std::move(stream), mgr, sched, channel, buf_size);
38
39 if (max_dur_ms > 0) {
40 sampler->build_for(max_dur_ms);
41 } else {
42 sampler->build();
43 }
44
45 return sampler;
46}
47
48std::shared_ptr<Kriya::SamplingPipeline> create_sampler_from_stream(
49 std::shared_ptr<Kakshya::DynamicSoundStream> stream,
50 uint32_t channel, uint64_t max_dur_ms)
51{
52 if (!stream)
53 return nullptr;
54
55 auto& mgr = *get_buffer_manager();
56 auto& sched = *get_scheduler();
57 const uint32_t buf_size = Config::get_buffer_size();
58
59 auto sampler = std::make_shared<Kriya::SamplingPipeline>(
60 std::move(stream), mgr, sched, channel, buf_size);
61
62 if (max_dur_ms > 0) {
63 sampler->build_for(max_dur_ms);
64 } else {
65 sampler->build();
66 }
67
68 return sampler;
69}
70
71namespace {
72
73 std::vector<std::shared_ptr<Kriya::SamplingPipeline>> samplers_from_stream(
74 const std::shared_ptr<Kakshya::DynamicSoundStream>& stream,
75 uint64_t max_dur_ms, uint32_t max_channels)
76 {
77 const uint32_t ch_count = (max_channels == 0)
79 : std::min(max_channels, stream->get_num_channels());
80
81 std::vector<std::shared_ptr<Kriya::SamplingPipeline>> result;
82 result.reserve(ch_count);
83
84 for (uint32_t i = 0; i < ch_count; ++i)
85 result.push_back(create_sampler_from_stream(stream, i, max_dur_ms));
86
87 return result;
88 }
89
90} // namespace
91
92std::shared_ptr<Kriya::SamplingPipeline> create_sampler(
93 uint32_t num_samples, bool truncate, uint32_t channel, uint64_t max_dur_ms)
94{
95 auto stream = choose_audio_bounded(num_samples, truncate);
96
97 if (!stream) {
99 "create_sampler: no file chosen");
100 return nullptr;
101 }
102
103 return create_sampler_from_stream(std::move(stream), channel, max_dur_ms);
104}
105
106std::vector<std::shared_ptr<Kriya::SamplingPipeline>> create_samplers(
107 const std::string& filepath, uint32_t num_samples, bool truncate,
108 uint64_t max_dur_ms, uint32_t max_channels)
109{
110 auto stream = get_io_manager()->load_audio_bounded(filepath, num_samples, truncate);
111
112 if (!stream) {
114 "create_samplers: failed to load '{}'", filepath);
115 return {};
116 }
117
118 return samplers_from_stream(stream, max_dur_ms, max_channels);
119}
120
121std::vector<std::shared_ptr<Kriya::SamplingPipeline>> create_samplers(
122 uint32_t num_samples, bool truncate, uint64_t max_dur_ms, uint32_t max_channels)
123{
124 auto stream = choose_audio_bounded(num_samples, truncate);
125
126 if (!stream) {
128 "create_samplers: no file chosen");
129 return {};
130 }
131
132 return samplers_from_stream(stream, max_dur_ms, max_channels);
133}
134
136 const std::string& filepath, uint32_t num_samples, bool truncate)
137{
138 auto stream = get_io_manager()->load_audio_bounded(filepath, num_samples, truncate);
139
140 if (!stream) {
142 "create_tap_set: failed to load '{}'", filepath);
143 }
144
145 return create_tap_set_from_stream(std::move(stream));
146}
147
148Kriya::TapSetBuilder create_tap_set(uint32_t num_samples, bool truncate)
149{
150 auto stream = choose_audio_bounded(num_samples, truncate);
151
152 if (!stream) {
154 "create_tap_set: no file chosen");
155 }
156
157 return create_tap_set_from_stream(std::move(stream));
158}
159
161 std::shared_ptr<Kakshya::DynamicSoundStream> stream)
162{
165}
166
167Kriya::ChimeraBuilder create_chimera(std::shared_ptr<Buffers::TextureArrayBuffer> buffer)
168{
170}
171
173 const Kakshya::VideoStreamSpec& spec,
175 std::optional<Portal::Graphics::FitMode> fit)
176{
177 auto array = get_buffer_manager()->create_graphics_buffer<Buffers::TextureArrayBuffer>(
179
180 auto builder = create_chimera(std::move(array));
181 builder.render(std::move(render));
182 return builder;
183}
184
185std::shared_ptr<Buffers::TextureArrayBuffer> create_texture_array(
186 const Kakshya::VideoStreamSpec& spec,
187 const Portal::Graphics::RenderConfig& render,
188 std::optional<Portal::Graphics::FitMode> fit,
189 uint32_t mode)
190{
191 auto array = get_buffer_manager()->create_graphics_buffer<Buffers::TextureArrayBuffer>(
193
194 array->set_mode(mode);
195 array->setup_rendering(render);
196 return array;
197}
198
199std::shared_ptr<Kakshya::DynamicSoundStream> create_ring(double seconds, uint32_t channels)
200{
201 const uint32_t rate = Config::get_sample_rate();
202 const auto capacity = static_cast<uint64_t>(seconds * static_cast<double>(rate));
203
204 if (capacity == 0 || channels == 0) {
206 "create_ring: {} seconds on {} channels is empty", seconds, channels);
207 return nullptr;
208 }
209
210 auto ring = std::make_shared<Kakshya::DynamicSoundStream>(rate, channels);
211 ring->enable_circular_buffer(capacity);
212 return ring;
213}
214
215std::shared_ptr<Kriya::BufferPipeline> record_into(
216 const std::shared_ptr<Kakshya::DynamicSoundStream>& stream,
217 Kriya::CaptureBuilder source, uint32_t channel)
218{
219 if (!stream) {
220 return nullptr;
221 }
222
223 source.for_cycles(1);
224
225 auto pipeline = create_buffer_pipeline();
226 *pipeline >> static_cast<Kriya::BufferOperation>(source)
228 pipeline->execute_buffer_rate();
229
230 return pipeline;
231}
232
233std::shared_ptr<Kriya::BufferPipeline> record_into(
234 const std::shared_ptr<Kakshya::DynamicSoundStream>& stream,
235 const std::shared_ptr<Buffers::AudioBuffer>& buffer, uint32_t channel)
236{
237 if (!buffer) {
238 return nullptr;
239 }
240
242}
243
244std::vector<std::shared_ptr<Kriya::BufferPipeline>> record_into(
245 const std::shared_ptr<Kakshya::DynamicSoundStream>& stream,
246 std::vector<Kriya::CaptureBuilder> sources)
247{
248 std::vector<std::shared_ptr<Kriya::BufferPipeline>> pipelines;
249
250 if (!stream) {
251 return pipelines;
252 }
253
254 pipelines.reserve(sources.size());
255 for (size_t channel = 0; channel < sources.size(); ++channel) {
256 pipelines.push_back(record_into(stream, std::move(sources[channel]), static_cast<uint32_t>(channel)));
257 }
258
259 return pipelines;
260}
261
262std::shared_ptr<Yantra::Vision::VisionWorkflow> create_vision_workflow()
263{
264 return std::make_shared<Yantra::Vision::VisionWorkflow>(
266}
267
268} // namespace MayaFlux
#define MF_ERROR(comp, ctx,...)
Core::GlobalStreamInfo stream
Definition Config.cpp:40
Dialog-backed loading and file-type helpers.
float rate
std::shared_ptr< NetworkGeometryBuffer > buffer
uint32_t mode
Pre-assembled, purpose-built signal flow configurations.
uint32_t channels
void set_mode(uint32_t mode)
Set the mode number passed to the shader.
A TextureBuffer whose image is a stack of layers, composed in one draw.
static BufferOperation route_to_container(std::shared_ptr< Kakshya::DynamicSoundStream > target, uint32_t channel=0)
Create a routing operation to DynamicSoundStream destination.
static CaptureBuilder capture_from(std::shared_ptr< Buffers::AudioBuffer > buffer)
Create a CaptureBuilder for fluent capture configuration.
Fundamental unit of operation in buffer processing pipelines.
Fluent builder interface for constructing BufferCapture configurations.
Definition Capture.hpp:249
Declares the layers of a Chimera, in order, and starts feeding them.
Definition Chimera.hpp:190
Describes a tap set one tap at a time, then starts it.
Definition TapSet.hpp:119
@ GRAPHICS_BACKEND
Standard graphics processing backend configuration.
uint32_t get_buffer_size()
Gets the buffer size from the default engine.
Definition Config.cpp:120
uint32_t get_sample_rate()
Gets the sample rate from the default engine.
Definition Config.cpp:111
@ Configuration
Configuration and parameter updates.
@ FileIO
Filesystem I/O operations.
@ API
MayaFlux/API Wrapper and convenience functions.
std::shared_ptr< Vruta::EventManager > get_event_manager()
Gets the event manager from the default engine.
Definition Chronie.cpp:27
Kriya::ChimeraBuilder create_chimera(std::shared_ptr< Buffers::TextureArrayBuffer > buffer)
Begin assembling the layers of a TextureArrayBuffer from what feeds each.
Definition Rigs.cpp:167
Kriya::TapSetBuilder create_tap_set(const std::string &filepath, uint32_t num_samples, bool truncate)
Begin describing several taps that read one audio file.
Definition Rigs.cpp:135
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:20
std::shared_ptr< Yantra::Vision::VisionWorkflow > create_vision_workflow()
A vision workflow running on the engine's managers.
Definition Rigs.cpp:262
std::shared_ptr< Kakshya::DynamicSoundStream > create_ring(double seconds, uint32_t channels)
Make a circular stream that keeps the most recent seconds of a signal.
Definition Rigs.cpp:199
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:48
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:106
std::shared_ptr< Kriya::BufferPipeline > record_into(const std::shared_ptr< Kakshya::DynamicSoundStream > &stream, Kriya::CaptureBuilder source, uint32_t channel)
Record a signal into one channel of a stream, a block at a time.
Definition Rigs.cpp:215
std::shared_ptr< Kriya::BufferPipeline > create_buffer_pipeline()
Creates a new buffer pipeline instance.
Definition Chronie.cpp:137
std::shared_ptr< Buffers::BufferManager > get_buffer_manager()
Gets the buffer manager from the default engine.
Definition Graph.cpp:148
std::shared_ptr< IO::IOManager > get_io_manager()
Retrieves the global IOManager instance for file loading and buffer management.
Definition Depot.cpp:575
std::shared_ptr< Buffers::TextureArrayBuffer > create_texture_array(const Kakshya::VideoStreamSpec &spec, const Portal::Graphics::RenderConfig &render, std::optional< Portal::Graphics::FitMode > fit, uint32_t mode)
Make a layered texture buffer that draws to a window.
Definition Rigs.cpp:185
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
std::shared_ptr< Vruta::TaskScheduler > get_scheduler()
Gets the task scheduler from the default engine.
Definition Chronie.cpp:22
Kriya::TapSetBuilder create_tap_set_from_stream(std::shared_ptr< Kakshya::DynamicSoundStream > stream)
Begin describing several taps that read an existing DynamicSoundStream.
Definition Rigs.cpp:160
Main namespace for the Maya Flux audio engine.
Definition Runtime.cpp:12
uint32_t get_num_channels() const
Retrieves the number of output channels.
Describes a DynamicVideoStream so it can be built by designated initializer.
Unified rendering configuration for graphics buffers.