Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,20 @@ pub fn generate_song_txt(header: &Header, lines: &[Line]) -> Result<String> {
ref text,
} => song_txt_str
.push_str(format!("F {} {} {} {}\n", start, duration, pitch, text).as_ref()),
Note::Rap {
start,
duration,
pitch,
ref text,
} => song_txt_str
.push_str(format!("R {} {} {} {}\n", start, duration, pitch, text).as_ref()),
Note::RapGolden {
start,
duration,
pitch,
ref text,
} => song_txt_str
.push_str(format!("G {} {} {} {}\n", start, duration, pitch, text).as_ref()),
Note::PlayerChange { player } => {
song_txt_str.push_str(format!("P{}\n", player).as_ref())
}
Expand Down
12 changes: 12 additions & 0 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,18 @@ pub fn parse_txt_lines_str(txt_str: &str) -> Result<Vec<Line>> {
pitch: note_pitch,
text: String::from(note_text),
},
"R" => Note::Rap {
start: note_start,
duration: note_duration,
pitch: note_pitch,
text: String::from(note_text),
},
"G" => Note::RapGolden {
start: note_start,
duration: note_duration,
pitch: note_pitch,
text: String::from(note_text),
},
_ => bail!(ErrorKind::UnknownNoteType(line_count)),
};

Expand Down
40 changes: 35 additions & 5 deletions src/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,28 @@ pub enum Note {
/// text or syllable of the note
text: String,
},
/// a rap note (pitch is ignored, normal points)
Rap {
/// start of the note
start: i32,
/// duration of the note
duration: i32,
/// pitch of the note (in semitones with C2 being 0)
pitch: i32, //pitch might not be needed but not including it might lose data from orig file
/// text or syllable of the note
text: String,
},
/// a golden rap note (pitch is ignored, 2x points)
RapGolden {
/// start of the note
start: i32,
/// duration of the note
duration: i32,
/// pitch of the note (in semitones with C2 being 0)
pitch: i32, //pitch might not be needed but not including it might lose data from orig file
/// text or syllable of the note
text: String,
},
/// player change indicator for duet mode
PlayerChange {
/// player to change to
Expand All @@ -168,7 +190,9 @@ impl Note {
match *self {
Note::Regular { start, .. }
| Note::Golden { start, .. }
| Note::Freestyle { start, .. } => Some(start),
| Note::Freestyle { start, .. }
| Note::Rap { start, .. }
| Note::RapGolden { start, .. } => Some(start),
Note::PlayerChange { .. } => None,
}
}
Expand All @@ -178,7 +202,9 @@ impl Note {
match *self {
Note::Regular { duration, .. }
| Note::Golden { duration, .. }
| Note::Freestyle { duration, .. } => Some(duration),
| Note::Freestyle { duration, .. }
| Note::Rap { duration, .. }
| Note::RapGolden { duration, .. } => Some(duration),
Note::PlayerChange { .. } => None,
}
}
Expand All @@ -188,7 +214,9 @@ impl Note {
match *self {
Note::Regular { pitch, .. }
| Note::Golden { pitch, .. }
| Note::Freestyle { pitch, .. } => Some(pitch),
| Note::Freestyle { pitch, .. }
| Note::Rap { pitch, .. }
| Note::RapGolden { pitch, .. } => Some(pitch),
Note::PlayerChange { .. } => None,
}
}
Expand All @@ -198,7 +226,9 @@ impl Note {
match *self {
Note::Regular { ref text, .. }
| Note::Golden { ref text, .. }
| Note::Freestyle { ref text, .. } => Some(text),
| Note::Freestyle { ref text, .. }
| Note::Rap { ref text, .. }
| Note::RapGolden { ref text, .. } => Some(text),
Note::PlayerChange { .. } => None,
}
}
Expand All @@ -207,7 +237,7 @@ impl Note {
pub fn player(&self) -> Option<i32> {
match *self {
Note::PlayerChange { player, .. } => Some(player),
Note::Regular { .. } | Note::Golden { .. } | Note::Freestyle { .. } => None,
Note::Regular { .. } | Note::Golden { .. } | Note::Freestyle { .. } | Note::Rap { .. } | Note::RapGolden { .. } => None,
}
}
}
Expand Down
82 changes: 82 additions & 0 deletions tests/txt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,88 @@ fn simple_txt_lines() {
assert_eq!(lines, parse_txt_lines_str(txt).unwrap());
}



#[test]
fn rap_notes() {
let txt = include_str!("txts/rap_notes.txt");
let lines = vec![
Line {
start: 0,
rel: None,
notes: vec![
Note::Rap {
start: 0,
duration: 4,
pitch: 59,
text: String::from("Test "),
},
Note::Rap {
start: 4,
duration: 4,
pitch: 59,
text: String::from("I"),
},
Note::Rap {
start: 8,
duration: 4,
pitch: 59,
text: String::from("'m "),
},
Note::RapGolden {
start: 12,
duration: 4,
pitch: 59,
text: String::from("test"),
},
Note::Rap {
start: 16,
duration: 4,
pitch: 59,
text: String::from("ing."),
},
],
},
Line {
start: 20,
rel: None,
notes: vec![
Note::Golden {
start: 24,
duration: 4,
pitch: 59,
text: String::from("Test "),
},
Note::Regular {
start: 28,
duration: 4,
pitch: 59,
text: String::from("I"),
},
Note::Regular {
start: 32,
duration: 4,
pitch: 59,
text: String::from("'m "),
},
Note::Freestyle {
start: 36,
duration: 4,
pitch: 59,
text: String::from("test"),
},
Note::Freestyle {
start: 40,
duration: 4,
pitch: 59,
text: String::from("ing."),
},
],
},
];
assert_eq!(lines, parse_txt_lines_str(txt).unwrap());
}

#[test]
fn komma_in_float_number() {
let txt = include_str!("txts/komma_in_float.txt");
Expand Down
17 changes: 17 additions & 0 deletions tests/txts/rap_notes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#TITLE:Testsong
#ARTIST:Testartist
#MP3:Testfile.mp3
#GAP:666
#BPM:123
R 0 4 59 Test
R 4 4 59 I
R 8 4 59 'm
G 12 4 59 test
R 16 4 59 ing.
- 20
* 24 4 59 Test
: 28 4 59 I
: 32 4 59 'm
F 36 4 59 test
F 40 4 59 ing.
E