MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
StreamContainer.hpp
Go to the documentation of this file.
1#pragma once
2
4
5namespace MayaFlux::Kakshya {
6
7/**
8 * @class StreamContainer
9 * @brief Data-driven interface for temporal stream containers with navigable read position.
10 *
11 * StreamContainer extends SignalSourceContainer by introducing explicit temporal navigation and read position
12 * management, making it suitable for playback, streaming, and interactive workflows. This abstraction enables
13 * digital-first systems to treat any multi-dimensional, processable signal source as a navigable stream,
14 * supporting advanced scenarios such as:
15 * - Real-time playback and scrubbing of audio, video, or multi-modal data
16 * - Looping, seeking, and temporal region-based processing
17 * - Interactive or programmatic navigation through large or infinite datasets
18 * - Streaming from live sources, files, or procedural generators with temporal semantics
19 * - Integration with digital-first nodes, routines, and buffer systems for seamless data-driven workflows
20 *
21 * Key features:
22 * - Explicit read position in the primary (temporal) dimension, decoupled from analog metaphors like "tape"
23 * - Support for temporal rate (sample rate, frame rate, etc.) and conversion between time and position units
24 * - Looping and region-based navigation for flexible playback and processing
25 * - Sequential and random access read operations, including peek and advance
26 * - Designed for composability with digital-first processing chains, nodes, and routines
27 * - Enables robust, data-driven orchestration of streaming, playback, and temporal analysis tasks
28 *
29 * StreamContainer is foundational for digital-first, data-driven applications that require precise,
30 * programmable control over temporal navigation and streaming, unconstrained by legacy analog models.
31 */
32class MAYAFLUX_API StreamContainer : public SignalSourceContainer {
33public:
34 virtual ~StreamContainer() = default;
35
36 // ===== Stream Position Management =====
37
38 /**
39 * @brief Set the current read position in the primary temporal dimension per channel.
40 * @param position Position in the first (temporal) dimension (e.g., frame/sample index)
41 *
42 * Enables random access and programmatic navigation within the stream.
43 */
44 virtual void set_read_position(const std::vector<uint64_t>& position) = 0;
45
46 /**
47 * @brief Update the read position for a specific channel.
48 * @param channel Channel index to update
49 * @param frame New position in the temporal dimension for the specified channel
50 *
51 * Allows fine-grained control over individual channels in multi-channel streams.
52 */
53 virtual void update_read_position_for_channel(size_t channel, uint64_t frame) = 0;
54
55 /**
56 * @brief Get the current read position.
57 * @return Current position in the temporal dimension per channel
58 *
59 * Allows external components to query or synchronize playback/processing state.
60 */
61 virtual const std::vector<uint64_t>& get_read_position() const = 0;
62
63 /**
64 * @brief Advance the read position by a specified amount.
65 * @param frames Number of frames to advance
66 * @note Should handle looping if enabled
67 *
68 * Supports efficient sequential access and playback scenarios.
69 */
70 virtual void advance_read_position(const std::vector<uint64_t>& frames) = 0;
71
72 /**
73 * @brief Check if read position has reached the end of the stream.
74 * @return true if at or past the end of data
75 *
76 * Useful for detecting end-of-stream in playback or streaming contexts.
77 */
78 virtual bool is_at_end() const = 0;
79
80 /**
81 * @brief Reset read position to the beginning of the stream.
82 *
83 * Enables repeatable playback or reprocessing from the start.
84 */
85 virtual void reset_read_position() = 0;
86
87 // ===== Temporal Information =====
88
89 /**
90 * @brief Get the temporal rate (e.g., sample rate, frame rate) of the stream.
91 * @return Rate in units per second
92 *
93 * Enables time-based navigation and synchronization with external systems.
94 */
95 virtual uint64_t get_temporal_rate() const = 0;
96
97 /**
98 * @brief Convert from time (seconds) to position units (e.g., frame/sample index).
99 * @param time Time value (interpretation depends on container type)
100 * @return Corresponding position in primary dimension
101 *
102 * Supports time-based seeking and integration with time-aware workflows.
103 */
104 virtual uint64_t time_to_position(double time) const = 0;
105
106 /**
107 * @brief Convert from position units (e.g., frame/sample index) to time (seconds).
108 * @param position Position in primary dimension
109 * @return Corresponding time value
110 *
111 * Enables precise mapping between temporal and positional domains.
112 */
113 virtual double position_to_time(uint64_t position) const = 0;
114
115 /**
116 * @brief Enable or disable looping behavior for the stream.
117 * @param enable true to enable looping
118 *
119 * When enabled, advancing past the end of the loop region wraps to the start.
120 */
121 virtual void set_looping(bool enable) = 0;
122
123 /**
124 * @brief Check if looping is enabled for the stream.
125 * @return true if looping is enabled
126 */
127 virtual bool is_looping() const = 0;
128
129 /**
130 * @brief Set the loop region using a Region.
131 * @param region The region to use for looping
132 *
133 * Defines the temporal bounds for looped playback or processing.
134 */
135 virtual void set_loop_region(const Region& region) = 0;
136
137 /**
138 * @brief Get the current loop region.
139 * @return Region representing the loop region
140 */
141 virtual Region get_loop_region() const = 0;
142
143 /**
144 * @brief Check if the stream is ready for reading.
145 * @return true if stream can be read from
146 *
147 * Useful for coordinating with asynchronous or streaming data sources.
148 */
149 virtual bool is_ready() const = 0;
150
151 /**
152 * @brief Get the number of remaining frames from the current position, per channel.
153 * @return Number of frames until end (accounting for looping)
154 *
155 * Enables efficient buffer management and lookahead in streaming scenarios.
156 */
157 virtual std::vector<uint64_t> get_remaining_frames() const = 0;
158
159 /**
160 * @brief Read data sequentially from the current position.
161 * @param output Buffer to write data into
162 * @param count Number of elements to read (interpretation is type-specific)
163 * @return Actual number of elements read
164 * @note Advances read position by amount read
165 *
166 * Supports efficient, contiguous data access for playback or processing.
167 */
168 virtual uint64_t read_sequential(std::span<double> output, uint64_t count) = 0;
169
170 /**
171 * @brief Peek at data without advancing the read position.
172 * @param output Buffer to write data into
173 * @param count Number of elements to peek
174 * @param offset Offset from current position in primary dimension
175 * @return Actual number of elements read
176 *
177 * Enables lookahead, preview, or non-destructive inspection of stream data.
178 */
179 virtual uint64_t peek_sequential(std::span<double> output, uint64_t count, uint64_t offset = 0) const = 0;
180
181 virtual void reset_processing_token() = 0;
182
183 virtual bool try_acquire_processing_token(int channel) = 0;
184
185 virtual bool has_processing_token(int channel) const = 0;
186};
187
188} // namespace MayaFlux::Kakshya
Data-driven interface for managing arbitrary processable signal sources.
virtual uint64_t time_to_position(double time) const =0
Convert from time (seconds) to position units (e.g., frame/sample index).
virtual const std::vector< uint64_t > & get_read_position() const =0
Get the current read position.
virtual Region get_loop_region() const =0
Get the current loop region.
virtual void reset_processing_token()=0
virtual void set_loop_region(const Region &region)=0
Set the loop region using a Region.
virtual uint64_t read_sequential(std::span< double > output, uint64_t count)=0
Read data sequentially from the current position.
virtual bool try_acquire_processing_token(int channel)=0
virtual bool is_ready() const =0
Check if the stream is ready for reading.
virtual void reset_read_position()=0
Reset read position to the beginning of the stream.
virtual double position_to_time(uint64_t position) const =0
Convert from position units (e.g., frame/sample index) to time (seconds).
virtual void set_looping(bool enable)=0
Enable or disable looping behavior for the stream.
virtual bool has_processing_token(int channel) const =0
virtual uint64_t get_temporal_rate() const =0
Get the temporal rate (e.g., sample rate, frame rate) of the stream.
virtual void advance_read_position(const std::vector< uint64_t > &frames)=0
Advance the read position by a specified amount.
virtual bool is_looping() const =0
Check if looping is enabled for the stream.
virtual uint64_t peek_sequential(std::span< double > output, uint64_t count, uint64_t offset=0) const =0
Peek at data without advancing the read position.
virtual std::vector< uint64_t > get_remaining_frames() const =0
Get the number of remaining frames from the current position, per channel.
virtual void update_read_position_for_channel(size_t channel, uint64_t frame)=0
Update the read position for a specific channel.
virtual bool is_at_end() const =0
Check if read position has reached the end of the stream.
virtual void set_read_position(const std::vector< uint64_t > &position)=0
Set the current read position in the primary temporal dimension per channel.
Data-driven interface for temporal stream containers with navigable read position.
Represents a point or span in N-dimensional space.
Definition Region.hpp:67