mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-08 20:56:43 +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
|
|
@ -8,6 +8,16 @@ pub struct ChainView<'a> {
|
|||
pub vertical: bool,
|
||||
}
|
||||
|
||||
impl<'a> ChainView<'a> {
|
||||
pub fn new (app: &'a App, vertical: bool) -> Self {
|
||||
Self {
|
||||
focused: app.section == AppSection::Chain,
|
||||
track: app.tracks.get(app.track_cursor - 1),
|
||||
vertical
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Render for ChainView<'a> {
|
||||
fn render (&self, buf: &mut Buffer, area: Rect) -> Usually<Rect> {
|
||||
let style = Some(if self.focused {
|
||||
|
|
|
|||
|
|
@ -28,44 +28,75 @@ pub struct SequencerView<'a> {
|
|||
pub notes_out: &'a [bool; 128],
|
||||
}
|
||||
|
||||
impl<'a> SequencerView<'a> {
|
||||
pub fn new (app: &'a App) -> Self {
|
||||
let track = app.tracks.get(app.track_cursor - 1);
|
||||
let phrase = app.phrase();
|
||||
Self {
|
||||
phrase,
|
||||
focused: app.section == AppSection::Sequencer,
|
||||
ppq: app.timebase.ppq() as usize,
|
||||
now: app.timebase.frame_to_pulse(app.playhead as f64) as usize,
|
||||
time_cursor: app.time_cursor,
|
||||
time_start: app.time_start,
|
||||
time_zoom: app.time_zoom,
|
||||
note_cursor: app.note_cursor,
|
||||
note_start: app.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] },
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Render for SequencerView<'a> {
|
||||
fn render (&self, buf: &mut Buffer, area: Rect) -> Usually<Rect> {
|
||||
let bg = if self.focused { Color::Rgb(20, 45, 5) } else { Color::Reset };
|
||||
fill_bg(buf, area, bg);
|
||||
self.draw_horizontal(buf, area)?;
|
||||
self.horizontal_draw(buf, area)?;
|
||||
Ok(area)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> SequencerView<'a> {
|
||||
fn draw_horizontal (&self, buf: &mut Buffer, area: Rect) -> Usually<()> {
|
||||
let style = Some(if self.focused {
|
||||
fn style_focus (&self) -> Option<Style> {
|
||||
Some(if self.focused {
|
||||
Style::default().green().not_dim()
|
||||
} else {
|
||||
Style::default().green().dim()
|
||||
});
|
||||
self::horizontal::keys(buf, area, self.note_start, self.notes_in, self.notes_out)?;
|
||||
let quant = ppq_to_name(self.time_zoom);
|
||||
quant.blit(
|
||||
buf,
|
||||
area.x + area.width - 1 - quant.len() as u16,
|
||||
area.y + area.height - 2,
|
||||
style
|
||||
);
|
||||
if let Some(phrase) = self.phrase {
|
||||
self::horizontal::timer(buf, area, self.time_start, self.time_zoom, self.now % phrase.length);
|
||||
self::horizontal::lanes(buf, area, phrase, self.ppq, self.time_zoom, self.time_start, self.note_start);
|
||||
}
|
||||
self::horizontal::cursor(buf, area, style.unwrap(), self.time_cursor, self.note_cursor);
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
mod horizontal {
|
||||
use crate::core::*;
|
||||
use super::*;
|
||||
impl<'a> SequencerView<'a> {
|
||||
fn horizontal_draw (&self, buf: &mut Buffer, area: Rect) -> Usually<()> {
|
||||
self.horizontal_keys(buf, area)?;
|
||||
self.horizontal_quant(buf, area);
|
||||
if let Some(phrase) = self.phrase {
|
||||
self.horizontal_timer(buf, area, phrase);
|
||||
self.horizontal_lanes(buf, area, phrase);
|
||||
}
|
||||
self.horizontal_cursor(buf, area);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn timer (buf: &mut Buffer, area: Rect, time0: usize, time_z: usize, now: usize) {
|
||||
fn horizontal_quant (&self, buf: &mut Buffer, area: Rect) {
|
||||
let quant = ppq_to_name(self.time_zoom);
|
||||
let quant_x = area.x + area.width - 1 - quant.len() as u16;
|
||||
let quant_y = area.y + area.height - 2;
|
||||
quant.blit(buf, quant_x, quant_y, self.style_focus());
|
||||
}
|
||||
|
||||
fn horizontal_cursor (&self, buf: &mut Buffer, area: Rect) {
|
||||
let (time, note) = (self.time_cursor, self.note_cursor);
|
||||
let x = area.x + 5 + time as u16;
|
||||
let y = area.y + 1 + note as u16 / 2;
|
||||
let c = if note % 2 == 0 { "▀" } else { "▄" };
|
||||
c.blit(buf, x, y, self.style_focus());
|
||||
}
|
||||
|
||||
fn horizontal_timer (&self, buf: &mut Buffer, area: Rect, phrase: &Phrase) {
|
||||
let (time0, time_z, now) =
|
||||
(self.time_start, self.time_zoom, self.now % phrase.length);
|
||||
let Rect { x, width, .. } = area;
|
||||
let offset = 5;
|
||||
for x in x+offset..x+width-offset {
|
||||
|
|
@ -80,13 +111,8 @@ mod horizontal {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn keys (
|
||||
buf: &mut Buffer,
|
||||
area: Rect,
|
||||
note0: usize,
|
||||
notes_in: &[bool;128],
|
||||
notes_out: &[bool;128],
|
||||
) -> Usually<Rect> {
|
||||
fn horizontal_keys (&self, buf: &mut Buffer, area: Rect) -> Usually<Rect> {
|
||||
let (note0, notes_in, notes_out) = (self.note_start, self.notes_in, self.notes_out);
|
||||
let dim = Style::default().not_dim();
|
||||
let red = Style::default().red();
|
||||
let yellow = Style::default().yellow();
|
||||
|
|
@ -112,7 +138,7 @@ mod horizontal {
|
|||
|
||||
let Rect { x, y, width, height } = area;
|
||||
let height = height.min(128);
|
||||
let h = height.saturating_sub(2);
|
||||
let h = height.saturating_sub(3);
|
||||
let index_to_color = |index: usize, default: Color|
|
||||
if notes_in[index] && notes_out[index] {
|
||||
Color::Yellow
|
||||
|
|
@ -208,15 +234,9 @@ mod horizontal {
|
|||
Ok(area)
|
||||
}
|
||||
|
||||
pub fn lanes (
|
||||
buf: &mut Buffer,
|
||||
area: Rect,
|
||||
phrase: &Phrase,
|
||||
ppq: usize,
|
||||
time_z: usize,
|
||||
time0: usize,
|
||||
note0: usize,
|
||||
) {
|
||||
fn horizontal_lanes (&self, buf: &mut Buffer, area: Rect, phrase: &Phrase) {
|
||||
let (ppq, time_z, time0, note0) =
|
||||
(self.ppq, self.time_zoom, self.time_start, self.note_start);
|
||||
let bg = Style::default();
|
||||
let (bw, wh) = (bg.dim(), bg.white().not_dim());
|
||||
|
||||
|
|
@ -295,22 +315,8 @@ mod horizontal {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn cursor (
|
||||
buf: &mut Buffer,
|
||||
area: Rect,
|
||||
style: Style,
|
||||
time: usize,
|
||||
note: usize
|
||||
) {
|
||||
let x = area.x + 5 + time as u16;
|
||||
let y = area.y + 1 + note as u16 / 2;
|
||||
let c = if note % 2 == 0 { "▀" } else { "▄" };
|
||||
c.blit(buf, x, y, Some(style));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//pub fn footer (
|
||||
//buf: &mut Buffer,
|
||||
//area: Rect,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::core::*;
|
||||
use crate::{core::*, model::App};
|
||||
|
||||
pub struct TransportView<'a> {
|
||||
pub timebase: &'a Arc<Timebase>,
|
||||
|
|
@ -10,6 +10,20 @@ pub struct TransportView<'a> {
|
|||
pub quant: usize,
|
||||
}
|
||||
|
||||
impl<'a> TransportView<'a> {
|
||||
pub fn new (app: &'a App) -> Self {
|
||||
Self {
|
||||
timebase: &app.timebase,
|
||||
playing: *app.playing.as_ref().unwrap_or(&TransportState::Stopped),
|
||||
monitor: app.track().map(|t|t.1.monitoring).unwrap_or(false),
|
||||
record: app.track().map(|t|t.1.recording).unwrap_or(false),
|
||||
overdub: app.track().map(|t|t.1.overdub).unwrap_or(false),
|
||||
frame: app.playhead,
|
||||
quant: app.quant,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Render for TransportView<'a> {
|
||||
fn render (&self, buf: &mut Buffer, area: Rect) -> Usually<Rect> {
|
||||
fill_bg(buf, area, Color::Rgb(20, 45, 5));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue