From 2c59b1acfdd74d0239dbb19069eb649c17d67358 Mon Sep 17 00:00:00 2001 From: unspeaker Date: Sat, 26 Apr 2025 13:31:09 +0300 Subject: [PATCH] test: fix coverage run --- crates/app/src/model.rs | 4 +-- crates/app/src/view.rs | 14 ++++----- crates/midi/src/clip.rs | 32 +++++++++++++++++++++ crates/midi/src/clip/clip_editor.rs | 44 ++++++----------------------- crates/midi/src/clip/clip_launch.rs | 20 +++++-------- deps/rust-jack | 2 +- 6 files changed, 58 insertions(+), 58 deletions(-) diff --git a/crates/app/src/model.rs b/crates/app/src/model.rs index 8a876d9f..17318f0c 100644 --- a/crates/app/src/model.rs +++ b/crates/app/src/model.rs @@ -287,14 +287,14 @@ pub trait HasScenes: HasSelection + HasEditor + Send + Sync { impl Scene { /// Returns the pulse length of the longest clip in the scene - fn pulses (&self) -> usize { + pub fn pulses (&self) -> usize { self.clips.iter().fold(0, |a, p|{ a.max(p.as_ref().map(|q|q.read().unwrap().length).unwrap_or(0)) }) } /// Returns true if all clips in the scene are /// currently playing on the given collection of tracks. - fn is_playing (&self, tracks: &[Track]) -> bool { + pub fn is_playing (&self, tracks: &[Track]) -> bool { self.clips.iter().any(|clip|clip.is_some()) && self.clips.iter().enumerate() .all(|(track_index, clip)|match clip { Some(c) => tracks diff --git a/crates/app/src/view.rs b/crates/app/src/view.rs index 4bf06558..2d575de7 100644 --- a/crates/app/src/view.rs +++ b/crates/app/src/view.rs @@ -480,7 +480,7 @@ impl Tek { }) } - fn update_clock (&self) { + pub fn update_clock (&self) { ViewCache::update_clock(&self.view_cache, self.clock(), self.size.w() > 80) } @@ -560,7 +560,7 @@ fn view_status ( ))) } -fn button_play_pause (playing: bool) -> impl Content { +pub(crate) fn button_play_pause (playing: bool) -> impl Content { let compact = true;//self.is_editing(); Tui::bg( if playing{Rgb(0,128,0)}else{Rgb(128,64,0)}, @@ -577,7 +577,7 @@ fn button_play_pause (playing: bool) -> impl Content { ) } -fn view_meter <'a> (label: &'a str, value: f32) -> impl Content + 'a { +pub (crate) fn view_meter <'a> (label: &'a str, value: f32) -> impl Content + 'a { col!( FieldH(ItemPalette::G[128], label, format!("{:>+9.3}", value)), Fixed::xy(if value >= 0.0 { 13 } @@ -598,7 +598,7 @@ fn view_meter <'a> (label: &'a str, value: f32) -> impl Content + 'a { else { Green }, ()))) } -fn view_meters (values: &[f32;2]) -> impl Content + use<'_> { +pub(crate) fn view_meters (values: &[f32;2]) -> impl Content + use<'_> { Bsp::s( format!("L/{:>+9.3}", values[0]), format!("R/{:>+9.3}", values[1]), @@ -784,7 +784,7 @@ impl ViewCache { pub const TIME_EMPTY: &'static str = "-.---s"; pub const BPM_EMPTY: &'static str = "---.---"; - pub(crate) fn track_counter (cache: &Arc>, track: usize, tracks: usize) + pub fn track_counter (cache: &Arc>, track: usize, tracks: usize) -> Arc> { let data = (track, tracks); @@ -792,7 +792,7 @@ impl ViewCache { cache.read().unwrap().trks.view.clone() } - pub(crate) fn scene_add (cache: &Arc>, scene: usize, scenes: usize, is_editing: bool) + pub fn scene_add (cache: &Arc>, scene: usize, scenes: usize, is_editing: bool) -> impl Content { let data = (scene, scenes); @@ -800,7 +800,7 @@ impl ViewCache { button_3("S", "add scene", cache.read().unwrap().scns.view.clone(), is_editing) } - pub(crate) fn update_clock (cache: &Arc>, clock: &Clock, compact: bool) { + pub fn update_clock (cache: &Arc>, clock: &Clock, compact: bool) { let rate = clock.timebase.sr.get(); let chunk = clock.chunk.load(Relaxed) as f64; let lat = chunk / rate * 1000.; diff --git a/crates/midi/src/clip.rs b/crates/midi/src/clip.rs index ce78907b..a7f998ed 100644 --- a/crates/midi/src/clip.rs +++ b/crates/midi/src/clip.rs @@ -1,9 +1,41 @@ +use crate::*; + mod clip_editor; pub use self::clip_editor::*; mod clip_launch; pub use self::clip_launch::*; mod clip_model; pub use self::clip_model::*; mod clip_play; pub use self::clip_play::*; mod clip_view; pub use self::clip_view::*; +pub trait HasEditor { + fn editor (&self) -> &Option; + fn editor_mut (&mut self) -> &Option; + fn is_editing (&self) -> bool { true } + fn editor_w (&self) -> usize { 0 } + fn editor_h (&self) -> usize { 0 } +} + +#[macro_export] macro_rules! has_editor { + (|$self:ident: $Struct:ident|{ + editor = $e0:expr; + editor_w = $e1:expr; + editor_h = $e2:expr; + is_editing = $e3:expr; + }) => { + impl HasEditor for $Struct { + fn editor (&$self) -> &Option { &$e0 } + fn editor_mut (&mut $self) -> &Option { &mut $e0 } + fn editor_w (&$self) -> usize { $e1 } + fn editor_h (&$self) -> usize { $e2 } + fn is_editing (&$self) -> bool { $e3 } + } + }; + (|$self:ident:$Struct:ident$(<$($L:lifetime),*$($T:ident$(:$U:path)?),*>)?|$cb:expr) => { + impl $(<$($L),*$($T $(: $U)?),*>)? HasEditor for $Struct $(<$($L),*$($T),*>)? { + fn editor (&$self) -> &MidiEditor { &$cb } + } + }; +} + #[cfg(test)] #[test] pub fn test_midi_clip () { let clip = MidiClip::stop_all(); println!("{clip:?}"); diff --git a/crates/midi/src/clip/clip_editor.rs b/crates/midi/src/clip/clip_editor.rs index b6090442..407269b4 100644 --- a/crates/midi/src/clip/clip_editor.rs +++ b/crates/midi/src/clip/clip_editor.rs @@ -5,7 +5,7 @@ use crate::*; pub struct MidiEditor { pub mode: PianoHorizontal, pub size: Measure, - keys: SourceIter<'static> + pub keys: SourceIter<'static> } impl std::fmt::Debug for MidiEditor { @@ -80,11 +80,9 @@ provide!(usize: |self: MidiEditor| { }); impl MidiEditor { - //fn clip_length (&self) -> usize { - //self.clip().as_ref().map(|p|p.read().unwrap().length).unwrap_or(1) - //} + /// Put note at current position - fn put_note (&mut self, advance: bool) { + pub fn put_note (&mut self, advance: bool) { let mut redraw = false; if let Some(clip) = self.clip() { let mut clip = clip.write().unwrap(); @@ -113,6 +111,7 @@ impl MidiEditor { self.mode.redraw(); } } + pub fn clip_status (&self) -> impl Content + '_ { let (color, name, length, looped) = if let Some(clip) = self.clip().as_ref().map(|p|p.read().unwrap()) { (clip.color, clip.name.clone(), clip.length, clip.looped) @@ -122,6 +121,7 @@ impl MidiEditor { FieldH(color, "Loop", looped.to_string()) ) } + pub fn edit_status (&self) -> impl Content + '_ { let (color, length) = if let Some(clip) = self.clip().as_ref().map(|p|p.read().unwrap()) { (clip.color, clip.length) @@ -137,6 +137,10 @@ impl MidiEditor { FieldH(color, "Note", format!("{note_name} {note_pos} {note_len}")), ) } + + //fn clip_length (&self) -> usize { + //self.clip().as_ref().map(|p|p.read().unwrap().length).unwrap_or(1) + //} } impl TimeRange for MidiEditor { @@ -235,33 +239,3 @@ impl Command for MidiEditCommand { Ok(None) } } - -pub trait HasEditor { - fn editor (&self) -> &Option; - fn editor_mut (&mut self) -> &Option; - fn is_editing (&self) -> bool { true } - fn editor_w (&self) -> usize { 0 } - fn editor_h (&self) -> usize { 0 } -} - -#[macro_export] macro_rules! has_editor { - (|$self:ident: $Struct:ident|{ - editor = $e0:expr; - editor_w = $e1:expr; - editor_h = $e2:expr; - is_editing = $e3:expr; - }) => { - impl HasEditor for $Struct { - fn editor (&$self) -> &Option { &$e0 } - fn editor_mut (&mut $self) -> &Option { &mut $e0 } - fn editor_w (&$self) -> usize { $e1 } - fn editor_h (&$self) -> usize { $e2 } - fn is_editing (&$self) -> bool { $e3 } - } - }; - (|$self:ident:$Struct:ident$(<$($L:lifetime),*$($T:ident$(:$U:path)?),*>)?|$cb:expr) => { - impl $(<$($L),*$($T $(: $U)?),*>)? HasEditor for $Struct $(<$($L),*$($T),*>)? { - fn editor (&$self) -> &MidiEditor { &$cb } - } - }; -} diff --git a/crates/midi/src/clip/clip_launch.rs b/crates/midi/src/clip/clip_launch.rs index 1d87cdfb..7c17903b 100644 --- a/crates/midi/src/clip/clip_launch.rs +++ b/crates/midi/src/clip/clip_launch.rs @@ -17,10 +17,9 @@ pub trait HasPlayClip: HasClock { fn pulses_since_start (&self) -> Option { if let Some((started, Some(_))) = self.play_clip().as_ref() { let elapsed = self.clock().playhead.pulse.get() - started.pulse.get(); - Some(elapsed) - } else { - None + return Some(elapsed) } + None } fn pulses_since_start_looped (&self) -> Option<(f64, f64)> { @@ -29,16 +28,13 @@ pub trait HasPlayClip: HasClock { let length = clip.read().unwrap().length.max(1); // prevent div0 on empty clip let times = (elapsed as usize / length) as f64; let elapsed = (elapsed as usize % length) as f64; - Some((times, elapsed)) - } else { - None + return Some((times, elapsed)) } + None } fn enqueue_next (&mut self, clip: Option<&Arc>>) { - let start = self.clock().next_launch_pulse() as f64; - let instant = Moment::from_pulse(self.clock().timebase(), start); - *self.next_clip_mut() = Some((instant, clip.cloned())); + *self.next_clip_mut() = Some((self.clock().next_launch_instant(), clip.cloned())); *self.reset_mut() = true; } @@ -82,9 +78,7 @@ pub trait HasPlayClip: HasClock { let target = t.pulse.get() + clip.length as f64; let current = clock.playhead.pulse.get(); if target > current { - time = format!("-{:>}", clock.timebase.format_beats_0( - target - current - )).into() + time = format!("-{:>}", clock.timebase.format_beats_0(target - current)).into() } } else { name = "Stop".to_string().into(); @@ -92,5 +86,5 @@ pub trait HasPlayClip: HasClock { }; FieldV(color, "Next:", format!("{} {}", time, name)) } - } + diff --git a/deps/rust-jack b/deps/rust-jack index a13c1c4d..caace909 160000 --- a/deps/rust-jack +++ b/deps/rust-jack @@ -1 +1 @@ -Subproject commit a13c1c4d20343e574787a703eaeea7aeda63b084 +Subproject commit caace9096c9df9c288b14a7c0ea1241d8da2baa1