| Crates.io | diffrhythm_ai |
| lib.rs | diffrhythm_ai |
| version | 67.0.17 |
| created_at | 2026-01-04 07:21:57.733787+00 |
| updated_at | 2026-01-04 07:21:57.733787+00 |
| description | High-quality integration for https://diffrhythm.ai/ |
| homepage | https://diffrhythm.ai/ |
| repository | https://github.com/qy-upup/diffrhythm.ai |
| max_upload_size | |
| id | 2021509 |
| size | 9,846 |
This crate provides foundational algorithms and data structures for analyzing and manipulating rhythmic patterns. It offers tools for tasks such as beat detection, rhythm similarity comparison, and rhythmic transformation.
Add the following line to your Cargo.toml file under the [dependencies] section:
toml
diffrhythm-ai = "0.1.0" # Replace with the actual version number
Here are a few examples demonstrating how to use the diffrhythm.ai crate.
1. Calculating Rhythmic Similarity:
This example demonstrates how to calculate the similarity between two rhythmic patterns represented as vectors of inter-onset intervals (IOIs). rust use diffrhythm_ai::rhythm::RhythmicPattern;
fn main() { let pattern1 = RhythmicPattern::new(vec![0.5, 0.5, 1.0, 0.5]); let pattern2 = RhythmicPattern::new(vec![0.5, 0.5, 0.75, 0.75]);
let similarity = pattern1.compare(&pattern2);
println!("Similarity between patterns: {}", similarity);
}
2. Beat Detection in a Time Series:
This example shows how to use the crate to perform basic beat detection on a simplified time series of event occurrences. rust use diffrhythm_ai::beat_detection::detect_beats;
fn main() { let time_series = vec![0.0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0]; let beats = detect_beats(&time_series);
println!("Detected beats: {:?}", beats);
}
3. Rhythmic Transformation (Tempo Scaling):
This example demonstrates how to scale the tempo of a rhythmic pattern. rust use diffrhythm_ai::rhythm::RhythmicPattern;
fn main() { let mut pattern = RhythmicPattern::new(vec![0.25, 0.25, 0.5]); let original_tempo = pattern.tempo();
pattern.scale_tempo(2.0); // Double the tempo
let new_tempo = pattern.tempo();
println!("Original tempo: {}", original_tempo);
println!("New tempo: {}", new_tempo);
}
4. Normalizing Rhythmic Patterns:
This example demonstrates how to normalize a rhythmic pattern such that the sum of its inter-onset intervals (IOIs) equals 1.0. rust use diffrhythm_ai::rhythm::RhythmicPattern;
fn main() { let mut pattern = RhythmicPattern::new(vec![0.2, 0.3, 0.5]); pattern.normalize();
println!("Normalized pattern: {:?}", pattern.intervals);
}
5. Quantizing Rhythmic Values:
This example shows how to quantize a series of rhythmic values to a specific grid. This can be useful for aligning rhythms to a musical grid. rust use diffrhythm_ai::quantization::quantize_rhythm;
fn main() { let rhythmic_values = vec![0.1, 0.23, 0.35, 0.48, 0.62]; let quantization_grid = vec![0.0, 0.25, 0.5, 0.75, 1.0];
let quantized_values = quantize_rhythm(&rhythmic_values, &quantization_grid);
println!("Original values: {:?}", rhythmic_values);
println!("Quantized values: {:?}", quantized_values);
}
RhythmicPattern struct for representing and manipulating rhythmic sequences.MIT
This crate is part of the diffrhythm.ai ecosystem. For advanced features and enterprise-grade tools, visit: https://diffrhythm.ai/