MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
RegionProcessorBase.hpp
Go to the documentation of this file.
1#pragma once
2
7
8namespace MayaFlux::Kakshya {
9
10/**
11 * @class RegionProcessorBase
12 * @brief Base class for N-dimensional region processors.
13 *
14 * RegionProcessorBase provides a foundation for advanced, data-driven region processing
15 * in Maya Flux. It abstracts common functionality for working with N-dimensional regions,
16 * including:
17 * - Region organization and management (non-linear, content-driven, or semantic regions)
18 * - Region-level caching for efficient repeated/random access
19 * - State and position tracking for non-linear or interactive workflows
20 * - Dimension role metadata for semantic-aware processing (e.g., TIME, CHANNEL, SPATIAL_X)
21 * - Coordinate transformations (scaling, translation, rotation) for flexible data access
22 *
23 * This class is designed for digital-first, data-driven workflows, enabling:
24 * - Non-linear playback, editing, and analysis of audio or multi-dimensional data
25 * - Dynamic region-based processing (e.g., slicing, rearrangement, feature extraction)
26 * - Efficient streaming and caching of large or remote datasets
27 * - Integration with higher-level processors such as RegionOrganizationProcessor
28 *
29 * Derived classes should implement region organization logic and may override
30 * caching, extraction, and transformation methods for specialized behavior.
31 *
32 * @see RegionOrganizationProcessor, DynamicRegionProcessor
33 */
34class MAYAFLUX_API RegionProcessorBase : public DataProcessor {
35public:
36 virtual ~RegionProcessorBase() = default;
37
38 /**
39 * @brief Attach this processor to a signal source container.
40 * Initializes region organization, caching, and dimension metadata.
41 * @param container The SignalSourceContainer to attach to.
42 */
43 void on_attach(std::shared_ptr<SignalSourceContainer> container) override;
44
45 /**
46 * @brief Detach this processor from its container.
47 * Cleans up region organization and cache state.
48 * @param container The SignalSourceContainer to detach from.
49 */
50 void on_detach(std::shared_ptr<SignalSourceContainer> container) override;
51
52 /**
53 * @brief Query if the processor is currently performing processing.
54 * @return true if processing is in progress, false otherwise.
55 */
56 [[nodiscard]] bool is_processing() const override { return m_is_processing.load(); }
57
58 /**
59 * @brief Set the maximum cache size for regions (in elements).
60 * @param max_cached_elements Maximum number of elements to cache.
61 */
62 inline void set_cache_limit(size_t max_cached_elements)
63 {
64 m_max_cache_size = max_cached_elements;
65 }
66
67 /**
68 * @brief Enable or disable automatic region caching.
69 * @param enabled true to enable, false to disable.
70 */
71 inline void set_auto_caching(bool enabled)
72 {
73 m_auto_caching = enabled;
74 }
75
76 /**
77 * @brief Get the current processing position (N-dimensional coordinates).
78 * @return Reference to the current position vector.
79 */
80 [[nodiscard]] inline const std::vector<uint64_t>& get_current_position() const
81 {
82 return m_current_position;
83 }
84
85 /**
86 * @brief Set the current processing position (N-dimensional coordinates).
87 * @param position New position vector.
88 */
89 inline void set_current_position(const std::vector<uint64_t>& position)
90 {
91 m_current_position = position;
92 }
93
94protected:
95 // Container and processing state
96 std::weak_ptr<SignalSourceContainer> m_container_weak;
97 std::atomic<bool> m_is_processing { false };
98
99 // Region organization and navigation
100 std::vector<OrganizedRegion> m_organized_regions;
101 size_t m_current_region_index = 0;
102 std::vector<uint64_t> m_current_position;
103
104 // Caching
105 std::unique_ptr<RegionCacheManager> m_cache_manager;
106 size_t m_max_cache_size { static_cast<size_t>(1024 * 1024) }; // 1MB default
107 bool m_auto_caching = true;
108
110
111 /**
112 * @brief Organize container data into structured regions.
113 * Must be implemented by derived classes to define region logic.
114 * @param container The SignalSourceContainer to organize.
115 */
116 virtual void organize_container_data(std::shared_ptr<SignalSourceContainer> container) = 0;
117
118 /**
119 * @brief Cache a region's data if beneficial and not already cached.
120 * Uses heuristics (e.g., segment size vs. cache size) to decide.
121 * @param segment The region segment to consider for caching.
122 * @param container The container providing the data.
123 */
124 virtual void cache_region_if_needed(const RegionSegment& segment,
125 const std::shared_ptr<SignalSourceContainer>& container);
126
127 /**
128 * @brief Advance position according to memory layout and looping.
129 * Supports both linear and multi-dimensional advancement, and respects region-specific looping.
130 * @param position Position vector to advance (modified in place).
131 * @param steps Number of steps to advance.
132 * @param region Optional region to constrain advancement.
133 * @return true if position was advanced, false if at end.
134 */
135 virtual bool advance_position(std::vector<uint64_t>& position,
136 uint64_t steps = 1,
137 const OrganizedRegion* region = nullptr);
138
139 /**
140 * @brief Ensure output data is properly dimensioned for region extraction.
141 * Resizes or allocates the output DataVariant as needed.
142 * @param output_data Output data variant vector to check/resize.
143 * @param required_shape Required shape for the output [num_frames, frame_size].
144 */
145 virtual void ensure_output_dimensioning(std::vector<DataVariant>& output_data,
146 const std::vector<uint64_t>& required_shape);
147};
148
149}
Interface for processing data within SignalSourceContainer objects.
std::unique_ptr< RegionCacheManager > m_cache_manager
const std::vector< uint64_t > & get_current_position() const
Get the current processing position (N-dimensional coordinates).
virtual void organize_container_data(std::shared_ptr< SignalSourceContainer > container)=0
Organize container data into structured regions.
bool is_processing() const override
Query if the processor is currently performing processing.
void set_cache_limit(size_t max_cached_elements)
Set the maximum cache size for regions (in elements).
void set_current_position(const std::vector< uint64_t > &position)
Set the current processing position (N-dimensional coordinates).
std::vector< OrganizedRegion > m_organized_regions
void set_auto_caching(bool enabled)
Enable or disable automatic region caching.
std::weak_ptr< SignalSourceContainer > m_container_weak
Base class for N-dimensional region processors.
std::vector< uint64_t > advance_position(const std::vector< uint64_t > &current_positions, uint64_t frames_to_advance, const ContainerDataStructure &structure, bool looping_enabled, const Region &loop_region)
Advance current positions by a number of frames, with optional looping.
Container structure for consistent dimension ordering.
A structured audio region with metadata and transition information.
Represents a discrete segment of audio data with caching capabilities.