mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
refactor: view constructors from App
This commit is contained in:
parent
1e3d96e64e
commit
b01863dfdc
5 changed files with 88 additions and 102 deletions
50
src/view.rs
50
src/view.rs
|
|
@ -18,7 +18,7 @@ use crate::{render, App, AppSection, core::*};
|
|||
|
||||
render!(App |self, buf, area| {
|
||||
let Rect { x, y, width, height } = area;
|
||||
let transport = self.draw_transport(buf, area)?;
|
||||
let transport = TransportView::new(self).render(buf, area)?;
|
||||
let y = y + transport.height;
|
||||
let arranger = if self.arranger_mode {
|
||||
self.draw_arranger_horizontal(buf, Rect {
|
||||
|
|
@ -38,7 +38,7 @@ render!(App |self, buf, area| {
|
|||
}
|
||||
let y = y + arranger.height;
|
||||
if self.track_cursor > 0 {
|
||||
let chain = self.draw_chain(buf, Rect {
|
||||
let chain = ChainView::new(&self, false).render(buf, Rect {
|
||||
x, y: y + height - height / 3 - 1, width, height: height / 3
|
||||
})?;
|
||||
if self.section == AppSection::Chain {
|
||||
|
|
@ -48,7 +48,7 @@ render!(App |self, buf, area| {
|
|||
Style::default().green().dim()
|
||||
}).draw(buf, Rect { width, ..chain })
|
||||
}
|
||||
let phrase = self.draw_phrase(buf, Rect {
|
||||
let phrase = SequencerView::new(&self).render(buf, Rect {
|
||||
x, y, width, height: height - height / 3
|
||||
})?;
|
||||
if self.section == AppSection::Sequencer {
|
||||
|
|
@ -88,17 +88,6 @@ impl App {
|
|||
}
|
||||
Ok(area)
|
||||
}
|
||||
fn draw_transport (&self, buf: &mut Buffer, area: Rect) -> Usually<Rect> {
|
||||
TransportView {
|
||||
timebase: &self.timebase,
|
||||
playing: *self.playing.as_ref().unwrap_or(&TransportState::Stopped),
|
||||
monitor: self.track().map(|t|t.1.monitoring).unwrap_or(false),
|
||||
record: self.track().map(|t|t.1.recording).unwrap_or(false),
|
||||
overdub: self.track().map(|t|t.1.overdub).unwrap_or(false),
|
||||
frame: self.playhead,
|
||||
quant: self.quant,
|
||||
}.render(buf, area)
|
||||
}
|
||||
fn draw_arranger_horizontal (&self, buf: &mut Buffer, area: Rect) -> Usually<Rect> {
|
||||
ArrangerViewHorizontal {
|
||||
buf,
|
||||
|
|
@ -121,37 +110,4 @@ impl App {
|
|||
cursor: &(self.track_cursor, self.scene_cursor),
|
||||
}.draw()
|
||||
}
|
||||
fn draw_chain (&self, buf: &mut Buffer, area: Rect) -> Usually<Rect> {
|
||||
ChainView {
|
||||
focused: self.section == AppSection::Chain,
|
||||
track: self.tracks.get(self.track_cursor - 1),
|
||||
vertical: false,
|
||||
}.render(buf, area)
|
||||
}
|
||||
fn draw_phrase (&self, buf: &mut Buffer, area: Rect) -> Usually<Rect> {
|
||||
let track = self.tracks.get(self.track_cursor - 1);
|
||||
let phrase = self.phrase();
|
||||
let seq_area = SequencerView {
|
||||
phrase,
|
||||
focused: self.section == AppSection::Sequencer,
|
||||
ppq: self.timebase.ppq() as usize,
|
||||
now: self.timebase.frame_to_pulse(self.playhead as f64) as usize,
|
||||
time_cursor: self.time_cursor,
|
||||
time_start: self.time_start,
|
||||
time_zoom: self.time_zoom,
|
||||
note_cursor: self.note_cursor,
|
||||
note_start: self.note_start,
|
||||
notes_in: if let Some(track) = track { &track.notes_in } else { &[false;128] },
|
||||
notes_out: if let Some(track) = track { &track.notes_out } else { &[false;128] },
|
||||
}.render(buf, area)?;
|
||||
if let Some(track) = track {
|
||||
if phrase.is_none() && self.section == AppSection::Sequencer {
|
||||
let label = format!("[ENTER] Create new clip: {}", track.name);
|
||||
let x = area.x + seq_area.width / 2 - (label.len() / 2) as u16;
|
||||
let y = area.y + seq_area.height / 2;
|
||||
label.blit(buf, x, y, Some(Style::default().white()));
|
||||
}
|
||||
}
|
||||
Ok(seq_area)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue