MayaFlux 0.3.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
BufferOperation.cpp
Go to the documentation of this file.
1#include "BufferOperation.hpp"
2
5
8
9namespace MayaFlux::Kriya {
10
12 const std::shared_ptr<Buffers::BufferManager>& buffer_manager,
13 uint32_t input_channel,
15 uint32_t cycle_count)
16{
17 auto input_buffer = std::make_shared<Buffers::AudioBuffer>(input_channel);
18 buffer_manager->register_input_listener(input_buffer, input_channel);
19 buffer_manager->add_buffer(input_buffer, Buffers::ProcessingToken::AUDIO_BACKEND, input_channel);
20
21 BufferCapture capture(input_buffer, mode, cycle_count);
22 if (mode == BufferCapture::CaptureMode::ACCUMULATE && cycle_count == 0) {
23 capture.as_circular(4096);
24 }
25
26 return { BufferOperation::OpType::CAPTURE, std::move(capture) };
27}
28
30 const std::shared_ptr<Buffers::BufferManager>& buffer_manager,
31 uint32_t input_channel)
32{
33 auto input_buffer = std::make_shared<Buffers::AudioBuffer>(input_channel);
34 buffer_manager->register_input_listener(input_buffer, input_channel);
35 buffer_manager->add_buffer(input_buffer, Buffers::ProcessingToken::AUDIO_BACKEND, input_channel);
36 return CaptureBuilder(input_buffer);
37}
38
40 const std::shared_ptr<IO::IOManager>& io_manager,
41 const std::string& filepath,
42 uint32_t channel,
43 uint32_t cycle_count)
44{
45 auto file_container = io_manager->load_audio(filepath);
46 if (!file_container) {
47 error<std::runtime_error>(Journal::Component::Kriya, Journal::Context::AsyncIO, std::source_location::current(),
48 "Failed to load audio file: {}", filepath);
49 }
50
51 auto file_buffer = std::make_shared<Buffers::SoundFileBridge>(channel, file_container);
52 file_buffer->setup_processors(Buffers::ProcessingToken::AUDIO_BACKEND);
53
54 BufferCapture capture(file_buffer,
56 cycle_count);
57
59
60 return { BufferOperation::OpType::CAPTURE, std::move(capture) };
61}
62
64 const std::shared_ptr<IO::IOManager>& io_manager,
65 const std::string& filepath,
66 uint32_t channel)
67{
68 auto file_container = io_manager->load_audio(filepath);
69 if (!file_container) {
70 error<std::runtime_error>(Journal::Component::Kriya, Journal::Context::AsyncIO, std::source_location::current(),
71 "Failed to load audio file: {}", filepath);
72 }
73
74 auto file_buffer = std::make_shared<Buffers::SoundFileBridge>(channel, file_container);
75 file_buffer->setup_processors(Buffers::ProcessingToken::AUDIO_BACKEND);
76
77 return CaptureBuilder(file_buffer).on_capture_processing();
78}
79
81 const std::shared_ptr<IO::IOManager>& io_manager,
82 const std::string& filepath,
83 std::shared_ptr<Kakshya::DynamicSoundStream> target_stream,
84 uint32_t cycle_count)
85{
86 auto file_container = io_manager->load_audio(filepath);
87 if (!file_container) {
88 error<std::runtime_error>(Journal::Component::Kriya, Journal::Context::AsyncIO, std::source_location::current(),
89 "Failed to load audio file: {}", filepath);
90 }
91
92 auto temp_buffer = std::make_shared<Buffers::SoundFileBridge>(0, file_container);
93 temp_buffer->setup_processors(Buffers::ProcessingToken::AUDIO_BACKEND);
94
96 op.m_source_container = temp_buffer->get_capture_stream();
97 op.m_target_container = std::move(target_stream);
98 op.m_load_length = cycle_count;
99 return op;
100}
101
103{
105 op.m_transformer = std::move(transformer);
106 return op;
107}
108
109BufferOperation BufferOperation::route_to_buffer(std::shared_ptr<Buffers::AudioBuffer> target)
110{
112 op.m_target_buffer = std::move(target);
113 return op;
114}
115
116BufferOperation BufferOperation::route_to_container(std::shared_ptr<Kakshya::DynamicSoundStream> target)
117{
119 op.m_target_container = std::move(target);
120 return op;
121}
122
123BufferOperation BufferOperation::load_from_container(std::shared_ptr<Kakshya::DynamicSoundStream> source,
124 std::shared_ptr<Buffers::AudioBuffer> target,
125 uint64_t start_frame,
126 uint32_t length)
127{
129 op.m_source_container = std::move(source);
130 op.m_target_buffer = std::move(target);
131 op.m_start_frame = start_frame;
132 op.m_load_length = length;
133 return op;
134}
135
136BufferOperation BufferOperation::when(std::function<bool(uint32_t)> condition)
137{
139 op.m_condition = std::move(condition);
140 return op;
141}
142
144{
146 op.m_dispatch_handler = std::move(handler);
147 return op;
148}
149
150BufferOperation BufferOperation::fuse_data(std::vector<std::shared_ptr<Buffers::AudioBuffer>> sources,
151 TransformVectorFunction fusion_func,
152 std::shared_ptr<Buffers::AudioBuffer> target)
153{
155 op.m_source_buffers = std::move(sources);
156 op.m_fusion_function = std::move(fusion_func);
157 op.m_target_buffer = std::move(target);
158 return op;
159}
160
161BufferOperation BufferOperation::fuse_containers(std::vector<std::shared_ptr<Kakshya::DynamicSoundStream>> sources,
162 TransformVectorFunction fusion_func,
163 std::shared_ptr<Kakshya::DynamicSoundStream> target)
164{
166 op.m_source_containers = std::move(sources);
167 op.m_fusion_function = std::move(fusion_func);
168 op.m_target_container = std::move(target);
169 return op;
170}
171
173 std::shared_ptr<Buffers::AudioBuffer> buffer,
175{
177 op.m_target_buffer = std::move(buffer);
178 op.m_buffer_modifier = std::move(modifier);
179 return op;
180}
181
182CaptureBuilder BufferOperation::capture_from(std::shared_ptr<Buffers::AudioBuffer> buffer)
183{
184 return CaptureBuilder(std::move(buffer));
185}
186
188{
189 m_priority = priority;
190 return *this;
191}
192
194{
195 m_token = token;
196 return *this;
197}
198
200{
202 return *this;
203}
204
206{
207 m_tag = tag;
208 return *this;
209}
210
212{
213 if (m_type == OpType::MODIFY) {
215 } else if (m_type == OpType::CAPTURE) {
217 }
218 return *this;
219}
220
226
228{
229 m_is_streaming = true;
230 return *this;
231}
232
234 : m_type(type)
235 , m_capture(std::move(capture))
236 , m_tag(m_capture.get_tag())
237{
238}
239
241 : m_type(type)
242 , m_capture(nullptr)
243{
244}
245
247{
249 return true;
250 }
252 return false;
253 }
254
255 switch (op.get_type()) {
257 return true;
259 return op.is_streaming();
260 default:
261 return false;
262 }
263}
264
291
292}
Eigen::Index count
BufferCapture & for_cycles(uint32_t count)
Set the number of times to execute this capture operation.
Definition Capture.cpp:25
CaptureMode
Defines the data capture and retention strategy.
Definition Capture.hpp:58
@ TRANSIENT
Single cycle capture (default) - data expires after 1 cycle.
@ ACCUMULATE
Accumulate over multiple cycles in container.
Flexible data capture interface for buffer-based processing pipelines.
Definition Capture.hpp:52
std::function< bool(uint32_t)> m_condition
std::vector< std::shared_ptr< Buffers::AudioBuffer > > m_source_buffers
Buffers::AudioProcessingFunction m_buffer_modifier
std::shared_ptr< Buffers::AudioBuffer > m_target_buffer
static CaptureBuilder capture_input_from(const std::shared_ptr< Buffers::BufferManager > &buffer_manager, uint32_t input_channel)
Create CaptureBuilder for input channel with fluent configuration.
std::vector< std::shared_ptr< Kakshya::DynamicSoundStream > > m_source_containers
static BufferOperation when(std::function< bool(uint32_t)> condition)
Create a conditional operation for pipeline branching.
BufferOperation & for_cycles(uint32_t count)
BufferOperation(OpType type, BufferCapture capture)
BufferOperation & as_process_phase()
Hint that this operation should execute in process phase.
static bool is_capture_phase_operation(const BufferOperation &op)
std::shared_ptr< Kakshya::DynamicSoundStream > m_target_container
static BufferOperation capture(BufferCapture capture)
Create a capture operation using BufferCapture configuration.
BufferOperation & with_tag(const std::string &tag)
Assign identification tag.
static BufferOperation load_from_container(std::shared_ptr< Kakshya::DynamicSoundStream > source, std::shared_ptr< Buffers::AudioBuffer > target, uint64_t start_frame=0, uint32_t length=0)
Create a load operation from container to buffer.
BufferOperation & every_n_cycles(uint32_t n)
Set cycle interval for periodic execution.
static BufferOperation fuse_containers(std::vector< std::shared_ptr< Kakshya::DynamicSoundStream > > sources, TransformVectorFunction fusion_func, std::shared_ptr< Kakshya::DynamicSoundStream > target)
Create a fusion operation for multiple DynamicSoundStream sources.
static BufferOperation capture_file(const std::shared_ptr< IO::IOManager > &io_manager, const std::string &filepath, uint32_t channel=0, uint32_t cycle_count=0)
Create a file capture operation that reads from file and stores in stream.
static BufferOperation file_to_stream(const std::shared_ptr< IO::IOManager > &io_manager, const std::string &filepath, std::shared_ptr< Kakshya::DynamicSoundStream > target_stream, uint32_t cycle_count=0)
Create operation to route file data to DynamicSoundStream.
static BufferOperation dispatch_to(OperationFunction handler)
Create a dispatch operation for external processing.
bool is_streaming() const
Check if this operation is a streaming operation.
static BufferOperation route_to_buffer(std::shared_ptr< Buffers::AudioBuffer > target)
Create a routing operation to AudioBuffer destination.
TransformVectorFunction m_fusion_function
BufferOperation & with_priority(uint8_t priority)
Set execution priority for scheduler ordering.
static CaptureBuilder capture_from(std::shared_ptr< Buffers::AudioBuffer > buffer)
Create a CaptureBuilder for fluent capture configuration.
BufferOperation & on_token(Buffers::ProcessingToken token)
Set processing token for execution context.
OpType get_type() const
Getters for internal state (read-only)
Buffers::ProcessingToken m_token
static BufferOperation capture_input(const std::shared_ptr< Buffers::BufferManager > &buffer_manager, uint32_t input_channel, BufferCapture::CaptureMode mode=BufferCapture::CaptureMode::ACCUMULATE, uint32_t cycle_count=0)
Create capture operation from input channel using convenience API.
static BufferOperation route_to_container(std::shared_ptr< Kakshya::DynamicSoundStream > target)
Create a routing operation to DynamicSoundStream destination.
static BufferOperation modify_buffer(std::shared_ptr< Buffers::AudioBuffer > buffer, Buffers::AudioProcessingFunction modifier)
Create a modify operation for direct buffer manipulation.
std::shared_ptr< Kakshya::DynamicSoundStream > m_source_container
TransformationFunction m_transformer
BufferOperation & as_streaming()
Mark this operation as streaming (executes continuously) Useful for modify_buffer and similar statefu...
OpType
Defines the fundamental operation types in the processing pipeline.
@ BRANCH
Branch to sub-pipeline based on conditions.
@ SYNC
Synchronize with timing/cycles for coordination.
@ LOAD
Load data from container to buffer with position control.
@ CONDITION
Conditional operation for branching logic.
@ FUSE
Fuse multiple sources using custom fusion functions.
@ ROUTE
Route data to destination (buffer or container)
@ CAPTURE
Capture data from source buffer using BufferCapture strategy.
@ MODIFY
Modify Buffer Data using custom quick process.
@ DISPATCH
Dispatch to external handler for custom processing.
@ TRANSFORM
Apply transformation function to data variants.
static BufferOperation fuse_data(std::vector< std::shared_ptr< Buffers::AudioBuffer > > sources, TransformVectorFunction fusion_func, std::shared_ptr< Buffers::AudioBuffer > target)
Create a fusion operation for multiple AudioBuffer sources.
static BufferOperation transform(TransformationFunction transformer)
Create a transform operation with custom transformation function.
static bool is_process_phase_operation(const BufferOperation &op)
static CaptureBuilder capture_file_from(const std::shared_ptr< IO::IOManager > &io_manager, const std::string &filepath, uint32_t channel=0)
Create CaptureBuilder for file with fluent configuration.
ExecutionPhase get_execution_phase() const
Get the execution phase hint for this operation.
Fundamental unit of operation in buffer processing pipelines.
CaptureBuilder & on_capture_processing()
Set processing control to ON_CAPTURE mode.
Definition Capture.cpp:89
Fluent builder interface for constructing BufferCapture configurations.
Definition Capture.hpp:231
std::function< void(const std::shared_ptr< AudioBuffer > &)> AudioProcessingFunction
Audio processing function - receives correctly-typed AudioBuffer.
ProcessingToken
Bitfield enum defining processing characteristics and backend requirements for buffer operations.
@ AUDIO_BACKEND
Standard audio processing backend configuration.
@ AsyncIO
Async I/O operations ( network, streaming)
@ Kriya
Automatable tasks and fluent scheduling api for Nodes and Buffers.
std::function< Kakshya::DataVariant(std::vector< Kakshya::DataVariant > &, uint32_t)> TransformVectorFunction
std::function< Kakshya::DataVariant(Kakshya::DataVariant &, uint32_t)> TransformationFunction
Definition Capture.hpp:16
std::function< void(Kakshya::DataVariant &, uint32_t)> OperationFunction
Definition Capture.hpp:15