Skip to content

Commit

Permalink
Store cursor time along with accidental context in case musicxml goes…
Browse files Browse the repository at this point in the history
… backward
  • Loading branch information
hedgecrw committed Nov 18, 2024
1 parent 94a464e commit e78d5ed
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions amm_sdk/src/storage/musicxml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,7 @@ impl MusicXmlConverter {
#[allow(clippy::cast_possible_truncation, clippy::cast_possible_wrap)]
fn parse_note_element(
note: &musicxml::elements::Note,
accidental_context: &mut BTreeMap<Pitch, Accidental>,
accidental_context: &mut BTreeMap<Pitch, Vec<(usize, Accidental)>>,
time_slices: &mut BTreeMap<String, Vec<TimeSliceContainer>>,
divisions_per_quarter_note: usize,
previous_cursor: usize,
Expand Down Expand Up @@ -1179,10 +1179,21 @@ impl MusicXmlConverter {
musicxml::datatypes::AccidentalValue::FlatFlat => Accidental::DoubleFlat,
_ => Accidental::Natural,
};
accidental_context.insert(pitch, accidental);
accidental_context
.entry(pitch)
.or_default()
.push((if chord { previous_cursor } else { cursor }, accidental));
Some(accidental)
} else if let Some(accidental_list) = accidental_context.get(&pitch) {
accidental_list.iter().find_map(|(accidental_time, accidental)| {
if *accidental_time <= if chord { previous_cursor } else { cursor } {
Some(*accidental)
} else {
None
}
})
} else {
accidental_context.get(&pitch).copied()
None
};
let tuplet_details =
note
Expand Down

0 comments on commit e78d5ed

Please sign in to comment.