editor: reverse highlight

This commit is contained in:
🪞👃🪞 2025-05-14 21:02:00 +03:00
parent 4a9e9132f3
commit b7152ef807
4 changed files with 38 additions and 23 deletions

View file

@ -95,34 +95,36 @@ use crate::*;
#[tengri_proc::command(MidiEditor)] impl MidiEditCommand {
fn append_note (editor: &mut MidiEditor, advance: bool) -> Perhaps<Self> {
editor.put_note(advance);
editor.redraw();
Ok(None)
}
fn delete_note (_editor: &mut MidiEditor) -> Perhaps<Self> {
fn delete_note (editor: &mut MidiEditor) -> Perhaps<Self> {
editor.redraw();
todo!()
}
fn set_note_pos (editor: &mut MidiEditor, pos: usize) -> Perhaps<Self> {
editor.set_note_pos(pos.min(127));
editor.redraw();
Ok(None)
}
fn set_note_len (editor: &mut MidiEditor, value: usize) -> Perhaps<Self> {
//let note_len = editor.get_note_len();
//let time_zoom = editor.get_time_zoom();
editor.set_note_len(value);
//if note_len / time_zoom != x / time_zoom {
editor.redraw();
//}
editor.redraw();
Ok(None)
}
fn set_note_scroll (editor: &mut MidiEditor, value: usize) -> Perhaps<Self> {
editor.set_note_lo(value.min(127));
editor.redraw();
Ok(None)
}
fn set_time_pos (editor: &mut MidiEditor, value: usize) -> Perhaps<Self> {
editor.set_time_pos(value);
editor.redraw();
Ok(None)
}
fn set_time_scroll (editor: &mut MidiEditor, value: usize) -> Perhaps<Self> {
editor.set_time_start(value);
editor.redraw();
Ok(None)
}
fn set_time_zoom (editor: &mut MidiEditor, value: usize) -> Perhaps<Self> {
@ -132,10 +134,12 @@ use crate::*;
}
fn set_time_lock (editor: &mut MidiEditor, value: bool) -> Perhaps<Self> {
editor.set_time_lock(value);
editor.redraw();
Ok(None)
}
fn show (editor: &mut MidiEditor, clip: Option<Arc<RwLock<MidiClip>>>) -> Perhaps<Self> {
editor.set_clip(clip.as_ref());
editor.redraw();
Ok(None)
}
// TODO: 1-9 seek markers that by default start every 8th of the clip

View file

@ -64,11 +64,22 @@ impl PianoHorizontal {
/// Draw the piano roll background.
///
/// This mode uses full blocks on note on and half blocks on legato: █▄ █▄ █▄
fn draw_bg (buf: &mut BigBuffer, clip: &MidiClip, zoom: usize, note_len: usize) {
fn draw_bg (
buf: &mut BigBuffer,
clip: &MidiClip,
zoom: usize,
note_len: usize,
note_point: usize,
time_point: usize,
) {
for (y, note) in (0..=127).rev().enumerate() {
for (x, time) in (0..buf.width).map(|x|(x, x*zoom)) {
let cell = buf.get_mut(x, y).unwrap();
cell.set_bg(clip.color.darkest.rgb);
if note == (127-note_point) || time == time_point {
cell.set_bg(Rgb(0,0,0));
} else {
cell.set_bg(clip.color.darkest.rgb);
}
if time % 384 == 0 {
cell.set_fg(clip.color.darker.rgb);
cell.set_char('│');
@ -267,10 +278,10 @@ impl MidiViewer for PianoHorizontal {
let clip = clip.read().unwrap();
let buf_size = self.buffer_size(&clip);
let mut buffer = BigBuffer::from(buf_size);
let note_len = self.get_note_len();
let time_zoom = self.get_time_zoom();
self.time_len().set(clip.length);
PianoHorizontal::draw_bg(&mut buffer, &clip, time_zoom, note_len);
PianoHorizontal::draw_bg(&mut buffer, &clip, time_zoom,
self.get_note_len(), self.get_note_pos(), self.get_time_pos());
PianoHorizontal::draw_fg(&mut buffer, &clip, time_zoom);
buffer
} else {

View file

@ -53,7 +53,7 @@ pub fn to_rms (samples: &[f32]) -> f32 {
(sum / samples.len() as f32).sqrt()
}
pub (crate) fn view_meter <'a> (label: &'a str, value: f32) -> impl Content<TuiOut> + 'a {
pub fn view_meter <'a> (label: &'a str, value: f32) -> impl Content<TuiOut> + 'a {
col!(
FieldH(ItemTheme::G[128], label, format!("{:>+9.3}", value)),
Fixed::xy(if value >= 0.0 { 13 }
@ -74,7 +74,7 @@ pub (crate) fn view_meter <'a> (label: &'a str, value: f32) -> impl Content<TuiO
else { Green }, ())))
}
pub(crate) fn view_meters (values: &[f32;2]) -> impl Content<TuiOut> + use<'_> {
pub fn view_meters (values: &[f32;2]) -> impl Content<TuiOut> + use<'_> {
let left = format!("L/{:>+9.3}", values[0]);
let right = format!("R/{:>+9.3}", values[1]);
Bsp::s(left, right)

View file

@ -223,12 +223,12 @@ fn draw_info (sample: Option<&Arc<RwLock<Sample>>>) -> impl Content<TuiOut> + us
let sample = sample.unwrap().read().unwrap();
let theme = sample.color;
row!(
FieldH(theme, "Name", format!("{:<10}", sample.name.clone())),
FieldH(theme, "Length", format!("{:<8}", sample.channels[0].len())),
FieldH(theme, "Start", format!("{:<8}", sample.start)),
FieldH(theme, "End", format!("{:<8}", sample.end)),
FieldH(theme, "Transpose", " 0 "),
FieldH(theme, "Gain", format!("{}", sample.gain)),
FieldH(theme, "Name", format!("{:<10}", sample.name.clone())),
FieldH(theme, "Length", format!("{:<8}", sample.channels[0].len())),
FieldH(theme, "Start", format!("{:<8}", sample.start)),
FieldH(theme, "End", format!("{:<8}", sample.end)),
FieldH(theme, "Trans", "0"),
FieldH(theme, "Gain", format!("{}", sample.gain)),
)
}))
}
@ -239,11 +239,11 @@ fn draw_info_v (sample: Option<&Arc<RwLock<Sample>>>) -> impl Content<TuiOut> +
let theme = sample.color;
Fixed::x(20, col!(
Fill::x(Align::w(FieldH(theme, "Name ", format!("{:<10}", sample.name.clone())))),
Fill::x(Align::w(FieldH(theme, "Length", format!("{:<8}", sample.channels[0].len())))),
Fill::x(Align::w(FieldH(theme, "Start ", format!("{:<8}", sample.start)))),
Fill::x(Align::w(FieldH(theme, "End ", format!("{:<8}", sample.end)))),
Fill::x(Align::w(FieldH(theme, "Trans ", "0 "))),
Fill::x(Align::w(FieldH(theme, "Gain ", format!("{}", sample.gain)))),
Fill::x(Align::w(FieldH(theme, "Length", format!("{:<8}", sample.channels[0].len())))),
Fill::x(Align::w(FieldH(theme, "Start ", format!("{:<8}", sample.start)))),
Fill::x(Align::w(FieldH(theme, "End ", format!("{:<8}", sample.end)))),
Fill::x(Align::w(FieldH(theme, "Trans ", "0"))),
Fill::x(Align::w(FieldH(theme, "Gain ", format!("{}", sample.gain)))),
))
}), Thunk::new(move||Tui::fg(Red, col!(
"× No sample.",