MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
BufferOperation.cpp
Go to the documentation of this file.
1#include "BufferOperation.hpp"
2
6
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::string& filepath,
41 uint32_t channel,
42 uint32_t cycle_count)
43{
44 auto file_container = MayaFlux::load_audio_file(filepath);
45 if (!file_container) {
46 error<std::runtime_error>(Journal::Component::Kriya, Journal::Context::AsyncIO, std::source_location::current(),
47 "Failed to load audio file: {}", filepath);
48 }
49
50 auto file_buffer = std::make_shared<Buffers::FileBridgeBuffer>(channel, file_container);
51 file_buffer->setup_chain_and_processor();
52
53 BufferCapture capture(file_buffer,
55 cycle_count);
56
58
59 return { BufferOperation::OpType::CAPTURE, std::move(capture) };
60}
61
63 const std::string& filepath,
64 uint32_t channel)
65{
66 auto file_container = MayaFlux::load_audio_file(filepath);
67 if (!file_container) {
68 error<std::runtime_error>(Journal::Component::Kriya, Journal::Context::AsyncIO, std::source_location::current(),
69 "Failed to load audio file: {}", filepath);
70 }
71
72 auto file_buffer = std::make_shared<Buffers::FileBridgeBuffer>(channel, file_container);
73 file_buffer->setup_chain_and_processor();
74
75 return CaptureBuilder(file_buffer).on_capture_processing();
76}
77
79 const std::string& filepath,
80 std::shared_ptr<Kakshya::DynamicSoundStream> target_stream,
81 uint32_t cycle_count)
82{
83 auto file_container = MayaFlux::load_audio_file(filepath);
84 if (!file_container) {
85 error<std::runtime_error>(Journal::Component::Kriya, Journal::Context::AsyncIO, std::source_location::current(),
86 "Failed to load audio file: {}", filepath);
87 }
88
89 auto temp_buffer = std::make_shared<Buffers::FileBridgeBuffer>(0, file_container);
90 temp_buffer->setup_chain_and_processor();
91
93 op.m_source_container = temp_buffer->get_capture_stream();
94 op.m_target_container = std::move(target_stream);
95 op.m_load_length = cycle_count;
96 return op;
97}
98
100{
102 op.m_transformer = std::move(transformer);
103 return op;
104}
105
106BufferOperation BufferOperation::route_to_buffer(std::shared_ptr<Buffers::AudioBuffer> target)
107{
109 op.m_target_buffer = std::move(target);
110 return op;
111}
112
113BufferOperation BufferOperation::route_to_container(std::shared_ptr<Kakshya::DynamicSoundStream> target)
114{
116 op.m_target_container = std::move(target);
117 return op;
118}
119
120BufferOperation BufferOperation::load_from_container(std::shared_ptr<Kakshya::DynamicSoundStream> source,
121 std::shared_ptr<Buffers::AudioBuffer> target,
122 uint64_t start_frame,
123 uint32_t length)
124{
126 op.m_source_container = std::move(source);
127 op.m_target_buffer = std::move(target);
128 op.m_start_frame = start_frame;
129 op.m_load_length = length;
130 return op;
131}
132
133BufferOperation BufferOperation::when(std::function<bool(uint32_t)> condition)
134{
136 op.m_condition = std::move(condition);
137 return op;
138}
139
141{
143 op.m_dispatch_handler = std::move(handler);
144 return op;
145}
146
147BufferOperation BufferOperation::fuse_data(std::vector<std::shared_ptr<Buffers::AudioBuffer>> sources,
148 TransformVectorFunction fusion_func,
149 std::shared_ptr<Buffers::AudioBuffer> target)
150{
152 op.m_source_buffers = std::move(sources);
153 op.m_fusion_function = std::move(fusion_func);
154 op.m_target_buffer = std::move(target);
155 return op;
156}
157
158BufferOperation BufferOperation::fuse_containers(std::vector<std::shared_ptr<Kakshya::DynamicSoundStream>> sources,
159 TransformVectorFunction fusion_func,
160 std::shared_ptr<Kakshya::DynamicSoundStream> target)
161{
163 op.m_source_containers = std::move(sources);
164 op.m_fusion_function = std::move(fusion_func);
165 op.m_target_container = std::move(target);
166 return op;
167}
168
170 std::shared_ptr<Buffers::AudioBuffer> buffer,
172{
174 op.m_target_buffer = std::move(buffer);
175 op.m_buffer_modifier = std::move(modifier);
176 return op;
177}
178
179CaptureBuilder BufferOperation::capture_from(std::shared_ptr<Buffers::AudioBuffer> buffer)
180{
181 return CaptureBuilder(std::move(buffer));
182}
183
185{
186 m_priority = priority;
187 return *this;
188}
189
195
197{
199 return *this;
200}
201
203{
204 m_tag = tag;
205 return *this;
206}
207
209{
210 if (m_type == OpType::MODIFY) {
211 m_modify_cycle_count = count;
212 } else if (m_type == OpType::CAPTURE) {
213 m_capture.for_cycles(count);
214 }
215 return *this;
216}
217
223
225{
226 m_is_streaming = true;
227 return *this;
228}
229
231 : m_type(type)
232 , m_capture(std::move(capture))
233 , m_tag(m_capture.get_tag())
234{
235}
236
238 : m_type(type)
239 , m_capture(nullptr)
240{
241}
242
244{
246 return true;
247 }
249 return false;
250 }
251
252 switch (op.get_type()) {
254 return true;
256 return op.is_streaming();
257 default:
258 return false;
259 }
260}
261
288
289}
Audio file loading and container management API.
static MayaFlux::Nodes::ProcessingToken token
Definition Timers.cpp:8
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
static BufferOperation modify_buffer(std::shared_ptr< Buffers::AudioBuffer > buffer, Buffers::BufferProcessingFunction modifier)
Create a modify operation for direct buffer manipulation.
std::shared_ptr< Buffers::AudioBuffer > m_target_buffer
static BufferOperation capture_file(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 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.
Buffers::BufferProcessingFunction m_buffer_modifier
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 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 file_to_stream(const std::string &filepath, std::shared_ptr< Kakshya::DynamicSoundStream > target_stream, uint32_t cycle_count=0)
Create operation to route file data to DynamicSoundStream.
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 CaptureBuilder capture_file_from(const std::string &filepath, uint32_t channel=0)
Create CaptureBuilder for file with fluent configuration.
static bool is_process_phase_operation(const BufferOperation &op)
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
ProcessingToken
Bitfield enum defining processing characteristics and backend requirements for buffer operations.
@ AUDIO_BACKEND
Standard audio processing backend configuration.
std::variant< AudioProcessingFunction, GraphicsProcessingFunction > BufferProcessingFunction
@ 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
std::shared_ptr< MayaFlux::Kakshya::SoundFileContainer > load_audio_file(const std::string &filepath)
Loads an audio file into a SoundFileContainer with automatic format detection.
Definition Depot.cpp:18