Skip to content

Commit

Permalink
sorting notes in midi_parse.rs
Browse files Browse the repository at this point in the history
wor-around of issue: Levitanus/rea-rs#1
  • Loading branch information
Levitanus committed Feb 15, 2023
1 parent bc93a9f commit f26f81b
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions rea-score/src/dom/midi_parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ pub fn parse_events<'a, T: ProbablyMutable>(
take: &'a Take<T>,
) -> Result<Box<dyn Iterator<Item = ParsedEvent> + 'a>, ReaperError>
{
let notes = rea_rs::FilterNotes::new(events.clone());
let mut notes: Vec<_> =
rea_rs::FilterNotes::new(events.clone()).collect();
notes.sort_by(|a, b| {
a.start_in_ppq
.partial_cmp(&b.start_in_ppq)
.expect("can not compare event positions")
});
let notations = events
.filter_map(|ev| {
let msg = ev.message().get_raw();
Expand All @@ -29,7 +35,7 @@ pub fn parse_events<'a, T: ProbablyMutable>(
))
})
.collect::<Vec<_>>();
let parsed_events = notes.map(move |note| {
let parsed_events = notes.into_iter().map(move |note| {
let position =
RelativePosition::from(AbsolutePosition::from(
Position::from_ppq(note.start_in_ppq, take),
Expand Down Expand Up @@ -281,10 +287,10 @@ impl ParsedEvent {
self.notations = self
.notations
.into_iter()
.filter_map(|not| {
match self.event.push_notation(not.clone()) {
.filter_map(|note| {
match self.event.push_notation(note.clone()) {
Ok(_) => None,
Err(_) => Some(not),
Err(_) => Some(note),
}
})
.collect();
Expand Down

0 comments on commit f26f81b

Please sign in to comment.