This repository has no description
0

Configure Feed

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

🥅 Bubble up errors from .sync_audio_with

+48 -59
+3 -1
examples/schedule-hell/src/main.rs
··· 16 16 video = video 17 17 // Sync inputs // 18 18 .sync_audio_with("schedule-hell.midi") 19 - .sync_audio_with("schedule-hell.wav"); 19 + .expect("Failed to sync from MIDI file") 20 + .sync_audio_with("schedule-hell.wav") 21 + .expect("Failed to sync from WAV file"); 20 22 21 23 if let Ok(marker) = args.value_from_str::<_, String>("--marker") { 22 24 let marker_start = video
+12 -13
src/synchronization/cue_markers.rs
··· 1 - use crate::{synchronization::sync::Syncable, ui::MaybeProgressBar}; 1 + use crate::{ 2 + synchronization::sync::{SyncData, Syncable}, 3 + ui::MaybeProgressBar, 4 + }; 5 + use anyhow::{Result, anyhow}; 2 6 use serde::Deserialize; 3 7 use serde_aux::field_attributes::deserialize_number_from_string; 4 8 use std::{collections::HashMap, io::Read, path::PathBuf, process::Stdio}; ··· 42 46 fn load( 43 47 &self, 44 48 progress: Option<&indicatif::ProgressBar>, 45 - ) -> super::sync::SyncData { 49 + ) -> Result<SyncData> { 46 50 progress.set_length(4); 47 51 progress.set_message("Running ffprobe"); 48 52 ··· 52 56 .args(["-output_format", "json"]) 53 57 .arg("-show_chapters") 54 58 .stdout(Stdio::piped()) 55 - .spawn() 56 - .expect(&format!( 57 - "Couldn't run ffprobe to get chapters of {:?}", 58 - self.path 59 - )); 59 + .spawn()?; 60 60 61 61 progress.inc(1); 62 62 progress.set_message("Getting ffprobe output"); ··· 65 65 ffprobe 66 66 .stdout 67 67 .take() 68 - .expect("Coudln't get stdout of ffprobe run") 68 + .ok_or(anyhow!("Couldn't get stdout of ffprobe"))? 69 69 .read_to_string(&mut raw_output) 70 - .expect("Couldn't read ffprobe stdout"); 70 + .map_err(|e| anyhow!("Couldn't read ffprobe stdout: {e:?}"))?; 71 71 72 72 progress.inc(1); 73 73 progress.set_message("Parsing ffprobe output"); 74 74 75 - let output: FFprobeOutput = 76 - serde_json::from_str(&raw_output).expect("Invalid ffprobe output"); 75 + let output: FFprobeOutput = serde_json::from_str(&raw_output)?; 77 76 78 77 progress.inc(1); 79 78 progress.set_message("Gathering chapters"); 80 79 81 - super::sync::SyncData { 80 + Ok(SyncData { 82 81 stems: HashMap::new(), 83 82 bpm: None, 84 83 markers: output ··· 91 90 ) 92 91 }) 93 92 .collect(), 94 - } 93 + }) 95 94 } 96 95 }
+16 -23
src/synchronization/midi.rs
··· 2 2 use super::sync::{SyncData, Syncable}; 3 3 use crate::synchronization::sync::TimestampMS; 4 4 use crate::ui::MaybeProgressBar; 5 + use anyhow::Result; 5 6 use indicatif::ProgressBar; 6 7 use itertools::Itertools; 7 8 use measure_time::debug_time; 8 9 use midly::{MetaMessage, MidiMessage, TrackEvent, TrackEventKind}; 9 10 use rayon::prelude::*; 10 - use std::io::Read; 11 11 use std::{collections::HashMap, fmt::Debug, path::PathBuf}; 12 12 13 13 pub struct MidiSynchronizer { ··· 31 31 } 32 32 } 33 33 34 - fn load(&self, progressbar: Option<&ProgressBar>) -> SyncData { 34 + fn load(&self, progressbar: Option<&ProgressBar>) -> Result<SyncData> { 35 35 let (now, notes_per_instrument, markers) = 36 - load_midi_file(&self.midi_path, progressbar); 36 + load_midi_file(&self.midi_path, progressbar)?; 37 37 38 38 if let Some(pb) = progressbar { 39 39 pb.set_length(notes_per_instrument.len() as _); 40 40 pb.set_position(0); 41 41 } 42 42 43 - SyncData { 43 + Ok(SyncData { 44 44 markers, 45 45 bpm: Some(tempo_to_bpm(now.tempo)), 46 46 stems: HashMap::from_par_iter(notes_per_instrument.par_iter().map( ··· 92 92 ) 93 93 }, 94 94 )), 95 - } 95 + }) 96 96 } 97 97 } 98 98 ··· 148 148 fn load_midi_file( 149 149 source: &PathBuf, 150 150 progressbar: Option<&ProgressBar>, 151 - ) -> ( 151 + ) -> Result<( 152 152 Now, 153 153 HashMap<String, Vec<Note>>, 154 154 HashMap<TimestampMS, String>, 155 - ) { 155 + )> { 156 156 debug_time!("load_midi_notes"); 157 157 158 158 let mut markers = HashMap::<TimestampMS, String>::new(); ··· 165 165 pb.set_position(0); 166 166 } 167 167 168 - let raw = std::fs::read(source).unwrap_or_else(|_| { 169 - panic!("Failed to read MIDI file {}", source.to_str().unwrap()) 170 - }); 171 - let midifile = midly::Smf::parse(&raw).unwrap(); 168 + let raw = std::fs::read(source)?; 169 + let midifile = midly::Smf::parse(&raw)?; 172 170 173 171 let mut timeline = Timeline::new(); 174 172 progressbar ··· 194 192 for event in track { 195 193 match event.kind { 196 194 TrackEventKind::Meta(MetaMessage::TrackName(name_bytes)) => { 197 - track_name = String::from_utf8(name_bytes.to_vec()) 198 - .unwrap_or_default(); 195 + track_name = String::from_utf8(name_bytes.to_vec())?; 199 196 } 200 197 TrackEventKind::Meta(MetaMessage::Tempo(tempo)) => { 201 198 if now.tempo == 0 { ··· 257 254 let mut stem_notes = StemNotes::new(); 258 255 for (tick, tracks) in timeline.iter().sorted_by_key(|(tick, _)| *tick) { 259 256 for (track_name, event) in tracks { 260 - if let TrackEventKind::Meta(MetaMessage::Marker(mut marker)) = 261 - event.kind 257 + if let TrackEventKind::Meta(MetaMessage::Marker(marker)) = event.kind 262 258 { 263 - let mut text = String::new(); 264 - 265 - marker 266 - .read_to_string(&mut text) 267 - .expect("Marker is not valid UTF8"); 268 - 269 - markers.insert(absolute_tick_to_ms[tick], text); 259 + markers.insert( 260 + absolute_tick_to_ms[tick], 261 + String::from_utf8(marker.to_vec())?, 262 + ); 270 263 } 271 264 272 265 if let TrackEventKind::Midi { ··· 315 308 } 316 309 } 317 310 318 - (now, result, markers) 311 + Ok((now, result, markers)) 319 312 } 320 313 321 314 fn midi_tick_to_ms(tick: u32, tempo: usize, ppq: usize) -> usize {
+7 -13
src/synchronization/sync.rs
··· 1 1 use super::audio::Stem; 2 + use anyhow::Result; 2 3 use serde::{Deserialize, Serialize}; 3 4 use std::{collections::HashMap, path::PathBuf}; 4 5 ··· 6 7 7 8 pub trait Syncable { 8 9 fn new(path: impl Into<PathBuf>) -> Self; 9 - fn load(&self, progress: Option<&indicatif::ProgressBar>) -> SyncData; 10 + fn load(&self, progress: Option<&indicatif::ProgressBar>) 11 + -> Result<SyncData>; 10 12 } 11 13 12 14 #[derive(Debug, Default, Serialize, Deserialize)] ··· 17 19 } 18 20 19 21 impl SyncData { 20 - pub fn union(self, other: SyncData) -> Self { 21 - let mut combined = Self::default(); 22 - 23 - combined.bpm = other.bpm.or(self.bpm); 24 - 25 - combined.stems.extend(self.stems); 26 - combined.stems.extend(other.stems); 27 - 28 - combined.markers.extend(self.markers); 29 - combined.markers.extend(other.markers); 30 - 31 - combined 22 + pub fn merge_with(&mut self, other: SyncData) { 23 + self.bpm = other.bpm.or(self.bpm); 24 + self.stems.extend(other.stems); 25 + self.markers.extend(other.markers); 32 26 } 33 27 }
-1
src/video/encoders/mod.rs
··· 4 4 video::{encoders::vgv::VGVTranscodeMode, engine::EngineOutput}, 5 5 }; 6 6 use anyhow::Result; 7 - use rayon::iter::ParallelIterator; 8 7 use std::path::PathBuf; 9 8 10 9 pub mod ffmpeg;
-1
src/video/encoders/vgv.rs
··· 7 7 use ::vgv::Transcoder; 8 8 use anyhow::Result; 9 9 use itertools::Itertools; 10 - use rayon::iter::ParallelIterator; 11 10 use std::{ops::ControlFlow, path::PathBuf}; 12 11 13 12 #[derive(strum_macros::Display)]
+10 -7
src/video/video.rs
··· 8 8 ui::{self, Log, Pretty}, 9 9 video::hooks::{AttachHooks, CommandAction, Hook}, 10 10 }; 11 + use anyhow::Result; 11 12 use chrono::DateTime; 12 13 use measure_time::debug_time; 13 14 use std::{ ··· 153 154 } 154 155 } 155 156 156 - pub fn sync_audio_with(self, sync_data_path: impl Into<PathBuf>) -> Self { 157 + pub fn sync_audio_with( 158 + mut self, 159 + filepath: impl Into<PathBuf>, 160 + ) -> Result<Self> { 157 161 debug_time!("sync_audio_with"); 158 162 159 - let file_path: PathBuf = sync_data_path.into(); 163 + let file_path: PathBuf = filepath.into(); 160 164 let pb = Some(&self.progress_bars.loading); 161 165 162 166 let syncdata = match file_path.extension().and_then(|s| s.to_str()) { ··· 167 171 CueMarkersSynchronizer::new(file_path.clone()).load(pb) 168 172 } 169 173 _ => panic!("Unsupported sync data format"), 170 - }; 174 + }?; 171 175 172 176 let pb = pb.unwrap(); 173 177 ··· 202 206 ), 203 207 ); 204 208 205 - return Self { 206 - syncdata: self.syncdata.union(syncdata), 207 - ..self 208 - }; 209 + self.syncdata.merge_with(syncdata); 210 + 211 + Ok(self) 209 212 } 210 213 211 214 pub fn ms_to_frames(&self, ms: usize) -> usize {