MayaFlux 0.2.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
OrganizedRegion.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "RegionSegment.hpp"
4
5namespace MayaFlux::Kakshya {
6
7/**
8 * @struct OrganizedRegion
9 * @brief A structured audio region with metadata and transition information
10 *
11 * Represents a higher-level organization of audio segments with associated
12 * metadata, enabling complex non-linear audio arrangements and transitions.
13 */
14struct MAYAFLUX_API OrganizedRegion {
15 std::string group_name; ///< Name of the region group
16 size_t region_index {}; ///< Index within the group
17 std::vector<RegionSegment> segments; ///< Audio segments in this region
18 std::unordered_map<std::string, std::any> attributes; ///< Extensible metadata
19 RegionTransition transition_type = RegionTransition::IMMEDIATE; ///< Transition to next region
20 double transition_duration_ms = 0.0; ///< Duration of transition in milliseconds
21 RegionSelectionPattern selection_pattern = RegionSelectionPattern::SEQUENTIAL;
22
23 RegionState state = RegionState::IDLE;
24 std::vector<uint64_t> current_position; ///< Current read position
25 size_t active_segment_index = 0; ///< Currently active segment
26 std::vector<size_t> active_segment_indices; ///< Multiple active segments (for overlapping)
27
28 // Playback control
29 bool looping_enabled = false;
30 std::vector<uint64_t> loop_start; ///< Loop start coordinates
31 std::vector<uint64_t> loop_end; ///< Loop end coordinates
32
33 OrganizedRegion() = default;
34
35 OrganizedRegion(std::string name, size_t index)
36 : group_name(std::move(name))
37 , region_index(index)
38 {
39 }
40
41 /**
42 * @brief Get the total volume (elements) of all segments
43 */
44 uint64_t get_total_volume() const
45 {
46 uint64_t total = 0;
47 for (const auto& segment : segments) {
48 total += segment.get_total_elements();
49 }
50 return total;
51 }
52
53 /**
54 * @brief Check if position is within any segment
55 */
56 bool contains_position(const std::vector<uint64_t>& position) const
57 {
58 return std::ranges::any_of(segments,
59 [&position](const RegionSegment& segment) {
60 return segment.contains_position(position);
61 });
62 }
63
64 /**
65 * @brief Get the active segment for current position
66 */
68 {
69 if (active_segment_index < segments.size()) {
70 return &segments[active_segment_index];
71 }
72 return nullptr;
73 }
74
75 /**
76 * @brief Find segment containing specific position
77 */
78 std::optional<size_t> find_segment_for_position(const std::vector<uint64_t>& position) const
79 {
80 for (size_t i = 0; i < segments.size(); ++i) {
81 if (segments[i].contains_position(position)) {
82 return i;
83 }
84 }
85 return std::nullopt;
86 }
87
88 /**
89 * @brief Set processing metadata for this region
90 */
91 template <typename T>
92 void set_attribute(const std::string& key, T&& value)
93 {
94 attributes[key] = std::forward<T>(value);
95 }
96
97 /**
98 * @brief Get processing metadata from this region
99 */
100 template <typename T>
101 std::optional<T> get_attribute(const std::string& key) const
102 {
103 auto it = attributes.find(key);
104 if (it != attributes.end()) {
105 try {
106 return safe_any_cast<T>(it->second);
107 } catch (const std::bad_any_cast&) {
108 return std::nullopt;
109 }
110 }
111 return std::nullopt;
112 }
113};
114}
RegionSelectionPattern
Describes how regions are selected for processing or playback.
Definition Region.hpp:11
RegionTransition
Describes how transitions between regions are handled.
Definition Region.hpp:26
RegionState
Processing state for regions.
Definition Region.hpp:38
uint64_t get_total_volume() const
Get the total volume (elements) of all segments.
std::vector< uint64_t > loop_start
Loop start coordinates.
std::vector< uint64_t > current_position
Current read position.
std::vector< size_t > active_segment_indices
Multiple active segments (for overlapping)
OrganizedRegion(std::string name, size_t index)
std::optional< T > get_attribute(const std::string &key) const
Get processing metadata from this region.
void set_attribute(const std::string &key, T &&value)
Set processing metadata for this region.
const RegionSegment * get_active_segment() const
Get the active segment for current position.
std::unordered_map< std::string, std::any > attributes
Extensible metadata.
std::vector< RegionSegment > segments
Audio segments in this region.
std::optional< size_t > find_segment_for_position(const std::vector< uint64_t > &position) const
Find segment containing specific position.
bool contains_position(const std::vector< uint64_t > &position) const
Check if position is within any segment.
std::string group_name
Name of the region group.
std::vector< uint64_t > loop_end
Loop end coordinates.
A structured audio region with metadata and transition information.
bool contains_position(const std::vector< uint64_t > &pos) const
Check if a position is within this segment.
Represents a discrete segment of audio data with caching capabilities.