| Crates.io | sm_tomusic_ai |
| lib.rs | sm_tomusic_ai |
| version | 67.0.74 |
| created_at | 2026-01-08 10:17:49.231822+00 |
| updated_at | 2026-01-08 10:17:49.231822+00 |
| description | High-quality integration for https://tomusic.ai/ |
| homepage | https://tomusic.ai/ |
| repository | https://github.com/qy-upup/sm-tomusic-ai |
| max_upload_size | |
| id | 2029913 |
| size | 11,417 |
A Rust crate designed to provide core functionalities for music information retrieval and symbolic music processing, tailored for integration with the ToMusic.ai platform. This crate offers tools for analyzing, manipulating, and generating music data.
To use sm-tomusic-ai in your Rust project, add the following to your Cargo.toml file:
toml
[dependencies]
sm-tomusic-ai = "0.1.0" # Replace with the latest version
Here are a few examples demonstrating how to use sm-tomusic-ai:
1. Extracting Melodic Contour from a MIDI File: rust use sm_tomusic_ai::midi;
fn main() -> Result<(), Box
println!("Extracted Melody: {:?}", melody);
Ok(())
}
This example demonstrates how to extract the primary melodic line from a MIDI file using the extract_melody function. The function returns a vector representing the melodic contour. Error handling is included for robust operation.
2. Transposing a Musical Piece: rust use sm_tomusic_ai::music_theory;
fn main() { let notes = vec!["C", "D", "E", "F", "G"]; let transposed_notes = music_theory::transpose(notes, 2); // Transpose up by 2 semitones
println!("Original Notes: {:?}", notes);
println!("Transposed Notes: {:?}", transposed_notes);
}
This example showcases the transpose function, which allows you to transpose a sequence of musical notes by a specified number of semitones. It takes a vector of notes and a transposition interval as input.
3. Generating a Simple Chord Progression: rust use sm_tomusic_ai::composition;
fn main() { let key = "C"; let progression = composition::generate_chord_progression(key, 4); // Generate a 4-chord progression in C major
println!("Generated Chord Progression: {:?}", progression);
}
This example uses the generate_chord_progression function to create a basic chord progression based on a given key. The function returns a vector of chord names.
4. Calculating Intervallic Distance between two Notes: rust use sm_tomusic_ai::music_theory;
fn main() { let note1 = "C"; let note2 = "G"; let interval = music_theory::calculate_interval(note1, note2);
println!("Interval between {} and {} is: {}", note1, note2, interval);
}
This example uses the calculate_interval function to determine the intervallic distance between two musical notes.
5. Detecting Beat Onsets in an Audio File (Placeholder - Requires Audio Processing Dependencies):
rust
// Note: This example is a placeholder and requires integration with an audio processing library.
// The sm-tomusic-ai crate may not directly handle audio processing.
// use sm_tomusic_ai::audio;
// fn main() -> Result<(), Box
// println!("Detected Beat Onsets: {:?}", onsets); // Ok(()) // }
This placeholder illustrates the potential for future audio processing functionality. This would require integrating with an external audio processing library.
MIT
This crate is part of the sm-tomusic-ai ecosystem. For advanced features and enterprise-grade tools, visit: https://tomusic.ai/