MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
BufferPipelineBranches.cpp
Go to the documentation of this file.
2
3namespace MayaFlux::Kriya {
4
6 std::function<bool(uint32_t)> condition,
7 const std::function<void(BufferPipeline&)>& branch_builder,
8 bool synchronous,
9 uint64_t samples_per_operation)
10{
11 auto branch_pipeline = std::make_shared<BufferPipeline>();
12 if (m_scheduler) {
13 branch_pipeline->m_scheduler = m_scheduler;
14 }
15 branch_pipeline->m_buffer_manager = m_buffer_manager;
16 branch_pipeline->m_io_manager = m_io_manager;
17 branch_builder(*branch_pipeline);
18
19 m_branches.push_back({ .condition = std::move(condition),
20 .pipeline = std::move(branch_pipeline),
21 .synchronous = synchronous,
22 .samples_per_operation = samples_per_operation });
23
24 return *this;
25}
26
27std::shared_ptr<Vruta::SoundRoutine> BufferPipeline::dispatch_branch_async(BranchInfo& branch, uint64_t)
28{
29 if (!m_scheduler)
30 return nullptr;
31
32 branch.pipeline->m_active_self = branch.pipeline;
33
34 auto branch_routine = branch.pipeline->execute_internal(1, branch.samples_per_operation);
35
36 auto task = std::make_shared<Vruta::SoundRoutine>(std::move(branch_routine));
37 m_scheduler->add_task(task);
38
39 m_branch_tasks.push_back(task);
40
41 return task;
42}
43
44std::shared_ptr<Vruta::GraphicsRoutine> BufferPipeline::dispatch_frame_branch(BranchInfo& branch)
45{
46 if (!m_scheduler)
47 return nullptr;
48
49 branch.pipeline->m_active_self = branch.pipeline;
50
51 auto task = std::make_shared<Vruta::GraphicsRoutine>(
52 branch.pipeline->execute_frame_internal(1, branch.samples_per_operation));
53 m_scheduler->add_task(task);
54
55 m_branch_tasks.push_back(task);
56
57 return task;
58}
59
61{
62 for (auto& branch : m_branches) {
63 if (branch.pipeline) {
64 branch.pipeline->m_active_self.reset();
65 }
66 }
67
68 std::erase_if(m_branch_tasks, [](const auto& task) {
69 return !task || !task->is_active();
70 });
71}
72
73}
std::vector< std::shared_ptr< Vruta::Routine > > m_branch_tasks
std::shared_ptr< IO::IOManager > m_io_manager
BufferPipeline & branch_if(std::function< bool(uint32_t)> condition, const std::function< void(BufferPipeline &)> &branch_builder, bool synchronous=false, uint64_t samples_per_operation=1)
Add conditional branch to the pipeline.
std::vector< BranchInfo > m_branches
std::shared_ptr< Buffers::BufferManager > m_buffer_manager
std::shared_ptr< Vruta::GraphicsRoutine > dispatch_frame_branch(BranchInfo &branch)
Vruta::TaskScheduler * m_scheduler
std::shared_ptr< Vruta::SoundRoutine > dispatch_branch_async(BranchInfo &branch, uint64_t cycle)
Coroutine-based execution engine for composable, multi-strategy buffer processing.
void add_task(const std::shared_ptr< Routine > &routine, const std::string &name="", bool initialize=false)
Add a routine to the scheduler based on its processing token.
Definition Scheduler.cpp:94
std::shared_ptr< BufferPipeline > pipeline