1use serde::{Deserialize, Serialize};
4use std::collections::HashMap;
5
6#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct AnalysisResult {
9 pub tempo: Option<TempoResult>,
11
12 pub beat: Option<BeatResult>,
14
15 pub key: Option<KeyResult>,
17
18 pub chord: Option<ChordResult>,
20
21 pub melody: Option<MelodyResult>,
23
24 pub structure: Option<StructureResult>,
26
27 pub genre: Option<GenreResult>,
29
30 pub mood: Option<MoodResult>,
32
33 pub spectral: Option<SpectralResult>,
35
36 pub rhythm: Option<RhythmResult>,
38
39 pub harmonic: Option<HarmonicResult>,
41
42 pub sample_rate: f32,
44
45 pub duration: f32,
47}
48
49#[derive(Debug, Clone, Serialize, Deserialize)]
51pub struct TempoResult {
52 pub bpm: f32,
54
55 pub confidence: f32,
57
58 pub stability: f32,
60
61 pub alternatives: Vec<(f32, f32)>, }
64
65#[derive(Debug, Clone, Serialize, Deserialize)]
67pub struct BeatResult {
68 pub beat_times: Vec<f32>,
70
71 pub downbeat_times: Vec<f32>,
73
74 pub beat_confidence: Vec<f32>,
76
77 pub time_signature: Option<(u8, u8)>,
79}
80
81#[derive(Debug, Clone, Serialize, Deserialize)]
83pub struct KeyResult {
84 pub key: String,
86
87 pub root: u8,
89
90 pub is_major: bool,
92
93 pub confidence: f32,
95
96 pub profile_correlations: Vec<f32>,
98}
99
100#[derive(Debug, Clone, Serialize, Deserialize)]
102pub struct ChordResult {
103 pub chords: Vec<ChordLabel>,
105
106 pub progressions: Vec<String>,
108
109 pub complexity: f32,
111}
112
113#[derive(Debug, Clone, Serialize, Deserialize)]
115pub struct ChordLabel {
116 pub start: f32,
118
119 pub end: f32,
121
122 pub label: String,
124
125 pub confidence: f32,
127}
128
129#[derive(Debug, Clone, Serialize, Deserialize)]
131pub struct MelodyResult {
132 pub pitch_contour: Vec<f32>,
134
135 pub time_points: Vec<f32>,
137
138 pub confidence: Vec<f32>,
140
141 pub range: (f32, f32),
143
144 pub complexity: f32,
146}
147
148#[derive(Debug, Clone, Serialize, Deserialize)]
150pub struct StructureResult {
151 pub segments: Vec<Segment>,
153
154 pub similarity_matrix: Vec<f32>,
156
157 pub matrix_size: usize,
159
160 pub complexity: f32,
162}
163
164#[derive(Debug, Clone, Serialize, Deserialize)]
166pub struct Segment {
167 pub start: f32,
169
170 pub end: f32,
172
173 pub label: String,
175
176 pub confidence: f32,
178}
179
180#[derive(Debug, Clone, Serialize, Deserialize)]
182pub struct GenreResult {
183 pub genres: HashMap<String, f32>,
185
186 pub top_genre_name: String,
188
189 pub top_genre_confidence: f32,
191}
192
193impl GenreResult {
194 #[must_use]
196 pub fn top_genre(&self) -> (&str, f32) {
197 (&self.top_genre_name, self.top_genre_confidence)
198 }
199}
200
201#[derive(Debug, Clone, Serialize, Deserialize)]
203pub struct MoodResult {
204 pub valence: f32,
206
207 pub arousal: f32,
209
210 pub moods: HashMap<String, f32>,
212
213 pub intensity: f32,
215}
216
217#[derive(Debug, Clone, Serialize, Deserialize)]
219pub struct SpectralResult {
220 pub centroid: Vec<f32>,
222
223 pub rolloff: Vec<f32>,
225
226 pub flux: Vec<f32>,
228
229 pub contrast: Vec<Vec<f32>>,
231
232 pub mean_centroid: f32,
234
235 pub mean_rolloff: f32,
237
238 pub mean_flux: f32,
240}
241
242#[derive(Debug, Clone, Serialize, Deserialize)]
244pub struct RhythmResult {
245 pub onset_strength: Vec<f32>,
247
248 pub onset_times: Vec<f32>,
250
251 pub patterns: Vec<RhythmPattern>,
253
254 pub complexity: f32,
256
257 pub syncopation: f32,
259}
260
261#[derive(Debug, Clone, Serialize, Deserialize)]
263pub struct RhythmPattern {
264 pub start: f32,
266
267 pub duration: f32,
269
270 pub description: String,
272
273 pub strength: f32,
275}
276
277#[derive(Debug, Clone, Serialize, Deserialize)]
279pub struct HarmonicResult {
280 pub harmonic_energy: Vec<f32>,
282
283 pub percussive_energy: Vec<f32>,
285
286 pub hpr_ratio: f32,
288
289 pub pitch_class_profile: Vec<f32>,
291
292 pub chroma: Vec<Vec<f32>>,
294}
295
296#[derive(Debug, Clone, Serialize, Deserialize)]
298pub struct LoudnessResult {
299 pub integrated_loudness: f32,
301
302 pub loudness_range: f32,
304
305 pub peak_loudness: f32,
307
308 pub true_peak: f32,
310}
311
312bitflags::bitflags! {
313 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
315 pub struct FeatureSet: u32 {
316 const SPECTRAL = 0b0000_0001;
318 const RHYTHM = 0b0000_0010;
320 const HARMONIC = 0b0000_0100;
322 const TEMPO = 0b0000_1000;
324 const KEY = 0b0001_0000;
326 const CHORD = 0b0010_0000;
328 const MELODY = 0b0100_0000;
330 const ALL = 0b0111_1111;
332 }
333}
334
335impl Default for FeatureSet {
336 fn default() -> Self {
337 Self::ALL
338 }
339}