1use crate::{Position3D, Result};
4use serde::{Deserialize, Serialize};
5use std::collections::HashMap;
6use std::time::{Duration, Instant};
7
8pub trait VisualDisplay: Send + Sync {
10 fn render_effect(&mut self, effect: &VisualEffect) -> Result<()>;
12
13 fn clear_all(&mut self) -> Result<()>;
15
16 fn update(&mut self) -> Result<()>;
18
19 fn is_ready(&self) -> bool;
21
22 fn capabilities(&self) -> VisualDisplayCapabilities;
24
25 fn display_id(&self) -> String;
27}
28
29#[derive(Debug, Clone, Serialize, Deserialize)]
31pub struct VisualEffect {
32 pub id: String,
34
35 pub name: String,
37
38 pub elements: Vec<VisualElement>,
40
41 pub duration: Duration,
43
44 pub looping: bool,
46
47 pub priority: u8,
49
50 pub position: Position3D,
52
53 pub audio_source_id: Option<String>,
55}
56
57#[derive(Debug, Clone, Serialize, Deserialize)]
59pub struct VisualElement {
60 pub start_time: Duration,
62
63 pub duration: Duration,
65
66 pub element_type: VisualElementType,
68
69 pub color: ColorRGBA,
71
72 pub intensity: f32,
74
75 pub size: f32,
77
78 pub animation: Option<AnimationParams>,
80
81 pub distance_attenuation: f32,
83}
84
85#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
87pub enum VisualElementType {
88 PointLight,
90
91 DirectionalLight,
93
94 ParticleEffect,
96
97 Shape(ShapeType),
99
100 Text,
102
103 ProgressBar,
105
106 Waveform,
108
109 Spectrum,
111
112 Custom(String),
114}
115
116#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
118pub enum ShapeType {
119 Sphere,
121
122 Cube,
124
125 Cylinder,
127
128 Cone,
130
131 Ring,
133
134 Arrow,
136}
137
138#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
140pub struct ColorRGBA {
141 pub r: f32,
143
144 pub g: f32,
146
147 pub b: f32,
149
150 pub a: f32,
152}
153
154#[derive(Debug, Clone, Serialize, Deserialize)]
156pub struct AnimationParams {
157 pub animation_type: AnimationType,
159
160 pub speed: f32,
162
163 pub amplitude: f32,
165
166 pub phase: f32,
168
169 pub easing: EasingFunction,
171}
172
173#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
175pub enum AnimationType {
176 Static,
178
179 Pulse,
181
182 Fade,
184
185 Rotate,
187
188 Scale,
190
191 Oscillate,
193
194 Spiral,
196
197 Custom(String),
199}
200
201#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
203pub enum EasingFunction {
204 Linear,
206
207 EaseIn,
209
210 EaseOut,
212
213 EaseInOut,
215
216 Bounce,
218
219 Elastic,
221}
222
223#[derive(Debug, Clone, Serialize, Deserialize)]
225pub struct VisualDisplayCapabilities {
226 pub max_concurrent_effects: usize,
228
229 pub supported_elements: Vec<VisualElementType>,
231
232 pub color_depth: u8,
234
235 pub refresh_rate: f32,
237
238 pub spatial_support: bool,
240
241 pub animation_support: bool,
243
244 pub alpha_support: bool,
246
247 pub resolution: (u32, u32),
249
250 pub field_of_view: Option<f32>,
252
253 pub features: HashMap<String, String>,
255}
256
257#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
259pub enum DirectionZone {
260 Front,
262
263 Left,
265
266 Back,
268
269 Right,
271
272 Above,
274
275 Below,
277}
278
279#[derive(Debug, Clone, Serialize, Deserialize)]
281pub struct VisualAudioMetrics {
282 pub processing_latency: f32,
284
285 pub sync_accuracy: f32,
287
288 pub active_effects: usize,
290
291 pub frame_rate: f32,
293
294 pub gpu_utilization: f32,
296
297 pub cache_hit_rate: f32,
299
300 pub user_satisfaction: f32,
302
303 pub resource_usage: VisualResourceUsage,
305}
306
307#[derive(Debug, Clone, Serialize, Deserialize)]
309pub struct VisualResourceUsage {
310 pub cpu_usage: f32,
312
313 pub gpu_memory_usage: f32,
315
316 pub system_memory_usage: f32,
318
319 pub effect_library_size: usize,
321
322 pub active_displays: usize,
324
325 pub render_queue_size: usize,
327}
328
329#[derive(Debug)]
332pub(crate) struct VisualEvent {
333 pub(crate) source_id: String,
334 pub(crate) event_type: VisualEventType,
335 pub(crate) intensity: f32,
336 pub(crate) color_hint: Option<ColorRGBA>,
337 pub(crate) timestamp: Instant,
338}
339
340#[derive(Debug)]
341pub(crate) struct SpatialVisualEvent {
342 pub(crate) base_event: VisualEvent,
343 pub(crate) position: Position3D,
344 pub(crate) distance: f32,
345 pub(crate) attenuation: f32,
346 pub(crate) direction_zone: DirectionZone,
347}
348
349#[derive(Debug, Clone, PartialEq, Eq)]
350pub(crate) enum VisualEventType {
351 FrequencyBand(FrequencyBand),
352 Onset,
353 Beat,
354 Downbeat,
355 SpectralChange,
356 Silence,
357 Custom(String),
358}
359
360#[derive(Debug, Clone, Copy, PartialEq, Eq)]
361pub(crate) enum FrequencyBand {
362 Low,
363 Mid,
364 High,
365}
366
367impl Default for VisualAudioMetrics {
370 fn default() -> Self {
371 Self {
372 processing_latency: 0.0,
373 sync_accuracy: 0.0,
374 active_effects: 0,
375 frame_rate: 0.0,
376 gpu_utilization: 0.0,
377 cache_hit_rate: 0.0,
378 user_satisfaction: 5.0,
379 resource_usage: VisualResourceUsage::default(),
380 }
381 }
382}
383
384impl Default for VisualResourceUsage {
385 fn default() -> Self {
386 Self {
387 cpu_usage: 0.0,
388 gpu_memory_usage: 0.0,
389 system_memory_usage: 0.0,
390 effect_library_size: 0,
391 active_displays: 0,
392 render_queue_size: 0,
393 }
394 }
395}