mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 19:56:42 +01:00
240 lines
8 KiB
Rust
240 lines
8 KiB
Rust
use crate::*;
|
|
|
|
impl Sequencer<Tui> {
|
|
|
|
const H_KEYS_OFFSET: usize = 5;
|
|
|
|
pub(crate) fn horizontal_draw <'a> (&self, to: &mut Tui) -> Usually<()> {
|
|
let area = to.area();
|
|
Split::down()
|
|
.add_ref(&SequenceName(&self))
|
|
.add_ref(&SequenceRange)
|
|
.add_ref(&SequenceLoopRange)
|
|
.add_ref(&SequenceNoteRange)
|
|
.render(to.with_area(area.x(), area.y(), 10, area.h()))?;
|
|
let area = [area.x() + 10, area.y(), area.w().saturating_sub(10), area.h().min(66)];
|
|
Lozenge(Style::default().fg(Nord::BG2)).draw(to.with_rect(area))?;
|
|
let area = [area.x() + 1, area.y(), area.w().saturating_sub(1), area.h()];
|
|
Layers([
|
|
&SequenceKeys(&self),
|
|
&self.phrase.as_ref().map(|phrase|SequenceTimer(&self, phrase.clone())),
|
|
&SequenceNotes(&self),
|
|
&SequenceCursor(&self),
|
|
&SequenceZoom(&self),
|
|
]).render(to.with_rect(area))?;
|
|
Ok(())
|
|
}
|
|
|
|
}
|
|
|
|
const STYLE_LABEL: Option<Style> = Some(Style {
|
|
fg: Some(Color::Reset),
|
|
bg: None,
|
|
underline_color: None,
|
|
add_modifier: Modifier::empty(),
|
|
sub_modifier: Modifier::BOLD,
|
|
});
|
|
|
|
const STYLE_VALUE: Option<Style> = Some(Style {
|
|
fg: Some(Color::White),
|
|
bg: None,
|
|
underline_color: None,
|
|
add_modifier: Modifier::BOLD,
|
|
sub_modifier: Modifier::DIM,
|
|
});
|
|
|
|
struct SequenceName<'a>(&'a Sequencer<Tui>);
|
|
|
|
impl<'a> Widget for SequenceName<'a> {
|
|
type Engine = Tui;
|
|
fn layout (&self, area: [u16;4]) -> Perhaps<[u16;4]> {
|
|
todo!()
|
|
}
|
|
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
|
|
let [x, y, ..] = to.area();
|
|
let frame = [x, y, 10, 4];
|
|
Lozenge(Style::default().fg(Nord::BG2)).draw(to.with_rect(frame))?;
|
|
to.blit(&"Name:", x + 1, y + 1, STYLE_LABEL)?;
|
|
to.blit(&*self.0.name.read().unwrap(), x + 1, y + 2, STYLE_VALUE)?;
|
|
Ok(Some(frame))
|
|
}
|
|
}
|
|
|
|
struct SequenceRange;
|
|
|
|
impl Widget for SequenceRange {
|
|
type Engine = Tui;
|
|
fn layout (&self, area: [u16;4]) -> Perhaps<[u16;4]> {
|
|
todo!()
|
|
}
|
|
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
|
|
let [x, y, ..] = to.area();
|
|
let frame = [x, y, 10, 6];
|
|
Lozenge(Style::default().fg(Nord::BG2)).draw(to.with_rect(frame))?;
|
|
to.blit(&"Start: ", x + 1, y + 1, STYLE_LABEL)?;
|
|
to.blit(&" 1.1.1", x + 1, y + 2, STYLE_VALUE)?;
|
|
to.blit(&"End: ", x + 1, y + 3, STYLE_LABEL)?;
|
|
to.blit(&" 2.1.1", x + 1, y + 4, STYLE_VALUE)?;
|
|
Ok(Some(frame))
|
|
}
|
|
}
|
|
|
|
struct SequenceLoopRange;
|
|
|
|
impl Widget for SequenceLoopRange {
|
|
type Engine = Tui;
|
|
fn layout (&self, area: [u16;4]) -> Perhaps<[u16;4]> {
|
|
todo!()
|
|
}
|
|
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
|
|
let [x, y, ..] = to.area();
|
|
let range = [x, y, 10, 7];
|
|
Lozenge(Style::default().fg(Nord::BG2)).draw(to.with_rect(range))?;
|
|
to.blit(&"Loop [ ]", x + 1, y + 1, STYLE_LABEL)?;
|
|
to.blit(&"From: ", x + 1, y + 2, STYLE_LABEL)?;
|
|
to.blit(&" 1.1.1", x + 1, y + 3, STYLE_VALUE)?;
|
|
to.blit(&"Length: ", x + 1, y + 4, STYLE_LABEL)?;
|
|
to.blit(&" 1.0.0", x + 1, y + 5, STYLE_VALUE)?;
|
|
Ok(Some(range))
|
|
}
|
|
}
|
|
|
|
struct SequenceNoteRange;
|
|
|
|
impl Widget for SequenceNoteRange {
|
|
type Engine = Tui;
|
|
fn layout (&self, area: [u16;4]) -> Perhaps<[u16;4]> {
|
|
todo!()
|
|
}
|
|
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
|
|
let [x, y, ..] = to.area();
|
|
let range = [x, y, 10, 9];
|
|
Lozenge(Style::default().fg(Nord::BG2)).draw(to.with_rect(range))?;
|
|
to.blit(&"Notes: ", x + 1, y + 1, STYLE_LABEL)?;
|
|
to.blit(&"C#0-C#9 ", x + 1, y + 2, STYLE_VALUE)?;
|
|
to.blit(&"[ /2 ]", x + 1, y + 3, STYLE_LABEL)?;
|
|
to.blit(&"[ x2 ]", x + 1, y + 4, STYLE_LABEL)?;
|
|
to.blit(&"[ Rev ]", x + 1, y + 5, STYLE_LABEL)?;
|
|
to.blit(&"[ Inv ]", x + 1, y + 6, STYLE_LABEL)?;
|
|
to.blit(&"[ Dup ]", x + 1, y + 7, STYLE_LABEL)?;
|
|
Ok(Some(to.area()))
|
|
}
|
|
}
|
|
|
|
struct SequenceKeys<'a>(&'a Sequencer<Tui>);
|
|
|
|
impl<'a> Widget for SequenceKeys<'a> {
|
|
type Engine = Tui;
|
|
fn layout (&self, area: [u16;4]) -> Perhaps<[u16;4]> {
|
|
todo!()
|
|
}
|
|
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
|
|
let area = to.area();
|
|
if area.h() < 2 {
|
|
return Ok(Some(area))
|
|
}
|
|
let area = [area.x(), area.y() + 1, 5, area.h() - 2];
|
|
buffer_update(to.buffer(), area, &|cell, x, y|{
|
|
let y = y + self.0.note_axis.start as u16;
|
|
if x < self.0.keys.area.width && y < self.0.keys.area.height {
|
|
*cell = self.0.keys.get(x, y).clone()
|
|
}
|
|
});
|
|
Ok(Some(area))
|
|
}
|
|
}
|
|
|
|
struct SequenceNotes<'a>(&'a Sequencer<Tui>);
|
|
|
|
impl<'a> Widget for SequenceNotes<'a> {
|
|
type Engine = Tui;
|
|
fn layout (&self, area: [u16;4]) -> Perhaps<[u16;4]> {
|
|
todo!()
|
|
}
|
|
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
|
|
let area = to.area();
|
|
if area.h() < 2 {
|
|
return Ok(Some(area))
|
|
}
|
|
let area = [
|
|
area.x() + Sequencer::H_KEYS_OFFSET as u16,
|
|
area.y() + 1,
|
|
area.w().saturating_sub(Sequencer::H_KEYS_OFFSET as u16),
|
|
area.h().saturating_sub(2),
|
|
];
|
|
to.buffer_update(area, &move |cell, x, y|{
|
|
let src_x = ((x as usize + self.0.time_axis.start) * self.0.time_axis.scale) as usize;
|
|
let src_y = (y as usize + self.0.note_axis.start) as usize;
|
|
if src_x < self.0.buffer.width && src_y < self.0.buffer.height - 1 {
|
|
let src = self.0.buffer.get(src_x, self.0.buffer.height - src_y);
|
|
src.map(|src|{
|
|
cell.set_symbol(src.symbol());
|
|
cell.set_fg(src.fg);
|
|
});
|
|
}
|
|
});
|
|
Ok(Some(area))
|
|
}
|
|
}
|
|
|
|
struct SequenceCursor<'a>(&'a Sequencer<Tui>);
|
|
|
|
impl<'a> Widget for SequenceCursor<'a> {
|
|
type Engine = Tui;
|
|
fn layout (&self, area: [u16;4]) -> Perhaps<[u16;4]> {
|
|
todo!()
|
|
}
|
|
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
|
|
let area = to.area();
|
|
if let (Some(time), Some(note)) = (self.0.time_axis.point, self.0.note_axis.point) {
|
|
let x = area.x() + Sequencer::H_KEYS_OFFSET as u16 + time as u16;
|
|
let y = area.y() + 1 + note as u16 / 2;
|
|
let c = if note % 2 == 0 { "▀" } else { "▄" };
|
|
to.blit(&c, x, y, self.0.style_focus())
|
|
} else {
|
|
Ok(Some([0,0,0,0]))
|
|
}
|
|
}
|
|
}
|
|
|
|
struct SequenceZoom<'a>(&'a Sequencer<Tui>);
|
|
|
|
impl<'a> Widget for SequenceZoom<'a> {
|
|
type Engine = Tui;
|
|
fn layout (&self, area: [u16;4]) -> Perhaps<[u16;4]> {
|
|
todo!()
|
|
}
|
|
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
|
|
let area = to.area();
|
|
let quant = ppq_to_name(self.0.time_axis.scale);
|
|
let quant_x = area.x() + area.w() - 1 - quant.len() as u16;
|
|
let quant_y = area.y() + area.h() - 2;
|
|
to.blit(&quant, quant_x, quant_y, self.0.style_focus())
|
|
}
|
|
}
|
|
|
|
struct SequenceTimer<'a>(&'a Sequencer<Tui>, Arc<RwLock<Phrase>>);
|
|
|
|
impl<'a> Widget for SequenceTimer<'a> {
|
|
type Engine = Tui;
|
|
fn layout (&self, area: [u16;4]) -> Perhaps<[u16;4]> {
|
|
todo!()
|
|
}
|
|
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
|
|
let area = to.area();
|
|
let phrase = self.1.read().unwrap();
|
|
let (time0, time_z, now) = (
|
|
self.0.time_axis.start, self.0.time_axis.scale, self.0.now % phrase.length
|
|
);
|
|
let [x, _, width, _] = area;
|
|
let x2 = x as usize + Sequencer::H_KEYS_OFFSET;
|
|
let x3 = x as usize + width as usize;
|
|
for x in x2..x3 {
|
|
let step = (time0 + x2) * time_z;
|
|
let next_step = (time0 + x2 + 1) * time_z;
|
|
let style = Sequencer::<Tui>::style_timer_step(now, step as usize, next_step as usize);
|
|
to.blit(&"-", x as u16, area.y(), Some(style))?;
|
|
}
|
|
return Ok(Some([area.x(), area.y(), area.w(), 1]))
|
|
}
|
|
}
|