tek/src/view.rs

100 lines
3 KiB
Rust

pub mod chain;
pub mod grid;
pub mod layout;
pub mod mixer;
pub mod sampler;
pub mod sequencer;
pub mod transport;
pub mod plugin;
pub use self::layout::*;
pub use self::transport::TransportView;
pub use self::grid::SceneGridView;
pub use self::chain::ChainView;
pub use self::sequencer::SequencerView;
use crate::{render, App, core::*};
render!(App |self, buf, area| {
let Rect { x, mut y, width, height } = area;
y = y + 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)?.height;
y = y + SceneGridView {
buf,
area: Rect { x, y, width, height: height / 3 },
name: "",
mode: self.grid_mode,
focused: self.section == 0,
scenes: &self.scenes,
tracks: &self.tracks,
cursor: &(self.track_cursor, self.scene_cursor),
}.draw()?.height;
if self.track_cursor > 0 {
let track = self.tracks
.get(self.track_cursor - 1)
.unwrap();
let chain_area = Rect { x, y: y + height - height / 3 - 1, width, height: height / 3 };
ChainView {
focused: self.section == 1,
track: Some(track),
vertical: false,
}
.render(buf, chain_area)?;
let phrase = self.phrase();
let seq_area = SequencerView {
phrase,
focused: self.section == 2,
ppq: self.timebase.ppq() as usize,
now: self.timebase.pulse_to_frame(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,
}.render(buf, Rect { x, y, width, height: height - height / 3 })?;
if phrase.is_none() && self.section == 2 {
let label = format!("[ENTER] Create new clip: {}", track.name);
let x = x + seq_area.width / 2 - (label.len() / 2) as u16;
let y = y + seq_area.height / 2;
label.blit(buf, x, y, Some(Style::default().white()));
}
} else {
let mut x = x;
for track in self.tracks.iter() {
track.name.blit(buf, x + 1, y, Some(Style::default().white().bold()));
x = x + ChainView {
focused: self.section == 1,
track: Some(track),
vertical: true,
}
.render(buf, Rect { x, y: y + 1, width, height: height - y - 1 })?
.width
.max(track.name.len() as u16);
}
}
if let Some(ref modal) = self.modal {
modal.render(buf, area)?;
}
Ok(area)
});