Construct a GranularMatrix with grammar rules appropriate for the requested output type.
REGION_GROUP: registers segment, attribute, sort (existing behaviour). CONTAINER: registers segment, attribute, sort, then appends reconstruct. The reconstruct rule reads the source container from ExecutionContext::execution_metadata["container"] and writes stitched per-channel audio into a SoundFileContainer. CONTAINER_ADDITIVE: same as CONTAINER but uses an overlap-add reconstruct rule
733{
734 auto matrix = std::make_shared<GranularMatrix>();
735
736 matrix->create_operation<
SegmentOp>(
"segment");
737 matrix->create_operation<
AttributeOp>(
"attribute");
738 matrix->create_operation<
SortOp>(
"sort");
739
740 matrix->get_grammar()->create_rule("segment")
741 .with_context(ComputationContext::TEMPORAL)
742 .with_priority(100)
743 .with_description("Fixed hop-size grain segmentation")
745 .executes(segment_grains)
746 .build();
747
748 matrix->get_grammar()->create_rule("attribute")
749 .with_context(attribution_context)
750 .with_priority(75)
751 .with_description("Per-grain feature attribution via analyzer or lambda")
753 .executes(attribute_grains)
754 .build();
755
756 matrix->get_grammar()->create_rule("sort")
757 .with_context(ComputationContext::STRUCTURAL)
758 .with_priority(50)
759 .with_description("Attribute-keyed grain sort, CPU or GPU")
761 .executes(sort_grains)
762 .build();
763
764 if (output == GranularOutput::CONTAINER) {
765 matrix->get_grammar()->create_rule("reconstruct")
766 .with_context(ComputationContext::STRUCTURAL)
767 .with_priority(25)
768 .with_description("Stitch sorted grains into a SoundFileContainer")
770 .executes(reconstruct_grains)
771 .build();
772 } else if (output == GranularOutput::CONTAINER_ADDITIVE) {
773 auto ola_executor =
774 [t = std::move(taper)](
const std::any& in,
const ExecutionContext& ctx) -> std::any {
776 if (t) {
778 }
779 return reconstruct_grains_additive(in, patched);
780 };
781
782 matrix->get_grammar()->create_rule("reconstruct")
783 .with_context(ComputationContext::STRUCTURAL)
784 .with_priority(25)
785 .with_description("Additive grain reconstruction into SoundFileContainer")
786 .matches_type<Kakshya::RegionGroup>()
787 .executes(ola_executor)
788 .build();
789 } else if (output == GranularOutput::STREAM) {
790 matrix->get_grammar()->create_rule("reconstruct")
791 .with_context(ComputationContext::STRUCTURAL)
792 .with_priority(25)
793 .with_description("Stitch sorted grains into a DynamicSoundStream")
794 .matches_type<Kakshya::RegionGroup>()
795 .executes(reconstruct_grains_stream)
796 .build();
797 } else if (output == GranularOutput::STREAM_ADDITIVE) {
798 auto ola_executor =
799 [t = std::move(taper)](const std::any& in, const ExecutionContext& ctx) -> std::any {
800 ExecutionContext patched = ctx;
801 if (t)
804 };
805
806 matrix->get_grammar()->create_rule("reconstruct")
807 .with_context(ComputationContext::STRUCTURAL)
808 .with_priority(25)
809 .with_description("Additive grain reconstruction into DynamicSoundStream")
810 .matches_type<Kakshya::RegionGroup>()
811 .executes(ola_executor)
812 .build();
813 }
814
815 return matrix;
816}
Computes a scalar attribute per grain and writes it onto each Region.
Segments container audio into fixed hop-size grain windows.
Sorts grains by a named attribute key, with optional GPU dispatch.
const ComputationGrammar::Rule::Executor reconstruct_grains_additive_stream
Grammar rule executor — OLA reconstruct into DynamicSoundStream.
Organizes related signal regions into a categorized collection.
std::unordered_map< std::string, std::any > execution_metadata
Arbitrary metadata parameters used by operations.
Context information controlling how a compute operation executes.