Skip to content

Commit

Permalink
ignore initial unplayable lines
Browse files Browse the repository at this point in the history
  • Loading branch information
Noah committed Jul 29, 2023
1 parent 572a95f commit af2fb14
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "guitar-tab-generator"
version = "1.1.2"
version = "1.1.3"
edition = "2021"
authors = ["Noah Baculi <[email protected]>"]
description = "Generate fingerstyle guitar tabs based on the difficulty of different finger positions"
Expand Down
41 changes: 39 additions & 2 deletions src/arrangement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,6 @@ pub fn create_arrangements(
.iter()
.filter(|line| matches!(line, Line::Playable(_)))
.collect_vec();

if input_playable_lines.is_empty() {
let empty_compositions = vec![
Arrangement {
Expand All @@ -286,8 +285,19 @@ pub fn create_arrangements(
return Ok(empty_compositions);
}

let first_playable_index = input_lines
.iter()
.position(|line| matches!(line, Line::Playable(_)))
.unwrap_or(0);

let lines = input_lines
.iter()
.skip(first_playable_index)
.cloned()
.collect_vec();

let pitch_fingering_candidates: Vec<Line<BeatVec<PitchVec<PitchFingering>>>> =
validate_fingerings(&guitar, &input_lines)?;
validate_fingerings(&guitar, &lines)?;

let measure_break_indices: Vec<usize> = pitch_fingering_candidates
.iter()
Expand Down Expand Up @@ -463,6 +473,33 @@ mod test_create_arrangements {
assert_eq!(arrangements, expected_arrangements);
}
#[test]
fn empty_start_lines_input() {
let input_pitches: Vec<Line<BeatVec<Pitch>>> = vec![
Line::Rest,
Line::MeasureBreak,
Line::Rest,
Line::Playable(vec![Pitch::E4]),
Line::Rest,
];

let arrangements = create_arrangements(Guitar::default(), input_pitches, 1).unwrap();

let expected_arrangements: Vec<Arrangement> = vec![Arrangement {
lines: vec![
Line::Playable(vec![PitchFingering {
pitch: Pitch::E4,
string_number: StringNumber::new(1).unwrap(),
fret: 0,
}]),
Line::Rest,
],
difficulty: 0,
max_fret_span: 0,
}];

assert_eq!(arrangements, expected_arrangements);
}
#[test]
fn zero_arrangements_requested() {
let input_pitches: Vec<Line<BeatVec<Pitch>>> = vec![Line::Playable(vec![Pitch::E4])];

Expand Down
6 changes: 6 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,14 @@ pub fn wrapper_create_arrangements(
Err(e) => return Err(anyhow!(format!("{}", e))),
};

let first_playable_index = input_lines
.iter()
.position(|line| matches!(line, arrangement::Line::Playable(_)))
.unwrap_or(0);

let pitches: Vec<BeatVec<String>> = input_lines
.iter()
.skip(first_playable_index)
.map(|line| match line {
arrangement::Line::Playable(pitches) => {
pitches.iter().map(|p| p.plain_text()).collect()
Expand Down

0 comments on commit af2fb14

Please sign in to comment.