fix timer of horizontal sequencer

This commit is contained in:
🪞👃🪞 2024-07-03 20:03:00 +03:00
parent 2601592d17
commit 1259176576
6 changed files with 293 additions and 254 deletions

View file

@ -11,70 +11,92 @@ pub enum ChainViewMode {
pub struct ChainView<'a> {
pub focused: bool,
pub chain: Option<&'a Track>,
pub track: Option<&'a Track>,
}
impl<'a> Render for ChainView<'a> {
fn render (&self, buf: &mut Buffer, area: Rect) -> Usually<Rect> {
let style = Some(if self.focused {
Style::default().green()
} else {
Style::default().green().dim()
} else {
Style::default().dim()
});
let (area, _plugins) = if let Some(ref chain) = self.chain {
draw_as_row(&*chain, buf, area, style)?
let Rect { x, y, width, height } = area;
if self.track.is_none() {
let label = "No track selected";
label.blit(
buf,
x + (width - label.len() as u16) / 2,
y + height / 2,
Some(Style::default().dim().bold())
);
}
lozenge_left(buf, x, y, height, style);
let (area, _plugins) = if let Some(ref chain) = self.track {
self.draw_as_row(buf, area, style)?
} else {
(area, vec![])
};
let Rect { x, y, width, height} = area;
lozenge_left(buf, x, y, height, style);
lozenge_right(buf, x + width - 1, y, height, style);
Ok(area)
}
}
pub fn draw_as_row (
state: &Track, buf: &mut Buffer, area: Rect, style: Option<Style>
) -> Usually<(Rect, Vec<Rect>)> {
let Rect { mut x, y, width, height } = area;
let mut h = 3u16;
let mut frames = vec![];
for (i, device) in state.devices.iter().enumerate() {
let x2 = 0u16;
let _y2 = 1u16;
//for port in device.midi_ins()?.iter() {
//port.blit(buf, x, y + y2, Some(Style::default()));
//x2 = x2.max(port.len() as u16);
//y2 = y2 + 1;
//}
//for port in device.audio_ins()?.iter() {
//port.blit(buf, x, y + y2, Some(Style::default()));
//x2 = x2.max(port.len() as u16);
//y2 = y2 + 1;
//}
let width = width.saturating_sub(x).saturating_sub(x2);
let frame = device.render(buf, Rect { x: x + x2, y, width, height })?;
lozenge_left(buf, x + x2, y, frame.height, style);
lozenge_right(buf, x + x2 + frame.width - 1, y, frame.height, style);
//let mut y2 = 1u16;
//for port in device.midi_outs()?.iter() {
//port.blit(buf, x + x2 + frame.width, y + y2, Some(Style::default()));
//x2 = x2.max(port.len() as u16);
//y2 = y2 + 1;
//}
//for port in device.audio_outs()?.iter() {
//port.blit(buf, x + x2 + frame.width, y + y2, Some(Style::default()));
//x2 = x2.max(port.len() as u16);
//y2 = y2 + 1;
//}
frames.push(frame);
h = h.max(frame.height);
x = x + frame.width;
impl<'a> ChainView<'a> {
pub fn draw_as_row (
&self, buf: &mut Buffer, area: Rect, style: Option<Style>
) -> Usually<(Rect, Vec<Rect>)> {
let Rect { mut x, y, width, height } = area;
let mut h = 3u16;
let mut frames = vec![];
let track = self.track.as_ref().unwrap();
for (i, device) in track.devices.iter().enumerate() {
let x2 = 0u16;
let _y2 = 1u16;
//for port in device.midi_ins()?.iter() {
//port.blit(buf, x, y + y2, Some(Style::default()));
//x2 = x2.max(port.len() as u16);
//y2 = y2 + 1;
//}
//for port in device.audio_ins()?.iter() {
//port.blit(buf, x, y + y2, Some(Style::default()));
//x2 = x2.max(port.len() as u16);
//y2 = y2 + 1;
//}
let width = width.saturating_sub(x).saturating_sub(x2);
let frame = device.render(buf, Rect { x: x + x2, y, width, height })?;
let style = if i == track.device {
Some(if self.focused {
Style::default().green().bold().not_dim()
} else {
Style::default().green().dim()
})
} else {
style
};
lozenge_left(buf, x + x2, y, frame.height, style);
lozenge_right(buf, x + x2 + frame.width - 1, y, frame.height, style);
//let mut y2 = 1u16;
//for port in device.midi_outs()?.iter() {
//port.blit(buf, x + x2 + frame.width, y + y2, Some(Style::default()));
//x2 = x2.max(port.len() as u16);
//y2 = y2 + 1;
//}
//for port in device.audio_outs()?.iter() {
//port.blit(buf, x + x2 + frame.width, y + y2, Some(Style::default()));
//x2 = x2.max(port.len() as u16);
//y2 = y2 + 1;
//}
frames.push(frame);
h = h.max(frame.height);
x = x + frame.width;
}
let label = "[Add device…]";
label.blit(buf, x + 1, area.y + 1, Some(Style::default().dim()));
x = x + 1 + label.len() as u16 + 1;
Ok((Rect { x: area.x, y: area.y, width: x, height: h }, frames))
}
let label = "[Add device…]";
label.blit(buf, x + 1, area.y + 1, Some(Style::default().dim()));
x = x + 1 + label.len() as u16 + 1;
Ok((Rect { x: area.x, y: area.y, width: x, height: h }, frames))
}
pub fn draw_as_column (