compiled layouts

This commit is contained in:
i do not exist 2026-08-29 18:46:46 +03:00
parent 6771b24f79
commit ab6959a84f
21 changed files with 534 additions and 263 deletions

View file

@ -53,7 +53,7 @@ impl PianoHorizontal {
buffer: RwLock::new(Default::default()).into(),
point: MidiCursor::default(),
clip: clip.cloned(),
color: clip.as_ref().map(|p|p.read().unwrap().color).unwrap_or(ItemTheme::G[64]),
color: clip.as_ref().map(|p|p.try_read().unwrap().color).unwrap_or(ItemTheme::G[64]),
};
piano.redraw();
piano
@ -140,7 +140,7 @@ impl PianoHorizontal {
draw(move|to: &mut Tui|{
let xywh = to.area().into();
let XYWH(x0, y0, w, _h) = xywh;
let source = buffer.read().unwrap();
let source = buffer.try_read().unwrap();
//if h as usize != note_axis {
//panic!("area height mismatch: {h} <> {note_axis}");
//}
@ -234,7 +234,7 @@ impl PianoHorizontal {
let xywh = to.area().into();
let XYWH(x, y, w, _h) = xywh;
let style = Some(Style::default().dim());
let length = self.clip.as_ref().map(|p|p.read().unwrap().length).unwrap_or(1);
let length = self.clip.as_ref().map(|p|p.try_read().unwrap().length).unwrap_or(1);
for (area_x, screen_x) in (0..w).map(|d|(d, d+x)) {
let t = area_x as usize * self.time_zoom().load(Relaxed);
if t < length {
@ -276,8 +276,8 @@ impl MidiViewer for PianoHorizontal {
(clip.length / self.range.time_zoom().load(Relaxed), 128)
}
fn redraw (&self) {
*self.buffer.write().unwrap() = if let Some(clip) = self.clip.as_ref() {
let clip = clip.read().unwrap();
*self.buffer.try_write().unwrap() = if let Some(clip) = self.clip.as_ref() {
let clip = clip.try_read().unwrap();
let buf_size = self.buffer_size(&clip);
let mut buffer = BigBuffer::from(buf_size);
let time_zoom = self.get_time_zoom();
@ -291,14 +291,14 @@ 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(ItemTheme::G[64]);
self.color = clip.map(|p|p.try_read().unwrap().color).unwrap_or(ItemTheme::G[64]);
self.redraw();
}
}
impl std::fmt::Debug for PianoHorizontal {
fn fmt (&self, f: &mut Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
let buffer = self.buffer.read().unwrap();
let buffer = self.buffer.try_read().unwrap();
f.debug_struct("PianoHorizontal")
.field("time_zoom", &self.range.time_zoom)
.field("buffer", &format!("{}x{}", buffer.width, buffer.height))