MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ process_to_stream_async() [1/2]

template<typename CompleteFn >
void MayaFlux::Yantra::Granular::process_to_stream_async ( const std::shared_ptr< GranularMatrix > &  matrix,
const std::shared_ptr< Kakshya::SignalSourceContainer > &  container,
AnalysisType  analysis_type,
CompleteFn &&  on_complete,
const GranularConfig config = {},
const std::string &  qualifier = {},
GranularOutput  output = GranularOutput::STREAM 
)

Async offline granular pipeline terminating in a DynamicSoundStream (AnalysisType path).

Runs the full pipeline on a background thread owned by matrix and invokes on_complete with the finished stream. Returns immediately.

The callback receives a shared_ptr<DynamicSoundStream> which is null if reconstruction produced an unexpected type. The caller is responsible for thread-safe installation of the stream into any downstream pipeline.

Parameters
matrixComputeMatrix that owns the async future.
containerSource signal data.
analysis_typeAttribution category.
on_completeCalled on the worker thread with the finished stream.
configPipeline scalar parameters.
qualifierScalar to extract. Empty uses type default.
outputSTREAM for concatenative, STREAM_ADDITIVE for OLA.

Definition at line 639 of file GranularWorkflow.hpp.

644 {},
645 const std::string& qualifier = {},
646 GranularOutput output = GranularOutput::STREAM)
647{
648 auto ctx = make_granular_context(config, analysis_type, qualifier);
649 ctx.execution_metadata["container"] = container;
650 if (config.taper)
651 ctx.execution_metadata["grain_taper"] = config.taper;
652
653 auto seg_op = matrix->get_operation<SegmentOp>("segment");
654 auto attr_op = matrix->get_operation<AttributeOp>("attribute");
655 auto sort_op = matrix->get_operation<SortOp>("sort");
656 apply_context_parameters(seg_op, ctx);
657 apply_context_parameters(attr_op, ctx);
658 apply_context_parameters(sort_op, ctx);
659
660 matrix->with_async(
661 make_granular_input(container),
662 [ctx, output](auto chain) {
663 auto sorted = chain
664 .template then<SegmentOp>("segment")
665 .template then<AttributeOp>("attribute")
666 .template then<SortOp>("sort")
667 .to_io();
668 if (output == GranularOutput::STREAM_ADDITIVE) {
669 return safe_any_cast_or_throw<
670 Datum<std::shared_ptr<Kakshya::SignalSourceContainer>>>(
671 reconstruct_grains_additive_stream(std::any(sorted), ctx));
672 }
673 return safe_any_cast_or_throw<
674 Datum<std::shared_ptr<Kakshya::SignalSourceContainer>>>(
675 reconstruct_grains_stream(std::any(sorted), ctx));
676 },
677 [on_complete = std::forward<CompleteFn>(on_complete)](
678 const Datum<std::shared_ptr<Kakshya::SignalSourceContainer>>& result) {
679 on_complete(std::dynamic_pointer_cast<Kakshya::DynamicSoundStream>(result.data));
680 });
681}