wip: zoom lock

This commit is contained in:
🪞👃🪞 2025-01-02 17:20:37 +01:00
parent 94491a323a
commit 44c28183de
11 changed files with 107 additions and 89 deletions

View file

@ -5,37 +5,19 @@ pub(crate) fn note_y_iter (note_lo: usize, note_hi: usize, y0: u16) -> impl Iter
(note_lo..=note_hi).rev().enumerate().map(move|(y, n)|(y, y0 + y as u16, n))
}
render!(Tui: (self: PianoHorizontal) => {
let (color, name, length, looped) = if let Some(phrase) = self.phrase().as_ref().map(|p|p.read().unwrap()) {
(phrase.color, phrase.name.clone(), phrase.length, phrase.looped)
} else {
(ItemPalette::from(TuiTheme::g(64)), String::new(), 0, false)
};
let field = move|x, y|row!(
Tui::fg_bg(color.lighter.rgb, color.darker.rgb, Tui::bold(true, x)),
Tui::fg_bg(color.lightest.rgb, color.dark.rgb, format!(" {y} ")),
);
Bsp::s(
Fixed::y(1, row!(
field(" Edit ", name.to_string()), " ",
field(" Length ", length.to_string()), " ",
field(" Loop ", looped.to_string())
)),
Bsp::s(
Fixed::y(1, Bsp::e(
Fixed::x(self.keys_width, ""),
Fill::x(PianoHorizontalTimeline(self)),
)),
Fill::xy(Bsp::e(
Fixed::x(self.keys_width, PianoHorizontalKeys(self)),
Fill::xy(self.size.of(lay!(
Fill::xy(PianoHorizontalNotes(self)),
Fill::xy(PianoHorizontalCursor(self)),
))),
)),
)
)
});
render!(Tui: (self: PianoHorizontal) => Bsp::s(
Fixed::y(1, Bsp::e(
Fixed::x(self.keys_width, ""),
Fill::x(PianoHorizontalTimeline(self)),
)),
Fill::xy(Bsp::e(
Fixed::x(self.keys_width, PianoHorizontalKeys(self)),
Fill::xy(self.size.of(lay!(
Fill::xy(PianoHorizontalNotes(self)),
Fill::xy(PianoHorizontalCursor(self)),
))),
)),
));
impl PianoHorizontal {
/// Draw the piano roll foreground using full blocks on note on and half blocks on legato: █▄ █▄ █▄
@ -131,7 +113,7 @@ impl MidiViewMode for PianoHorizontal {
fn buffer_size (&self, phrase: &MidiClip) -> (usize, usize) {
(phrase.length / self.range.time_zoom().get(), 128)
}
fn redraw (&mut self) {
fn redraw (&self) {
let buffer = if let Some(phrase) = self.phrase.as_ref() {
let phrase = phrase.read().unwrap();
let buf_size = self.buffer_size(&phrase);
@ -145,7 +127,7 @@ impl MidiViewMode for PianoHorizontal {
} else {
Default::default()
};
self.buffer = buffer
*self.buffer.write().unwrap() = buffer
}
fn set_phrase (&mut self, phrase: Option<&Arc<RwLock<MidiClip>>>) {
*self.phrase_mut() = phrase.cloned();
@ -157,9 +139,10 @@ impl MidiViewMode for PianoHorizontal {
impl std::fmt::Debug for PianoHorizontal {
fn fmt (&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
let buffer = self.buffer.read().unwrap();
f.debug_struct("PianoHorizontal")
.field("time_zoom", &self.range.time_zoom)
.field("buffer", &format!("{}x{}", self.buffer.width, self.buffer.height))
.field("buffer", &format!("{}x{}", buffer.width, buffer.height))
.finish()
}
}