rosu_rate_changer/
lib.rs

1mod audio;
2mod osu;
3mod constants;
4
5use std::fs;
6use rosu_map::Beatmap;
7pub use audio::*;
8pub use osu::*;
9use std::path::{Path, PathBuf};
10
11
12pub fn rate_map_from_beatmap(map: &mut Beatmap, osu_file_path : &str,  rate : f32) -> eyre::Result<()>{
13
14    let audio_path = map.audio_file.clone();
15    let audio_output_path = PathBuf::from(format!(
16        "{}_{}.ogg",
17        Path::new(&audio_path)
18            .file_stem()
19            .and_then(|s| s.to_str())
20            .ok_or_else(|| eyre::eyre!("Invalid audio file name"))?,
21        rate
22    )).to_str().unwrap().to_string();
23    change_osu_speed(map, osu_file_path, rate, &audio_output_path)?;
24
25    let osu_file_dir = Path::new(&osu_file_path)
26        .parent()
27        .ok_or_else(|| eyre::eyre!("Invalid osu file directory"))?;
28    let audio_path = osu_file_dir.join(audio_path);
29    let audio_output_path = audio_path.with_file_name(format!(
30        "{}_{}.ogg",
31        audio_path
32            .file_stem()
33            .and_then(|s| s.to_str())
34            .ok_or_else(|| eyre::eyre!("Invalid audio file name"))?,
35        rate
36    )).to_str().unwrap().to_string();
37
38    change_audio_speed(&audio_path.to_str().unwrap(), &audio_output_path, rate)?;
39    Ok(())
40}
41
42
43pub fn rate_map(osu_file_path: &str, rate : f32) -> eyre::Result<()>{
44    let mut map: Beatmap = rosu_map::Beatmap::from_path(osu_file_path)?;
45    rate_map_from_beatmap(&mut map,osu_file_path,rate)?;
46    Ok(())
47}
48
49#[cfg(test)]
50mod tests {
51    use super::*;
52
53    #[test]
54    fn test_rate_map_different_speeds() -> eyre::Result<()> {
55        // Premier test avec une vitesse de 1.5
56        rate_map("./resources/test.osu", 1.5)?;
57
58        // Vérification que les fichiers de sortie existent
59        assert!(Path::new("./resources/test_1.5x.osu").exists());
60        assert!(Path::new("./resources/decoy_1.5.ogg").exists());
61
62        // Deuxième test avec une vitesse de 0.75
63        rate_map("./resources/test.osu", 0.75)?;
64
65        // Vérification que les fichiers de sortie existent
66        assert!(Path::new("./resources/test_0.75x.osu").exists());
67        assert!(Path::new("./resources/decoy_0.75.ogg").exists());
68
69        Ok(())
70    }
71}