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

@ -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<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 () {
let clip = MidiClip::stop_all();
println!("{clip:?}");

View file

@ -5,7 +5,7 @@ use crate::*;
pub struct MidiEditor {
pub mode: PianoHorizontal,
pub size: Measure<TuiOut>,
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<TuiOut> + '_ {
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<TuiOut> + '_ {
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<MidiEditor> for MidiEditCommand {
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> {
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<RwLock<MidiClip>>>) {
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))
}
}