api: compact

This commit is contained in:
🪞👃🪞 2025-04-26 21:20:06 +03:00
parent e4808f8fc1
commit 3ef3d5eb6f
22 changed files with 441 additions and 558 deletions

View file

@ -35,14 +35,14 @@
//return None
//},
//kpat!(Char('a')) | kpat!(Shift-Char('A')) => Cmd::Clip(PoolClipCommand::Add(count, MidiClip::new(
//"Clip", true, 4 * PPQ, None, Some(ItemPalette::random())
//"Clip", true, 4 * PPQ, None, Some(ItemTheme::random())
//))),
//kpat!(Char('i')) => Cmd::Clip(PoolClipCommand::Add(index + 1, MidiClip::new(
//"Clip", true, 4 * PPQ, None, Some(ItemPalette::random())
//"Clip", true, 4 * PPQ, None, Some(ItemTheme::random())
//))),
//kpat!(Char('d')) | kpat!(Shift-Char('D')) => {
//let mut clip = state.clips()[index].read().unwrap().duplicate();
//clip.color = ItemPalette::random_near(clip.color, 0.25);
//clip.color = ItemTheme::random_near(clip.color, 0.25);
//Cmd::Clip(PoolClipCommand::Add(index + 1, clip))
//},
//_ => return None

View file

@ -1,5 +1,3 @@
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::*;

View file

@ -115,7 +115,7 @@ impl MidiEditor {
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)
} else { (ItemPalette::G[64], String::new().into(), 0, false) };
} else { (ItemTheme::G[64], String::new().into(), 0, false) };
Bsp::e(
FieldH(color, "Edit", format!("{name} ({length})")),
FieldH(color, "Loop", looped.to_string())
@ -125,7 +125,7 @@ impl MidiEditor {
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)
} else { (ItemPalette::G[64], 0) };
} else { (ItemTheme::G[64], 0) };
let time_pos = self.time_pos();
let time_zoom = self.time_zoom().get();
let time_lock = if self.time_lock().get() { "[lock]" } else { " " };

View file

@ -39,7 +39,7 @@ pub trait HasPlayClip: HasClock {
}
fn play_status (&self) -> impl Content<TuiOut> {
let (name, color): (Arc<str>, ItemPalette) = if let Some((_, Some(clip))) = self.play_clip() {
let (name, color): (Arc<str>, ItemTheme) = if let Some((_, Some(clip))) = self.play_clip() {
let MidiClip { ref name, color, .. } = *clip.read().unwrap();
(name.clone(), color)
} else {
@ -54,7 +54,7 @@ pub trait HasPlayClip: HasClock {
fn next_status (&self) -> impl Content<TuiOut> {
let mut time: Arc<str> = String::from("--.-.--").into();
let mut name: Arc<str> = String::from("").into();
let mut color = ItemPalette::G[64];
let mut color = ItemTheme::G[64];
let clock = self.clock();
if let Some((t, Some(clip))) = self.next_clip() {
let clip = clip.read().unwrap();

View file

@ -34,7 +34,7 @@ pub struct MidiClip {
/// All notes are displayed with minimum length
pub percussive: bool,
/// Identifying color of clip
pub color: ItemPalette,
pub color: ItemTheme,
}
/// MIDI message structural
@ -46,7 +46,7 @@ impl MidiClip {
looped: bool,
length: usize,
notes: Option<MidiData>,
color: Option<ItemPalette>,
color: Option<ItemTheme>,
) -> Self {
Self {
uuid: uuid::Uuid::new_v4(),
@ -58,7 +58,7 @@ impl MidiClip {
loop_start: 0,
loop_length: length,
percussive: true,
color: color.unwrap_or_else(ItemPalette::random)
color: color.unwrap_or_else(ItemTheme::random)
}
}
pub fn count_midi_messages (&self) -> usize {

View file

@ -1,8 +1,8 @@
use crate::*;
mod mode_browse; pub use self::mode_browse::*;
mod mode_length; pub use self::mode_length::*;
mod mode_rename; pub use self::mode_rename::*;
mod mode_browse;
/// Modes for clip pool
#[derive(Debug, Clone)]

View file

@ -13,7 +13,7 @@ pub struct PianoHorizontal {
/// The note cursor
pub point: MidiPointModel,
/// The highlight color palette
pub color: ItemPalette,
pub color: ItemTheme,
/// Width of the keyboard
pub keys_width: u16,
}
@ -31,7 +31,7 @@ impl PianoHorizontal {
buffer: RwLock::new(Default::default()).into(),
point: MidiPointModel::default(),
clip: clip.cloned(),
color: clip.as_ref().map(|p|p.read().unwrap().color).unwrap_or(ItemPalette::G[64]),
color: clip.as_ref().map(|p|p.read().unwrap().color).unwrap_or(ItemTheme::G[64]),
};
piano.redraw();
piano
@ -281,7 +281,7 @@ impl MidiViewer for PianoHorizontal {
fn set_clip (&mut self, clip: Option<&Arc<RwLock<MidiClip>>>) {
*self.clip_mut() = clip.cloned();
self.color = clip.map(|p|p.read().unwrap().color)
.unwrap_or(ItemPalette::G[64]);
.unwrap_or(ItemTheme::G[64]);
self.redraw();
}
}

View file

@ -168,7 +168,7 @@ impl<T: HasClips> Command<T> for PoolClipCommand {
Some(Self::SetLength(index, old_len))
},
SetColor(index, color) => {
let mut color = ItemPalette::from(color);
let mut color = ItemTheme::from(color);
std::mem::swap(&mut color, &mut model.clips()[index].write().unwrap().color);
Some(Self::SetColor(index, color.base))
},

View file

@ -85,12 +85,12 @@ impl MidiPool {
Ok(())
}
pub fn new_clip (&self) -> MidiClip {
MidiClip::new("Clip", true, 4 * PPQ, None, Some(ItemPalette::random()))
MidiClip::new("Clip", true, 4 * PPQ, None, Some(ItemTheme::random()))
}
pub fn cloned_clip (&self) -> MidiClip {
let index = self.clip_index();
let mut clip = self.clips()[index].read().unwrap().duplicate();
clip.color = ItemPalette::random_near(clip.color, 0.25);
clip.color = ItemTheme::random_near(clip.color, 0.25);
clip
}
pub fn add_new_clip (&self) -> (usize, Arc<RwLock<MidiClip>>) {