rgc_chart/models/osu/
sound.rs1use std::str::FromStr;
2
3#[derive(Debug, Clone, PartialEq)]
4pub enum SampleSet {
5 Normal,
6 Soft,
7 Drum,
8}
9
10impl FromStr for SampleSet {
11 type Err = String;
12
13 fn from_str(s: &str) -> Result<Self, Self::Err> {
14 match s {
15 "Normal" => Ok(SampleSet::Normal),
16 "Soft" => Ok(SampleSet::Soft),
17 "Drum" => Ok(SampleSet::Drum),
18 _ => Err(format!("Invalid SampleSet: {}", s)),
19 }
20 }
21}
22
23impl ToString for SampleSet {
24 fn to_string(&self) -> String {
25 match self {
26 SampleSet::Normal => "Normal".to_string(),
27 SampleSet::Soft => "Soft".to_string(),
28 SampleSet::Drum => "Drum".to_string(),
29 }
30 }
31}
32
33#[derive(Debug, Clone, PartialEq)]
34pub struct HitSample {
35 pub normal_set: u8,
36
37 pub addition_set: u8,
38
39 pub index: usize,
40
41 pub volume: u8,
42
43 pub filename: String,
44}
45
46impl Default for HitSample {
47 fn default() -> Self {
48 Self {
49 normal_set: 0,
50 addition_set: 0,
51 index: 0,
52 volume: 0,
53 filename: String::new(),
54 }
55 }
56}
57
58impl FromStr for HitSample {
59 type Err = String;
60
61 fn from_str(s: &str) -> Result<Self, Self::Err> {
62 let parts: Vec<&str> = s.split(':').collect();
63
64 if parts.len() < 4 {
65 return Ok(HitSample::default());
66 }
67
68 let normal_set = parts[0].parse::<u8>().unwrap_or(0);
69 let addition_set = parts[1].parse::<u8>().unwrap_or(0);
70 let index = parts[2].parse::<usize>().unwrap_or(0);
71 let volume = parts[3].parse::<u8>().unwrap_or(0);
72 let filename = if parts.len() > 4 {
73 parts[4].to_string()
74 } else {
75 String::new()
76 };
77
78 Ok(HitSample {
79 normal_set,
80 addition_set,
81 index,
82 volume,
83 filename,
84 })
85 }
86}
87
88impl HitSample {
89 pub fn to_osu_format(&self) -> String {
90 format!("{}:{}:{}:{}:{}",
91 self.normal_set,
92 self.addition_set,
93 self.index,
94 self.volume,
95 self.filename)
96 }
97}