mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 04:06:45 +01:00
wip: <200 errors yay
This commit is contained in:
parent
14d619a10a
commit
694970bf0d
20 changed files with 384 additions and 305 deletions
|
|
@ -4,8 +4,8 @@ impl Sequencer {
|
|||
|
||||
const H_KEYS_OFFSET: usize = 5;
|
||||
|
||||
pub(crate) fn horizontal_draw <'a> (&self, to: &mut TuiOutput<'a>) -> Usually<()> {
|
||||
let mut area = to.area;
|
||||
pub(crate) fn horizontal_draw <'a> (&self, to: &mut Tui) -> Usually<()> {
|
||||
let mut area = to.area();
|
||||
Split::down()
|
||||
.add_ref(&SequenceName(&self))
|
||||
.add_ref(&SequenceRange)
|
||||
|
|
@ -32,7 +32,10 @@ impl Sequencer {
|
|||
.add_ref(&SequenceNotes(&self))
|
||||
.add_ref(&SequenceCursor(&self))
|
||||
.add_ref(&SequenceZoom(&self))
|
||||
.render(&mut TuiOutput { buffer: to.buffer, area: area })?;
|
||||
.render(&mut TuiOutput {
|
||||
buffer: to.buffer,
|
||||
area: area
|
||||
})?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
@ -56,9 +59,9 @@ const STYLE_VALUE: Option<Style> = Some(Style {
|
|||
|
||||
struct SequenceName<'a>(&'a Sequencer);
|
||||
|
||||
impl<'a> Render<TuiOutput<'a>, Rect> for SequenceName<'a> {
|
||||
fn render (&self, to: &mut TuiOutput<'a>) -> Perhaps<Rect> {
|
||||
let Rect { x, y, .. } = to.area;
|
||||
impl<'a> Render<Tui> for SequenceName<'a> {
|
||||
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
|
||||
let Rect { x, y, .. } = to.area();
|
||||
let frame = Rect { x, y, width: 10, height: 4 };
|
||||
Lozenge(Style::default().fg(Nord::BG2)).draw(to.buffer, frame)?;
|
||||
"Name:".blit(to.buffer, x + 1, y + 1, STYLE_LABEL)?;
|
||||
|
|
@ -69,9 +72,9 @@ impl<'a> Render<TuiOutput<'a>, Rect> for SequenceName<'a> {
|
|||
|
||||
struct SequenceRange;
|
||||
|
||||
impl<'a> Render<TuiOutput<'a>, Rect> for SequenceRange {
|
||||
fn render (&self, to: &mut TuiOutput<'a>) -> Perhaps<Rect> {
|
||||
let Rect { x, y, .. } = to.area;
|
||||
impl<'a> Render<Tui> for SequenceRange {
|
||||
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
|
||||
let Rect { x, y, .. } = to.area();
|
||||
let frame = Rect { x, y, width: 10, height: 6 };
|
||||
Lozenge(Style::default().fg(Nord::BG2)).draw(to.buffer, frame)?;
|
||||
"Start: ".blit(to.buffer, x + 1, y + 1, STYLE_LABEL)?;
|
||||
|
|
@ -84,9 +87,9 @@ impl<'a> Render<TuiOutput<'a>, Rect> for SequenceRange {
|
|||
|
||||
struct SequenceLoopRange;
|
||||
|
||||
impl<'a> Render<TuiOutput<'a>, Rect> for SequenceLoopRange {
|
||||
fn render (&self, to: &mut TuiOutput<'a>) -> Perhaps<Rect> {
|
||||
let Rect { x, y, .. } = to.area;
|
||||
impl<'a> Render<Tui> for SequenceLoopRange {
|
||||
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
|
||||
let Rect { x, y, .. } = to.area();
|
||||
let range = Rect { x, y, width: 10, height: 7 };
|
||||
Lozenge(Style::default().fg(Nord::BG2)).draw(to.buffer, range)?;
|
||||
"Loop [ ]".blit(to.buffer, x + 1, y + 1, STYLE_LABEL)?;
|
||||
|
|
@ -100,9 +103,9 @@ impl<'a> Render<TuiOutput<'a>, Rect> for SequenceLoopRange {
|
|||
|
||||
struct SequenceNoteRange;
|
||||
|
||||
impl<'a> Render<TuiOutput<'a>, Rect> for SequenceNoteRange {
|
||||
fn render (&self, to: &mut TuiOutput<'a>) -> Perhaps<Rect> {
|
||||
let Rect { x, y, .. } = to.area;
|
||||
impl<'a> Render<Tui> for SequenceNoteRange {
|
||||
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
|
||||
let Rect { x, y, .. } = to.area();
|
||||
let range = Rect { x, y, width: 10, height: 9 };
|
||||
Lozenge(Style::default().fg(Nord::BG2)).draw(to.buffer, range)?;
|
||||
"Notes: ".blit(to.buffer, x + 1, y + 1, STYLE_LABEL)?;
|
||||
|
|
@ -118,8 +121,8 @@ impl<'a> Render<TuiOutput<'a>, Rect> for SequenceNoteRange {
|
|||
|
||||
struct SequenceKeys<'a>(&'a Sequencer);
|
||||
|
||||
impl<'a> Render<TuiOutput<'a>, Rect> for SequenceKeys<'a> {
|
||||
fn render (&self, to: &mut TuiOutput<'a>) -> Perhaps<Rect> {
|
||||
impl<'a> Render<Tui> for SequenceKeys<'a> {
|
||||
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
|
||||
if to.area.height < 2 {
|
||||
return Ok(Some(to.area))
|
||||
}
|
||||
|
|
@ -141,18 +144,19 @@ impl<'a> Render<TuiOutput<'a>, Rect> for SequenceKeys<'a> {
|
|||
|
||||
struct SequenceNotes<'a>(&'a Sequencer);
|
||||
|
||||
impl<'a> Render<TuiOutput<'a>, Rect> for SequenceNotes<'a> {
|
||||
fn render (&self, to: &mut TuiOutput<'a>) -> Perhaps<Rect> {
|
||||
if to.area.height < 2 {
|
||||
return Ok(Some(to.area))
|
||||
impl<'a> Render<Tui> for SequenceNotes<'a> {
|
||||
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
|
||||
let area = to.area();
|
||||
if area.height < 2 {
|
||||
return Ok(Some(area))
|
||||
}
|
||||
let area = Rect {
|
||||
x: to.area.x + Sequencer::H_KEYS_OFFSET as u16,
|
||||
y: to.area.y + 1,
|
||||
width: to.area.width - Sequencer::H_KEYS_OFFSET as u16,
|
||||
height: to.area.height - 2
|
||||
x: area.x + Sequencer::H_KEYS_OFFSET as u16,
|
||||
y: area.y + 1,
|
||||
width: area.width - Sequencer::H_KEYS_OFFSET as u16,
|
||||
height: area.height - 2
|
||||
};
|
||||
buffer_update(to.buffer, area, &move |cell, x, y|{
|
||||
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 {
|
||||
|
|
@ -163,19 +167,20 @@ impl<'a> Render<TuiOutput<'a>, Rect> for SequenceNotes<'a> {
|
|||
});
|
||||
}
|
||||
});
|
||||
Ok(Some(to.area))
|
||||
Ok(Some(area))
|
||||
}
|
||||
}
|
||||
|
||||
struct SequenceCursor<'a>(&'a Sequencer);
|
||||
|
||||
impl<'a> Render<TuiOutput<'a>, Rect> for SequenceCursor<'a> {
|
||||
fn render (&self, to: &mut TuiOutput<'a>) -> Perhaps<Rect> {
|
||||
impl<'a> Render<Tui> for SequenceCursor<'a> {
|
||||
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
|
||||
let area = to.area();
|
||||
if let (Some(time), Some(note)) = (self.0.time_axis.point, self.0.note_axis.point) {
|
||||
let x = to.area.x + Sequencer::H_KEYS_OFFSET as u16 + time as u16;
|
||||
let y = to.area.y + 1 + note as u16 / 2;
|
||||
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 { "▄" };
|
||||
c.blit(to.buffer, x, y, self.0.style_focus())
|
||||
to.blit(&c, x, y, self.0.style_focus())
|
||||
} else {
|
||||
Ok(Some(Rect::default()))
|
||||
}
|
||||
|
|
@ -184,32 +189,34 @@ impl<'a> Render<TuiOutput<'a>, Rect> for SequenceCursor<'a> {
|
|||
|
||||
struct SequenceZoom<'a>(&'a Sequencer);
|
||||
|
||||
impl<'a> Render<TuiOutput<'a>, Rect> for SequenceZoom<'a> {
|
||||
fn render (&self, to: &mut TuiOutput<'a>) -> Perhaps<Rect> {
|
||||
impl<'a> Render<Tui> for SequenceZoom<'a> {
|
||||
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
|
||||
let area = to.area();
|
||||
let quant = ppq_to_name(self.0.time_axis.scale);
|
||||
let quant_x = to.area.x + to.area.width - 1 - quant.len() as u16;
|
||||
let quant_y = to.area.y + to.area.height - 2;
|
||||
quant.blit(to.buffer, quant_x, quant_y, self.0.style_focus())
|
||||
let quant_x = area.x + area.width - 1 - quant.len() as u16;
|
||||
let quant_y = area.y + area.height - 2;
|
||||
buffer.blit(&quant, quant_x, quant_y, self.0.style_focus())
|
||||
}
|
||||
}
|
||||
|
||||
struct SequenceTimer<'a>(&'a Sequencer, Arc<RwLock<Phrase>>);
|
||||
|
||||
impl<'a> Render<TuiOutput<'a>, Rect> for SequenceTimer<'a> {
|
||||
fn render (&self, to: &mut TuiOutput<'a>) -> Perhaps<Rect> {
|
||||
impl<'a> Render<Tui> for SequenceTimer<'a> {
|
||||
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
|
||||
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 Rect { x, width, .. } = to.area;
|
||||
let Rect { 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::style_timer_step(now, step as usize, next_step as usize);
|
||||
"-".blit(to.buffer, x as u16, to.area.y, Some(style))?;
|
||||
to.blit(&"-", x as u16, area.y, Some(style))?;
|
||||
}
|
||||
return Ok(Some(Rect { x: to.area.x, y: to.area.y, width: to.area.width, height: 1 }))
|
||||
return Ok(Some(Rect { x: area.x, y: area.y, width: area.width, height: 1 }))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue