This repository has no description
0

Configure Feed

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

1use super::audio::Stem; 2use anyhow::Result; 3use serde::{Deserialize, Serialize}; 4use std::{collections::HashMap, fmt::Display, ops::Range, path::PathBuf}; 5 6pub type TimestampMS = usize; 7 8pub trait Syncable { 9 fn new(path: impl Into<PathBuf>) -> Self; 10 fn load(&self, progress: Option<&indicatif::ProgressBar>) 11 -> Result<SyncData>; 12} 13 14#[derive(Debug, Default, Serialize, Deserialize)] 15pub struct SyncData { 16 pub stems: HashMap<String, Stem>, 17 pub markers: HashMap<TimestampMS, String>, 18 pub bpm: Option<usize>, 19} 20 21impl SyncData { 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); 26 } 27 28 pub fn marker_ms_range( 29 &self, 30 marker: impl Display, 31 ) -> Option<Range<TimestampMS>> { 32 let start = self.markers.iter().find_map(|(&ms, m)| { 33 if m == &marker.to_string() { 34 Some(ms) 35 } else { 36 None 37 } 38 })?; 39 40 let end = self.markers.iter().find_map(|(&ms, m)| { 41 if m == &marker.to_string() && ms > start { 42 Some(ms) 43 } else { 44 None 45 } 46 })?; 47 48 Some(start..end) 49 } 50}