test: fix coverage run

This commit is contained in:
🪞👃🪞 2025-04-26 13:31:09 +03:00
parent 24bc33d3d0
commit 2c59b1acfd
6 changed files with 58 additions and 58 deletions

View file

@ -287,14 +287,14 @@ pub trait HasScenes: HasSelection + HasEditor + Send + Sync {
impl Scene { impl Scene {
/// Returns the pulse length of the longest clip in the 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|{ self.clips.iter().fold(0, |a, p|{
a.max(p.as_ref().map(|q|q.read().unwrap().length).unwrap_or(0)) a.max(p.as_ref().map(|q|q.read().unwrap().length).unwrap_or(0))
}) })
} }
/// Returns true if all clips in the scene are /// Returns true if all clips in the scene are
/// currently playing on the given collection of tracks. /// 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() self.clips.iter().any(|clip|clip.is_some()) && self.clips.iter().enumerate()
.all(|(track_index, clip)|match clip { .all(|(track_index, clip)|match clip {
Some(c) => tracks Some(c) => tracks

View file

@ -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) 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<TuiOut> { pub(crate) fn button_play_pause (playing: bool) -> impl Content<TuiOut> {
let compact = true;//self.is_editing(); let compact = true;//self.is_editing();
Tui::bg( Tui::bg(
if playing{Rgb(0,128,0)}else{Rgb(128,64,0)}, if playing{Rgb(0,128,0)}else{Rgb(128,64,0)},
@ -577,7 +577,7 @@ fn button_play_pause (playing: bool) -> impl Content<TuiOut> {
) )
} }
fn view_meter <'a> (label: &'a str, value: f32) -> impl Content<TuiOut> + 'a { pub (crate) fn view_meter <'a> (label: &'a str, value: f32) -> impl Content<TuiOut> + 'a {
col!( col!(
FieldH(ItemPalette::G[128], label, format!("{:>+9.3}", value)), FieldH(ItemPalette::G[128], label, format!("{:>+9.3}", value)),
Fixed::xy(if value >= 0.0 { 13 } Fixed::xy(if value >= 0.0 { 13 }
@ -598,7 +598,7 @@ fn view_meter <'a> (label: &'a str, value: f32) -> impl Content<TuiOut> + 'a {
else { Green }, ()))) else { Green }, ())))
} }
fn view_meters (values: &[f32;2]) -> impl Content<TuiOut> + use<'_> { pub(crate) fn view_meters (values: &[f32;2]) -> impl Content<TuiOut> + use<'_> {
Bsp::s( Bsp::s(
format!("L/{:>+9.3}", values[0]), format!("L/{:>+9.3}", values[0]),
format!("R/{:>+9.3}", values[1]), format!("R/{:>+9.3}", values[1]),
@ -784,7 +784,7 @@ impl ViewCache {
pub const TIME_EMPTY: &'static str = "-.---s"; pub const TIME_EMPTY: &'static str = "-.---s";
pub const BPM_EMPTY: &'static str = "---.---"; pub const BPM_EMPTY: &'static str = "---.---";
pub(crate) fn track_counter (cache: &Arc<RwLock<Self>>, track: usize, tracks: usize) pub fn track_counter (cache: &Arc<RwLock<Self>>, track: usize, tracks: usize)
-> Arc<RwLock<String>> -> Arc<RwLock<String>>
{ {
let data = (track, tracks); let data = (track, tracks);
@ -792,7 +792,7 @@ impl ViewCache {
cache.read().unwrap().trks.view.clone() cache.read().unwrap().trks.view.clone()
} }
pub(crate) fn scene_add (cache: &Arc<RwLock<Self>>, scene: usize, scenes: usize, is_editing: bool) pub fn scene_add (cache: &Arc<RwLock<Self>>, scene: usize, scenes: usize, is_editing: bool)
-> impl Content<TuiOut> -> impl Content<TuiOut>
{ {
let data = (scene, scenes); let data = (scene, scenes);
@ -800,7 +800,7 @@ impl ViewCache {
button_3("S", "add scene", cache.read().unwrap().scns.view.clone(), is_editing) button_3("S", "add scene", cache.read().unwrap().scns.view.clone(), is_editing)
} }
pub(crate) fn update_clock (cache: &Arc<RwLock<Self>>, clock: &Clock, compact: bool) { pub fn update_clock (cache: &Arc<RwLock<Self>>, clock: &Clock, compact: bool) {
let rate = clock.timebase.sr.get(); let rate = clock.timebase.sr.get();
let chunk = clock.chunk.load(Relaxed) as f64; let chunk = clock.chunk.load(Relaxed) as f64;
let lat = chunk / rate * 1000.; let lat = chunk / rate * 1000.;

View file

@ -1,9 +1,41 @@
use crate::*;
mod clip_editor; pub use self::clip_editor::*; mod clip_editor; pub use self::clip_editor::*;
mod clip_launch; pub use self::clip_launch::*; mod clip_launch; pub use self::clip_launch::*;
mod clip_model; pub use self::clip_model::*; mod clip_model; pub use self::clip_model::*;
mod clip_play; pub use self::clip_play::*; mod clip_play; pub use self::clip_play::*;
mod clip_view; pub use self::clip_view::*; mod clip_view; pub use self::clip_view::*;
pub trait HasEditor {
fn editor (&self) -> &Option<MidiEditor>;
fn editor_mut (&mut self) -> &Option<MidiEditor>;
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<MidiEditor> { &$e0 }
fn editor_mut (&mut $self) -> &Option<MidiEditor> { &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 () { #[cfg(test)] #[test] pub fn test_midi_clip () {
let clip = MidiClip::stop_all(); let clip = MidiClip::stop_all();
println!("{clip:?}"); println!("{clip:?}");

View file

@ -5,7 +5,7 @@ use crate::*;
pub struct MidiEditor { pub struct MidiEditor {
pub mode: PianoHorizontal, pub mode: PianoHorizontal,
pub size: Measure<TuiOut>, pub size: Measure<TuiOut>,
keys: SourceIter<'static> pub keys: SourceIter<'static>
} }
impl std::fmt::Debug for MidiEditor { impl std::fmt::Debug for MidiEditor {
@ -80,11 +80,9 @@ provide!(usize: |self: MidiEditor| {
}); });
impl 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 /// Put note at current position
fn put_note (&mut self, advance: bool) { pub fn put_note (&mut self, advance: bool) {
let mut redraw = false; let mut redraw = false;
if let Some(clip) = self.clip() { if let Some(clip) = self.clip() {
let mut clip = clip.write().unwrap(); let mut clip = clip.write().unwrap();
@ -113,6 +111,7 @@ impl MidiEditor {
self.mode.redraw(); self.mode.redraw();
} }
} }
pub fn clip_status (&self) -> impl Content<TuiOut> + '_ { pub fn clip_status (&self) -> impl Content<TuiOut> + '_ {
let (color, name, length, looped) = if let Some(clip) = self.clip().as_ref().map(|p|p.read().unwrap()) { 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) (clip.color, clip.name.clone(), clip.length, clip.looped)
@ -122,6 +121,7 @@ impl MidiEditor {
FieldH(color, "Loop", looped.to_string()) FieldH(color, "Loop", looped.to_string())
) )
} }
pub fn edit_status (&self) -> impl Content<TuiOut> + '_ { pub fn edit_status (&self) -> impl Content<TuiOut> + '_ {
let (color, length) = if let Some(clip) = self.clip().as_ref().map(|p|p.read().unwrap()) { let (color, length) = if let Some(clip) = self.clip().as_ref().map(|p|p.read().unwrap()) {
(clip.color, clip.length) (clip.color, clip.length)
@ -137,6 +137,10 @@ impl MidiEditor {
FieldH(color, "Note", format!("{note_name} {note_pos} {note_len}")), 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 { impl TimeRange for MidiEditor {
@ -235,33 +239,3 @@ impl Command<MidiEditor> for MidiEditCommand {
Ok(None) Ok(None)
} }
} }
pub trait HasEditor {
fn editor (&self) -> &Option<MidiEditor>;
fn editor_mut (&mut self) -> &Option<MidiEditor>;
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<MidiEditor> { &$e0 }
fn editor_mut (&mut $self) -> &Option<MidiEditor> { &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 }
}
};
}

View file

@ -17,10 +17,9 @@ pub trait HasPlayClip: HasClock {
fn pulses_since_start (&self) -> Option<f64> { fn pulses_since_start (&self) -> Option<f64> {
if let Some((started, Some(_))) = self.play_clip().as_ref() { if let Some((started, Some(_))) = self.play_clip().as_ref() {
let elapsed = self.clock().playhead.pulse.get() - started.pulse.get(); let elapsed = self.clock().playhead.pulse.get() - started.pulse.get();
Some(elapsed) return Some(elapsed)
} else {
None
} }
None
} }
fn pulses_since_start_looped (&self) -> Option<(f64, f64)> { 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 length = clip.read().unwrap().length.max(1); // prevent div0 on empty clip
let times = (elapsed as usize / length) as f64; let times = (elapsed as usize / length) as f64;
let elapsed = (elapsed as usize % length) as f64; let elapsed = (elapsed as usize % length) as f64;
Some((times, elapsed)) return Some((times, elapsed))
} else {
None
} }
None
} }
fn enqueue_next (&mut self, clip: Option<&Arc<RwLock<MidiClip>>>) { fn enqueue_next (&mut self, clip: Option<&Arc<RwLock<MidiClip>>>) {
let start = self.clock().next_launch_pulse() as f64; *self.next_clip_mut() = Some((self.clock().next_launch_instant(), clip.cloned()));
let instant = Moment::from_pulse(self.clock().timebase(), start);
*self.next_clip_mut() = Some((instant, clip.cloned()));
*self.reset_mut() = true; *self.reset_mut() = true;
} }
@ -82,9 +78,7 @@ pub trait HasPlayClip: HasClock {
let target = t.pulse.get() + clip.length as f64; let target = t.pulse.get() + clip.length as f64;
let current = clock.playhead.pulse.get(); let current = clock.playhead.pulse.get();
if target > current { if target > current {
time = format!("-{:>}", clock.timebase.format_beats_0( time = format!("-{:>}", clock.timebase.format_beats_0(target - current)).into()
target - current
)).into()
} }
} else { } else {
name = "Stop".to_string().into(); name = "Stop".to_string().into();
@ -92,5 +86,5 @@ pub trait HasPlayClip: HasClock {
}; };
FieldV(color, "Next:", format!("{} {}", time, name)) FieldV(color, "Next:", format!("{} {}", time, name))
} }
} }

2
deps/rust-jack vendored

@ -1 +1 @@
Subproject commit a13c1c4d20343e574787a703eaeea7aeda63b084 Subproject commit caace9096c9df9c288b14a7c0ea1241d8da2baa1