This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

⚡️ Paralellize MIDI amplitude inference over stems

+9 -17
+9 -17
src/synchronization/midi.rs
··· 6 6 use itertools::Itertools; 7 7 use measure_time::debug_time; 8 8 use midly::{MetaMessage, MidiMessage, TrackEvent, TrackEventKind}; 9 + use rayon::prelude::*; 9 10 use std::io::Read; 10 11 use std::{collections::HashMap, fmt::Debug, path::PathBuf}; 11 12 ··· 34 35 let (now, notes_per_instrument, markers) = 35 36 load_midi_file(&self.midi_path, progressbar); 36 37 38 + if let Some(pb) = progressbar { 39 + pb.set_length(notes_per_instrument.len() as _); 40 + pb.set_position(0); 41 + } 42 + 37 43 SyncData { 38 44 markers, 39 45 bpm: Some(tempo_to_bpm(now.tempo)), 40 - stems: HashMap::from_iter(notes_per_instrument.iter().map( 46 + stems: HashMap::from_par_iter(notes_per_instrument.par_iter().map( 41 47 |(name, notes)| { 42 48 let mut notes_per_ms = 43 49 HashMap::<usize, Vec<audio::Note>>::new(); 44 50 45 - if let Some(pb) = progressbar { 46 - pb.set_length(notes.len() as u64); 47 - pb.set_position(0); 48 - } 49 - progressbar 50 - .set_message(format!("Adding loaded notes for {name}")); 51 - 52 51 for note in notes.iter() { 53 52 notes_per_ms.entry(note.ms as usize).or_default().push( 54 53 audio::Note { ··· 57 56 velocity: note.vel, 58 57 }, 59 58 ); 60 - progressbar.inc(1); 61 59 } 62 60 63 61 let duration_ms = *notes_per_ms.keys().max().unwrap_or(&0); 64 62 65 - if let Some(pb) = progressbar { 66 - pb.set_length(duration_ms as u64 - 1); 67 - pb.set_position(0); 68 - } 69 - progressbar 70 - .set_message(format!("Infering amplitudes for {name}")); 71 - 72 63 let mut amplitudes = Vec::<f32>::new(); 73 64 let mut last_amplitude = 0.0; 74 65 for i in 0..duration_ms { ··· 80 71 .average(); 81 72 } 82 73 amplitudes.push(last_amplitude); 83 - progressbar.inc(1); 84 74 } 75 + 76 + progressbar.map(|bar| bar.inc(1)); 85 77 86 78 ( 87 79 name.clone(),