mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 19:56:42 +01:00
wip: <200 errors yay
This commit is contained in:
parent
14d619a10a
commit
694970bf0d
20 changed files with 384 additions and 305 deletions
|
|
@ -117,16 +117,7 @@ impl Tui {
|
|||
&mut self.buffers[self.buffer]
|
||||
}
|
||||
pub fn buffer_update (&mut self, area: Rect, callback: &impl Fn(&mut Cell, u16, u16)) {
|
||||
let buf = self.buffer();
|
||||
for row in 0..area.height {
|
||||
let y = area.y + row;
|
||||
for col in 0..area.width {
|
||||
let x = area.x + col;
|
||||
if x < buf.area.width && y < buf.area.height {
|
||||
callback(buf.get_mut(x, y), col, row);
|
||||
}
|
||||
}
|
||||
}
|
||||
buffer_update(self.buffer(), area, callback)
|
||||
}
|
||||
pub fn fill_bg (&mut self, area: Rect, color: Color) {
|
||||
self.buffer_update(area, &|cell,_,_|{cell.set_bg(color);})
|
||||
|
|
@ -628,3 +619,15 @@ impl<R: Render<Tui>> Render<Tui> for (Outset<u16>, R) {
|
|||
)))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn buffer_update (buf: &mut Buffer, area: Rect, callback: &impl Fn(&mut Cell, u16, u16)) {
|
||||
for row in 0..area.height {
|
||||
let y = area.y + row;
|
||||
for col in 0..area.width {
|
||||
let x = area.x + col;
|
||||
if x < buf.area.width && y < buf.area.height {
|
||||
callback(buf.get_mut(x, y), col, row);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ version = "0.1.0"
|
|||
|
||||
[dependencies]
|
||||
tek_core = { path = "../tek_core" }
|
||||
tek_proc = { path = "../tek_proc" }
|
||||
|
||||
livi = "0.7.4"
|
||||
suil-rs = { path = "../suil" }
|
||||
|
|
@ -31,4 +32,4 @@ path = "src/sampler_main.rs"
|
|||
|
||||
[[bin]]
|
||||
name = "tek_plugin"
|
||||
path = "src/plugin_main.rs"
|
||||
path = "src/sampler_main.rs"
|
||||
|
|
|
|||
|
|
@ -25,5 +25,6 @@ submod! {
|
|||
sample_add
|
||||
sampler
|
||||
sampler_edn
|
||||
sampler_view
|
||||
voice
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
use crate::*;
|
||||
|
||||
pub struct Mixer<E> {
|
||||
pub struct Mixer<E: Engine> {
|
||||
pub name: String,
|
||||
pub tracks: Vec<Track<E>>,
|
||||
pub selected_track: usize,
|
||||
pub selected_column: usize,
|
||||
}
|
||||
impl<E> Mixer<E> {
|
||||
impl<E: Engine> Mixer<E> {
|
||||
pub fn new (name: &str) -> Usually<Self> {
|
||||
let (client, _status) = Client::new(name, ClientOptions::NO_START_SERVER)?;
|
||||
Ok(Self {
|
||||
|
|
@ -25,7 +25,7 @@ impl<E> Mixer<E> {
|
|||
self.tracks.get(self.selected_track)
|
||||
}
|
||||
}
|
||||
impl<E> Process for Mixer<E> {
|
||||
impl<E: Engine> Process for Mixer<E> {
|
||||
fn process (&mut self, _: &Client, _: &ProcessScope) -> Control {
|
||||
Control::Continue
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,21 +22,20 @@ pub struct AddSampleModal {
|
|||
|
||||
exit!(AddSampleModal);
|
||||
|
||||
impl<'a> Render<TuiOutput<'a>, Rect> for AddSampleModal {
|
||||
fn render (&self, to: &mut TuiOutput<'a>) -> Perhaps<Rect> {
|
||||
make_dim(to.buffer);
|
||||
impl Render<Tui> for AddSampleModal {
|
||||
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
|
||||
let area = to.area();
|
||||
to.make_dim();
|
||||
let area = center_box(
|
||||
to.area,
|
||||
64.max(to.area.width.saturating_sub(8)),
|
||||
20.max(to.area.width.saturating_sub(8)),
|
||||
area,
|
||||
64.max(area.width.saturating_sub(8)),
|
||||
20.max(area.width.saturating_sub(8)),
|
||||
);
|
||||
fill_fg(to.buffer, area, Color::Reset);
|
||||
fill_bg(to.buffer, area, Nord::bg_lo(true, true));
|
||||
fill_char(to.buffer, area, ' ');
|
||||
format!("{}", &self.dir.to_string_lossy())
|
||||
.blit(to.buffer, area.x+2, area.y+1, Some(Style::default().bold()))?;
|
||||
"Select sample:"
|
||||
.blit(to.buffer, area.x+2, area.y+2, Some(Style::default().bold()))?;
|
||||
to.fill_fg(area, Color::Reset);
|
||||
to.fill_bg(area, Nord::bg_lo(true, true));
|
||||
to.fill_char(area, ' ');
|
||||
to.blit(&format!("{}", &self.dir.to_string_lossy()), area.x+2, area.y+1, Some(Style::default().bold()))?;
|
||||
to.blit(&"Select sample:", area.x+2, area.y+2, Some(Style::default().bold()))?;
|
||||
for (i, (is_dir, name)) in self.subdirs.iter()
|
||||
.map(|path|(true, path))
|
||||
.chain(self.files.iter().map(|path|(false, path)))
|
||||
|
|
@ -49,7 +48,7 @@ impl<'a> Render<TuiOutput<'a>, Rect> for AddSampleModal {
|
|||
let t = if is_dir { "" } else { "" };
|
||||
let line = format!("{t} {}", name.to_string_lossy());
|
||||
let line = &line[..line.len().min(area.width as usize - 4)];
|
||||
line.blit(to.buffer, area.x + 2, area.y + 3 + i as u16, Some(if i == self.cursor {
|
||||
to.blit(&line, area.x + 2, area.y + 3 + i as u16, Some(if i == self.cursor {
|
||||
Style::default().green()
|
||||
} else {
|
||||
Style::default().white()
|
||||
|
|
@ -58,13 +57,14 @@ impl<'a> Render<TuiOutput<'a>, Rect> for AddSampleModal {
|
|||
Lozenge(Style::default()).draw(to)
|
||||
}
|
||||
}
|
||||
|
||||
handle!(AddSampleModal |self,e|{
|
||||
if handle_keymap(self, e, KEYMAP_ADD_SAMPLE)? {
|
||||
return Ok(true)
|
||||
impl Handle<Tui> for AddSampleModal {
|
||||
fn handle (&mut self, e: &Tui) -> Usually<bool> {
|
||||
if handle_keymap(self, e, KEYMAP_ADD_SAMPLE)? {
|
||||
return Ok(true)
|
||||
}
|
||||
Ok(true)
|
||||
}
|
||||
Ok(true)
|
||||
});
|
||||
}
|
||||
|
||||
impl AddSampleModal {
|
||||
pub fn new (
|
||||
|
|
|
|||
|
|
@ -13,56 +13,20 @@ pub struct Sampler {
|
|||
pub modal: Arc<Mutex<Option<Box<dyn Exit + Send>>>>,
|
||||
pub output_gain: f32
|
||||
}
|
||||
impl<E: Engine> Handle<E> for Sampler {
|
||||
fn handle (&mut self, e: &E) -> Usually<E::Handled> {
|
||||
handle_keymap(self, event, KEYMAP_SAMPLER)
|
||||
}
|
||||
}
|
||||
impl Render<Tui> for Sampler {
|
||||
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
|
||||
tui_render_sampler(self, to)
|
||||
}
|
||||
}
|
||||
|
||||
process!(Sampler = Sampler::process);
|
||||
|
||||
handle!(Sampler |self, event| handle_keymap(self, event, KEYMAP_SAMPLER));
|
||||
|
||||
impl Render<Tui> for Sampler {
|
||||
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
|
||||
let Rect { x, y, height, .. } = to.area();
|
||||
let style = Style::default().gray();
|
||||
let title = format!(" {} ({})", self.name, self.voices.read().unwrap().len());
|
||||
title.blit(to.buffer(), x+1, y, Some(style.white().bold().not_dim()))?;
|
||||
let mut width = title.len() + 2;
|
||||
let mut y1 = 1;
|
||||
let mut j = 0;
|
||||
for (note, sample) in self.mapped.iter()
|
||||
.map(|(note, sample)|(Some(note), sample))
|
||||
.chain(self.unmapped.iter().map(|sample|(None, sample)))
|
||||
{
|
||||
if y1 >= height {
|
||||
break
|
||||
}
|
||||
let active = j == self.cursor.0;
|
||||
width = width.max(
|
||||
draw_sample(to.buffer(), x, y + y1, note, &*sample.read().unwrap(), active)?
|
||||
);
|
||||
y1 = y1 + 1;
|
||||
j = j + 1;
|
||||
}
|
||||
let height = ((2 + y1) as u16).min(height);
|
||||
Ok(Some(Rect { x, y, width: (width as u16).min(to.area().width), height }))
|
||||
}
|
||||
}
|
||||
|
||||
fn draw_sample (
|
||||
buf: &mut Buffer, x: u16, y: u16, note: Option<&u7>, sample: &Sample, focus: bool
|
||||
) -> Usually<usize> {
|
||||
let style = if focus { Style::default().green() } else { Style::default() };
|
||||
if focus {
|
||||
"🬴".blit(buf, x+1, y, Some(style.bold()))?;
|
||||
}
|
||||
let label1 = format!("{:3} {:12}",
|
||||
note.map(|n|n.to_string()).unwrap_or(String::default()),
|
||||
sample.name);
|
||||
let label2 = format!("{:>6} {:>6} +0.0",
|
||||
sample.start,
|
||||
sample.end);
|
||||
label1.blit(buf, x+2, y, Some(style.bold()))?;
|
||||
label2.blit(buf, x+3+label1.len()as u16, y, Some(style))?;
|
||||
Ok(label1.len() + label2.len() + 4)
|
||||
}
|
||||
|
||||
/// Key bindings for sampler device.
|
||||
pub const KEYMAP_SAMPLER: &'static [KeyBinding<Sampler>] = keymap!(Sampler {
|
||||
|
|
@ -105,7 +69,7 @@ pub const KEYMAP_SAMPLER: &'static [KeyBinding<Sampler>] = keymap!(Sampler {
|
|||
});
|
||||
|
||||
impl Sampler {
|
||||
pub fn from_edn <'e, E> (args: &[Edn<'e>]) -> Usually<JackDevice<E>> {
|
||||
pub fn from_edn <'e, E: Engine> (args: &[Edn<'e>]) -> Usually<JackDevice<E>> {
|
||||
let mut name = String::new();
|
||||
let mut dir = String::new();
|
||||
let mut samples = BTreeMap::new();
|
||||
|
|
@ -134,7 +98,7 @@ impl Sampler {
|
|||
Self::new(&name, Some(samples))
|
||||
}
|
||||
|
||||
pub fn new <E> (
|
||||
pub fn new <E: Engine> (
|
||||
name: &str, mapped: Option<BTreeMap<u7, Arc<RwLock<Sample>>>>
|
||||
) -> Usually<JackDevice<E>> {
|
||||
Jack::new(name)?
|
||||
|
|
|
|||
45
crates/tek_mixer/src/sampler_view.rs
Normal file
45
crates/tek_mixer/src/sampler_view.rs
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
use crate::*;
|
||||
|
||||
pub fn tui_render_sampler (sampler: &Sampler, to: &mut Tui) -> Perhaps<Rect> {
|
||||
let Rect { x, y, height, .. } = to.area();
|
||||
let style = Style::default().gray();
|
||||
let title = format!(" {} ({})", sampler.name, sampler.voices.read().unwrap().len());
|
||||
to.blit(&title, x+1, y, Some(style.white().bold().not_dim()))?;
|
||||
let mut width = title.len() + 2;
|
||||
let mut y1 = 1;
|
||||
let mut j = 0;
|
||||
for (note, sample) in sampler.mapped.iter()
|
||||
.map(|(note, sample)|(Some(note), sample))
|
||||
.chain(sampler.unmapped.iter().map(|sample|(None, sample)))
|
||||
{
|
||||
if y1 >= height {
|
||||
break
|
||||
}
|
||||
let active = j == sampler.cursor.0;
|
||||
width = width.max(
|
||||
draw_sample(to, x, y + y1, note, &*sample.read().unwrap(), active)?
|
||||
);
|
||||
y1 = y1 + 1;
|
||||
j = j + 1;
|
||||
}
|
||||
let height = ((2 + y1) as u16).min(height);
|
||||
Ok(Some(Rect { x, y, width: (width as u16).min(to.area().width), height }))
|
||||
}
|
||||
|
||||
fn draw_sample (
|
||||
to: &mut Tui, x: u16, y: u16, note: Option<&u7>, sample: &Sample, focus: bool
|
||||
) -> Usually<usize> {
|
||||
let style = if focus { Style::default().green() } else { Style::default() };
|
||||
if focus {
|
||||
to.blit(&"🬴", x+1, y, Some(style.bold()))?;
|
||||
}
|
||||
let label1 = format!("{:3} {:12}",
|
||||
note.map(|n|n.to_string()).unwrap_or(String::default()),
|
||||
sample.name);
|
||||
let label2 = format!("{:>6} {:>6} +0.0",
|
||||
sample.start,
|
||||
sample.end);
|
||||
to.blit(&label1, x+2, y, Some(style.bold()))?;
|
||||
to.blit(&label2, x+3+label1.len()as u16, y, Some(style))?;
|
||||
Ok(label1.len() + label2.len() + 4)
|
||||
}
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
use crate::*;
|
||||
use tek_core::Direction;
|
||||
|
||||
impl<'a> Render<Tui> for Track<Tui> {
|
||||
fn render (&self, to: &mut TuiOutput<'a>) -> Perhaps<Rect> {
|
||||
impl Render<Tui> for Track<Tui> {
|
||||
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
|
||||
TrackView {
|
||||
chain: Some(&self),
|
||||
direction: tek_core::Direction::Right,
|
||||
|
|
@ -24,8 +24,8 @@ impl<'a> Render<Tui> for Track<Tui> {
|
|||
}.render(to)
|
||||
}
|
||||
}
|
||||
pub struct TrackView<'a, T, U> {
|
||||
pub chain: Option<&'a Track<T, U>>,
|
||||
pub struct TrackView<'a, E: Engine> {
|
||||
pub chain: Option<&'a Track<E>>,
|
||||
pub direction: Direction,
|
||||
pub focused: bool,
|
||||
pub entered: bool,
|
||||
|
|
|
|||
11
crates/tek_proc/Cargo.toml
Normal file
11
crates/tek_proc/Cargo.toml
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
[package]
|
||||
name = "tek_proc"
|
||||
edition = "2021"
|
||||
version = "0.1.0"
|
||||
|
||||
[lib]
|
||||
proc-macro = true
|
||||
|
||||
[dependencies]
|
||||
syn = { version = "2.0", features = ["full"] }
|
||||
quote = "1.0"
|
||||
18
crates/tek_proc/src/lib.rs
Normal file
18
crates/tek_proc/src/lib.rs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
use proc_macro::TokenStream;
|
||||
use syn::{parse_macro_input, Attribute, Meta};
|
||||
|
||||
#[proc_macro_attribute]
|
||||
pub fn render (attr: TokenStream, item: TokenStream) -> TokenStream {
|
||||
println!("attr: \"{attr}\"");
|
||||
println!("item: \"{item}\"");
|
||||
let input = syn::parse_macro_input!(attr as Meta);
|
||||
panic!("attr: \"{input:?}\"");
|
||||
item
|
||||
}
|
||||
|
||||
#[proc_macro_attribute]
|
||||
pub fn handle (attr: TokenStream, item: TokenStream) -> TokenStream {
|
||||
println!("attr: \"{attr}\"");
|
||||
println!("item: \"{item}\"");
|
||||
item
|
||||
}
|
||||
|
|
@ -5,6 +5,7 @@ version = "0.1.0"
|
|||
|
||||
[dependencies]
|
||||
tek_core = { path = "../tek_core" }
|
||||
tek_proc = { path = "../tek_proc" }
|
||||
|
||||
[lib]
|
||||
path = "src/lib.rs"
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@ impl ArrangerViewMode {
|
|||
}
|
||||
/// Render arranger to terminal
|
||||
impl Render<Tui> for Arranger<Tui> {
|
||||
fn render (&'a self, to: &'a mut TuiOutput<'a>) -> Perhaps<Rect> {
|
||||
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
|
||||
let area = (|to|match self.mode {
|
||||
ArrangerViewMode::Horizontal =>
|
||||
super::arranger_view_h::draw(self, to),
|
||||
|
|
@ -111,18 +111,19 @@ impl Render<Tui> for Arranger<Tui> {
|
|||
super::arranger_view_v::draw_compact_2(self, to),
|
||||
ArrangerViewMode::VerticalExpanded =>
|
||||
super::arranger_view_v::draw_expanded(self, to),
|
||||
})(&mut to.area(Rect {
|
||||
x: to.area.x + 1,
|
||||
width: to.area.width - 2,
|
||||
y: to.area.y + 1,
|
||||
height: to.area.height - 2
|
||||
}))?.unwrap();
|
||||
Lozenge(Style::default().fg(Nord::BG2)).draw(&mut to.area(Rect {
|
||||
x: area.x.saturating_sub(1),
|
||||
width: area.width + 2,
|
||||
y: area.y.saturating_sub(1),
|
||||
height: area.height + 2,
|
||||
}))
|
||||
})(&mut to.alter_area(|x, y, w, h|(
|
||||
x + 1,
|
||||
y + 1,
|
||||
w.saturating_sub(2),
|
||||
h.saturating_sub(2),
|
||||
)))?.unwrap();
|
||||
Lozenge(Style::default().fg(Nord::BG2))
|
||||
.draw(&mut to.alter_area(|x, y, w, h|(
|
||||
x.saturating_sub(1),
|
||||
y.saturating_sub(1),
|
||||
w + 2,
|
||||
h + 2,
|
||||
)))
|
||||
}
|
||||
}
|
||||
impl Focusable<Tui> for Arranger<Tui> {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use crate::*;
|
||||
impl<'a> Arranger<TuiOutput<'a>, Rect> {
|
||||
impl<'a> Arranger<Tui> {
|
||||
pub fn rename_selected (&mut self) {
|
||||
self.modal = Some(Box::new(ArrangerRenameModal::new(
|
||||
self.selected,
|
||||
|
|
@ -31,16 +31,17 @@ impl ArrangerRenameModal {
|
|||
}
|
||||
}
|
||||
}
|
||||
impl<'a> Render<TuiOutput<'a>, Rect> for ArrangerRenameModal {
|
||||
fn render (&self, to: &mut TuiOutput<'a>) -> Perhaps<Rect> {
|
||||
let y = to.area.y + to.area.height / 2;
|
||||
impl Render<Tui> for ArrangerRenameModal {
|
||||
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
|
||||
let area = to.area();
|
||||
let y = area.y + area.height / 2;
|
||||
let bg_area = Rect {
|
||||
x: 1,
|
||||
y: y - 1,
|
||||
width: to.area.width - 2,
|
||||
width: area.width - 2,
|
||||
height: 3
|
||||
};
|
||||
fill_bg(to.buffer, bg_area, Nord::BG0);
|
||||
to.fill_bg(bg_area, Nord::BG0);
|
||||
Lozenge(Style::default().bold().white().dim()).draw(to.buffer, bg_area)?;
|
||||
let label = match self.target {
|
||||
ArrangerFocus::Mix => "Rename project:",
|
||||
|
|
@ -49,50 +50,52 @@ impl<'a> Render<TuiOutput<'a>, Rect> for ArrangerRenameModal {
|
|||
ArrangerFocus::Clip(_, _) => "Rename clip:",
|
||||
};
|
||||
let style = Some(Style::default().not_bold().white().not_dim());
|
||||
label.blit(to.buffer, to.area.x + 3, y, style)?;
|
||||
to.blit(&label, area.x + 3, y, style)?;
|
||||
let style = Some(Style::default().bold().white().not_dim());
|
||||
self.value.blit(to.buffer, to.area.x + 3 + label.len() as u16 + 1, y, style)?;
|
||||
to.blit(&self.value, area.x + 3 + label.len() as u16 + 1, y, style)?;
|
||||
let style = Some(Style::default().bold().white().not_dim().reversed());
|
||||
"▂".blit(to.buffer, to.area.x + 3 + label.len() as u16 + 1 + self.cursor as u16, y, style)?;
|
||||
Ok(Some(to.area))
|
||||
to.blit(&"▂", area.x + 3 + label.len() as u16 + 1 + self.cursor as u16, y, style)?;
|
||||
Ok(Some(area))
|
||||
}
|
||||
}
|
||||
handle!(ArrangerRenameModal |self, e| {
|
||||
match e {
|
||||
AppEvent::Input(Event::Key(k)) => {
|
||||
match k.code {
|
||||
KeyCode::Esc => {
|
||||
self.exit();
|
||||
},
|
||||
KeyCode::Enter => {
|
||||
*self.result.write().unwrap() = self.value.clone();
|
||||
self.exit();
|
||||
},
|
||||
KeyCode::Left => {
|
||||
self.cursor = self.cursor.saturating_sub(1);
|
||||
},
|
||||
KeyCode::Right => {
|
||||
self.cursor = self.value.len().min(self.cursor + 1)
|
||||
},
|
||||
KeyCode::Backspace => {
|
||||
let last = self.value.len().saturating_sub(1);
|
||||
self.value = format!("{}{}",
|
||||
&self.value[0..self.cursor.min(last)],
|
||||
&self.value[self.cursor.min(last)..last]
|
||||
);
|
||||
self.cursor = self.cursor.saturating_sub(1)
|
||||
impl Handle<Tui> for TransportQuantize {
|
||||
fn handle (&mut self, from: &Tui) -> Perhaps<bool> {
|
||||
match e {
|
||||
AppEvent::Input(Event::Key(k)) => {
|
||||
match k.code {
|
||||
KeyCode::Esc => {
|
||||
self.exit();
|
||||
},
|
||||
KeyCode::Enter => {
|
||||
*self.result.write().unwrap() = self.value.clone();
|
||||
self.exit();
|
||||
},
|
||||
KeyCode::Left => {
|
||||
self.cursor = self.cursor.saturating_sub(1);
|
||||
},
|
||||
KeyCode::Right => {
|
||||
self.cursor = self.value.len().min(self.cursor + 1)
|
||||
},
|
||||
KeyCode::Backspace => {
|
||||
let last = self.value.len().saturating_sub(1);
|
||||
self.value = format!("{}{}",
|
||||
&self.value[0..self.cursor.min(last)],
|
||||
&self.value[self.cursor.min(last)..last]
|
||||
);
|
||||
self.cursor = self.cursor.saturating_sub(1)
|
||||
}
|
||||
KeyCode::Char(c) => {
|
||||
self.value.insert(self.cursor, c);
|
||||
self.cursor = self.value.len().min(self.cursor + 1)
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
KeyCode::Char(c) => {
|
||||
self.value.insert(self.cursor, c);
|
||||
self.cursor = self.value.len().min(self.cursor + 1)
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
Ok(true)
|
||||
},
|
||||
_ => Ok(false),
|
||||
Ok(true)
|
||||
},
|
||||
_ => Ok(false),
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
impl Exit for ArrangerRenameModal {
|
||||
fn exited (&self) -> bool {
|
||||
self.done
|
||||
|
|
|
|||
|
|
@ -1,9 +1,7 @@
|
|||
use crate::*;
|
||||
|
||||
pub fn draw <'a> (
|
||||
state: &Arranger<TuiOutput<'a>, Rect>, to: &mut TuiOutput<'a>
|
||||
) -> Perhaps<Rect> {
|
||||
let mut area = to.area;
|
||||
pub fn draw (state: &Arranger<Tui>, to: &mut Tui) -> Perhaps<Rect> {
|
||||
let mut area = to.area();
|
||||
area.height = area.height.min((2 + state.tracks.len() * 2) as u16);
|
||||
let tracks = state.tracks.as_slice();
|
||||
Layered::new()
|
||||
|
|
@ -21,10 +19,10 @@ pub fn draw <'a> (
|
|||
|
||||
struct TrackNameColumn<'a>(&'a [Sequencer], ArrangerFocus);
|
||||
|
||||
impl<'a> Render<TuiOutput<'a>, Rect> for TrackNameColumn<'a> {
|
||||
fn render (&self, to: &mut TuiOutput<'a>) -> Perhaps<Rect> {
|
||||
impl<'a> Render<Tui> for TrackNameColumn<'a> {
|
||||
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
|
||||
let Self(tracks, selected) = self;
|
||||
let mut area = to.area;
|
||||
let mut area = to.area();
|
||||
let yellow = Some(Style::default().yellow().bold().not_dim());
|
||||
let white = Some(Style::default().white().bold().not_dim());
|
||||
area.width = 3 + 5.max(track_name_max_len(tracks)) as u16;
|
||||
|
|
@ -48,10 +46,10 @@ impl<'a> Render<TuiOutput<'a>, Rect> for TrackNameColumn<'a> {
|
|||
|
||||
struct TrackMonitorColumn<'a>(&'a [Sequencer]);
|
||||
|
||||
impl<'a> Render<TuiOutput<'a>, Rect> for TrackMonitorColumn<'a> {
|
||||
fn render (&self, to: &mut TuiOutput<'a>) -> Perhaps<Rect> {
|
||||
impl<'a> Render<Tui> for TrackMonitorColumn<'a> {
|
||||
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
|
||||
let Self(tracks) = self;
|
||||
let mut area = to.area;
|
||||
let mut area = to.area();
|
||||
let on = Some(Style::default().not_dim().green().bold());
|
||||
let off = Some(DIM);
|
||||
area.x += 1;
|
||||
|
|
@ -76,10 +74,10 @@ impl<'a> Render<TuiOutput<'a>, Rect> for TrackMonitorColumn<'a> {
|
|||
|
||||
struct TrackRecordColumn<'a>(&'a [Sequencer]);
|
||||
|
||||
impl<'a> Render<TuiOutput<'a>, Rect> for TrackRecordColumn<'a> {
|
||||
fn render (&self, to: &mut TuiOutput<'a>) -> Perhaps<Rect> {
|
||||
impl<'a> Render<Tui> for TrackRecordColumn<'a> {
|
||||
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
|
||||
let Self(tracks) = self;
|
||||
let mut area = to.area;
|
||||
let mut area = to.area();
|
||||
let on = Some(Style::default().not_dim().red().bold());
|
||||
let off = Some(Style::default().dim());
|
||||
area.x += 1;
|
||||
|
|
@ -104,10 +102,10 @@ impl<'a> Render<TuiOutput<'a>, Rect> for TrackRecordColumn<'a> {
|
|||
|
||||
struct TrackOverdubColumn<'a>(&'a [Sequencer]);
|
||||
|
||||
impl<'a> Render<TuiOutput<'a>, Rect> for TrackOverdubColumn<'a> {
|
||||
fn render (&self, to: &mut TuiOutput<'a>) -> Perhaps<Rect> {
|
||||
impl<'a> Render<Tui> for TrackOverdubColumn<'a> {
|
||||
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
|
||||
let Self(tracks) = self;
|
||||
let mut area = to.area;
|
||||
let mut area = to.area();
|
||||
let on = Some(Style::default().not_dim().yellow().bold());
|
||||
let off = Some(Style::default().dim());
|
||||
area.x = area.x + 1;
|
||||
|
|
@ -135,10 +133,10 @@ impl<'a> Render<TuiOutput<'a>, Rect> for TrackOverdubColumn<'a> {
|
|||
|
||||
struct TrackEraseColumn<'a>(&'a [Sequencer]);
|
||||
|
||||
impl<'a> Render<TuiOutput<'a>, Rect> for TrackEraseColumn<'a> {
|
||||
fn render (&self, to: &mut TuiOutput<'a>) -> Perhaps<Rect> {
|
||||
impl<'a> Render<Tui> for TrackEraseColumn<'a> {
|
||||
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
|
||||
let Self(tracks) = self;
|
||||
let mut area = to.area;
|
||||
let mut area = to.area();
|
||||
let off = Some(Style::default().dim());
|
||||
area.x = area.x + 1;
|
||||
for y in 0..area.height {
|
||||
|
|
@ -147,7 +145,7 @@ impl<'a> Render<TuiOutput<'a>, Rect> for TrackEraseColumn<'a> {
|
|||
} else if y % 2 == 0 {
|
||||
let index = (y as usize - 2) / 2;
|
||||
if let Some(_) = tracks.get(index) {
|
||||
" DEL ".blit(to.buffer, area.x, area.y + y, off)?;
|
||||
to.blit(&" DEL ", area.x, area.y + y, off)?;
|
||||
} else {
|
||||
area.height = y;
|
||||
break
|
||||
|
|
@ -161,10 +159,10 @@ impl<'a> Render<TuiOutput<'a>, Rect> for TrackEraseColumn<'a> {
|
|||
|
||||
struct TrackGainColumn<'a>(&'a [Sequencer]);
|
||||
|
||||
impl<'a> Render<TuiOutput<'a>, Rect> for TrackGainColumn<'a> {
|
||||
fn render (&self, to: &mut TuiOutput<'a>) -> Perhaps<Rect> {
|
||||
impl<'a> Render<Tui> for TrackGainColumn<'a> {
|
||||
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
|
||||
let Self(tracks) = self;
|
||||
let mut area = to.area;
|
||||
let mut area = to.area();
|
||||
let off = Some(Style::default().dim());
|
||||
area.x = area.x + 1;
|
||||
for y in 0..area.height {
|
||||
|
|
@ -173,7 +171,7 @@ impl<'a> Render<TuiOutput<'a>, Rect> for TrackGainColumn<'a> {
|
|||
} else if y % 2 == 0 {
|
||||
let index = (y as usize - 2) / 2;
|
||||
if let Some(_) = tracks.get(index) {
|
||||
" +0.0 ".blit(to.buffer, area.x, area.y + y, off)?;
|
||||
to.blit(&" +0.0 ", area.x, area.y + y, off)?;
|
||||
} else {
|
||||
area.height = y;
|
||||
break
|
||||
|
|
@ -187,10 +185,10 @@ impl<'a> Render<TuiOutput<'a>, Rect> for TrackGainColumn<'a> {
|
|||
|
||||
struct TrackScenesColumn<'a>(&'a [Sequencer], &'a [Scene], ArrangerFocus);
|
||||
|
||||
impl<'a> Render<TuiOutput<'a>, Rect> for TrackScenesColumn<'a> {
|
||||
fn render (&self, to: &mut TuiOutput<'a>) -> Perhaps<Rect> {
|
||||
impl<'a> Render<Tui> for TrackScenesColumn<'a> {
|
||||
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
|
||||
let Self(tracks, scenes, selected) = self;
|
||||
let area = to.area;
|
||||
let area = to.area();
|
||||
let mut x2 = 0;
|
||||
let Rect { x, y, height, .. } = area;
|
||||
for (scene_index, scene) in scenes.iter().enumerate() {
|
||||
|
|
@ -201,11 +199,11 @@ impl<'a> Render<TuiOutput<'a>, Rect> for TrackScenesColumn<'a> {
|
|||
Style::default().dim()
|
||||
});
|
||||
for y in y+1..y+height {
|
||||
"│".blit(to.buffer, x + x2, y, sep)?;
|
||||
to.blit(&"│", x + x2, y, sep)?;
|
||||
}
|
||||
let name = scene.name.read().unwrap();
|
||||
let mut x3 = name.len() as u16;
|
||||
name.blit(to.buffer, x + x2, y, sep)?;
|
||||
to.blit(&name, x + x2, y, sep)?;
|
||||
for (i, clip) in scene.clips.iter().enumerate() {
|
||||
let active_track = selected.track() == Some(i);
|
||||
if let Some(clip) = clip {
|
||||
|
|
@ -214,7 +212,7 @@ impl<'a> Render<TuiOutput<'a>, Rect> for TrackScenesColumn<'a> {
|
|||
Some(phrase) => &format!("{}", phrase.read().unwrap().name.read().unwrap()),
|
||||
None => "...."
|
||||
};
|
||||
label.blit(to.buffer, x + x2, y2, Some(if active_track && active_scene {
|
||||
to.blit(&label, x + x2, y2, Some(if active_track && active_scene {
|
||||
Style::default().not_dim().yellow().bold()
|
||||
} else {
|
||||
Style::default().not_dim()
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
use crate::*;
|
||||
|
||||
handle!(Sequencer |self, e| handle_keymap(self, e, KEYMAP_SEQUENCER));
|
||||
impl Handle<Tui> for TransportQuantize {
|
||||
fn handle (&mut self, from: &Tui) -> Perhaps<bool> {
|
||||
handle_keymap(self, e, KEYMAP_SEQUENCER)
|
||||
}
|
||||
}
|
||||
|
||||
/// Key bindings for phrase editor.
|
||||
pub const KEYMAP_SEQUENCER: &'static [KeyBinding<Sequencer>] = keymap!(Sequencer {
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
use crate::*;
|
||||
|
||||
impl<'a> Render<TuiOutput<'a>, Rect> for Sequencer {
|
||||
fn render (&self, to: &mut TuiOutput<'a>) -> Perhaps<Rect> {
|
||||
impl<'a> Render<Tui> for Sequencer {
|
||||
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
|
||||
self.horizontal_draw(to)?;
|
||||
if self.focused && self.entered {
|
||||
Corners(Style::default().green().not_dim()).draw(to.buffer, to.area)?;
|
||||
Corners(Style::default().green().not_dim()).draw(to)?;
|
||||
}
|
||||
Ok(Some(to.area))
|
||||
Ok(Some(to.area()))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 }))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -142,33 +142,33 @@ impl TransportToolbar {
|
|||
self.timebase.frame_to_usec(self.clock.frame as f64) as usize
|
||||
}
|
||||
}
|
||||
impl<'a> Focus<5, TuiOutput<'a>, Rect> for TransportToolbar {
|
||||
impl Focus<5, Tui> for TransportToolbar {
|
||||
fn focus (&self) -> usize {
|
||||
self.focus
|
||||
}
|
||||
fn focus_mut (&mut self) -> &mut usize {
|
||||
&mut self.focus
|
||||
}
|
||||
fn focusable (&self) -> [&dyn Focusable<TuiOutput<'a>, Rect>;5] {
|
||||
fn focusable (&self) -> [&dyn Focusable<Tui>;5] {
|
||||
[
|
||||
&self.playing as &dyn Focusable<TuiOutput<'a>, Rect>,
|
||||
&self.bpm as &dyn Focusable<TuiOutput<'a>, Rect>,
|
||||
&self.quant as &dyn Focusable<TuiOutput<'a>, Rect>,
|
||||
&self.sync as &dyn Focusable<TuiOutput<'a>, Rect>,
|
||||
&self.clock as &dyn Focusable<TuiOutput<'a>, Rect>,
|
||||
&self.playing as &dyn Focusable<Tui>,
|
||||
&self.bpm as &dyn Focusable<Tui>,
|
||||
&self.quant as &dyn Focusable<Tui>,
|
||||
&self.sync as &dyn Focusable<Tui>,
|
||||
&self.clock as &dyn Focusable<Tui>,
|
||||
]
|
||||
}
|
||||
fn focusable_mut (&mut self) -> [&mut dyn Focusable<TuiOutput<'a>, Rect>;5] {
|
||||
fn focusable_mut (&mut self) -> [&mut dyn Focusable<Tui>;5] {
|
||||
[
|
||||
&mut self.playing as &mut dyn Focusable<TuiOutput<'a>, Rect>,
|
||||
&mut self.bpm as &mut dyn Focusable<TuiOutput<'a>, Rect>,
|
||||
&mut self.quant as &mut dyn Focusable<TuiOutput<'a>, Rect>,
|
||||
&mut self.sync as &mut dyn Focusable<TuiOutput<'a>, Rect>,
|
||||
&mut self.clock as &mut dyn Focusable<TuiOutput<'a>, Rect>,
|
||||
&mut self.playing as &mut dyn Focusable<Tui>,
|
||||
&mut self.bpm as &mut dyn Focusable<Tui>,
|
||||
&mut self.quant as &mut dyn Focusable<Tui>,
|
||||
&mut self.sync as &mut dyn Focusable<Tui>,
|
||||
&mut self.clock as &mut dyn Focusable<Tui>,
|
||||
]
|
||||
}
|
||||
}
|
||||
impl<'a> Focusable<TuiOutput<'a>, Rect> for TransportToolbar {
|
||||
impl Focusable<Tui> for TransportToolbar {
|
||||
fn is_focused (&self) -> bool {
|
||||
self.focused
|
||||
}
|
||||
|
|
@ -185,7 +185,7 @@ pub struct TransportPlayPauseButton {
|
|||
pub value: Option<TransportState>,
|
||||
pub focused: bool
|
||||
}
|
||||
impl<'a> Focusable<TuiOutput<'a>, Rect> for TransportPlayPauseButton {
|
||||
impl Focusable<Tui> for TransportPlayPauseButton {
|
||||
fn is_focused (&self) -> bool {
|
||||
self.focused
|
||||
}
|
||||
|
|
@ -198,7 +198,7 @@ pub struct TransportBPM {
|
|||
pub value: f64,
|
||||
pub focused: bool
|
||||
}
|
||||
impl<'a> Focusable<TuiOutput<'a>, Rect> for TransportBPM {
|
||||
impl Focusable<Tui> for TransportBPM {
|
||||
fn is_focused (&self) -> bool {
|
||||
self.focused
|
||||
}
|
||||
|
|
@ -211,7 +211,7 @@ pub struct TransportQuantize {
|
|||
pub value: usize,
|
||||
pub focused: bool
|
||||
}
|
||||
impl<'a> Focusable<TuiOutput<'a>, Rect> for TransportQuantize {
|
||||
impl Focusable<Tui> for TransportQuantize {
|
||||
fn is_focused (&self) -> bool {
|
||||
self.focused
|
||||
}
|
||||
|
|
@ -224,7 +224,7 @@ pub struct TransportSync {
|
|||
pub value: usize,
|
||||
pub focused: bool
|
||||
}
|
||||
impl<'a> Focusable<TuiOutput<'a>, Rect> for TransportSync {
|
||||
impl Focusable<Tui> for TransportSync {
|
||||
fn is_focused (&self) -> bool {
|
||||
self.focused
|
||||
}
|
||||
|
|
@ -240,7 +240,7 @@ pub struct TransportClock {
|
|||
pub usecs: usize,
|
||||
pub focused: bool,
|
||||
}
|
||||
impl<'a> Focusable<TuiOutput<'a>, Rect> for TransportClock {
|
||||
impl Focusable<Tui> for TransportClock {
|
||||
fn is_focused (&self) -> bool {
|
||||
self.focused
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use crate::*;
|
||||
|
||||
impl Handle<Tui, bool> for TransportToolbar {
|
||||
impl Handle<Tui> for TransportToolbar {
|
||||
fn handle (&mut self, from: &Tui) -> Perhaps<bool> {
|
||||
Ok(
|
||||
from.key(KeyCode::Right).does(||self.focus_next())?
|
||||
|
|
@ -12,38 +12,55 @@ impl Handle<Tui, bool> for TransportToolbar {
|
|||
}
|
||||
}
|
||||
|
||||
handle!(TransportPlayPauseButton |self, _e| Ok(false));
|
||||
impl Handle<Tui> for TransportPlayPauseButton {
|
||||
fn handle (&mut self, from: &Tui) -> Perhaps<bool> {
|
||||
Ok(false)
|
||||
}
|
||||
}
|
||||
|
||||
handle!(TransportBPM |self, _e| {
|
||||
//TransportFocus::BPM => {
|
||||
//transport.timebase.bpm.fetch_add(1.0, Ordering::Relaxed);
|
||||
//},
|
||||
//TransportFocus::BPM => {
|
||||
//transport.timebase.bpm.fetch_sub(1.0, Ordering::Relaxed);
|
||||
//},
|
||||
Ok(false)
|
||||
});
|
||||
impl Handle<Tui> for TransportBPM {
|
||||
fn handle (&mut self, from: &Tui) -> Perhaps<bool> {
|
||||
//TransportFocus::BPM => {
|
||||
//transport.timebase.bpm.fetch_add(1.0, Ordering::Relaxed);
|
||||
//},
|
||||
//TransportFocus::BPM => {
|
||||
//transport.timebase.bpm.fetch_sub(1.0, Ordering::Relaxed);
|
||||
//},
|
||||
Ok(false)
|
||||
}
|
||||
}
|
||||
|
||||
handle!(TransportQuantize |self, _e| {
|
||||
//TransportFocus::Quant => {
|
||||
//transport.quant.value = next_note_length(transport.quant)
|
||||
//},
|
||||
//TransportFocus::Quant => {
|
||||
//transport.quant.value = prev_note_length(transport.quant);
|
||||
//},
|
||||
Ok(false)
|
||||
});
|
||||
impl Handle<Tui> for TransportQuantize {
|
||||
fn handle (&mut self, from: &Tui) -> Perhaps<bool> {
|
||||
//TransportFocus::Quant => {
|
||||
//transport.quant.value = next_note_length(transport.quant)
|
||||
//},
|
||||
//TransportFocus::Quant => {
|
||||
//transport.quant.value = prev_note_length(transport.quant);
|
||||
//},
|
||||
Ok(false)
|
||||
}
|
||||
}
|
||||
|
||||
handle!(TransportSync |self, _e| {
|
||||
//TransportFocus::Sync => {
|
||||
//transport.sync.value = next_note_length(transport.sync)
|
||||
//},
|
||||
//TransportFocus::Sync => {
|
||||
//transport.sync.value = prev_note_length(transport.sync);
|
||||
//},
|
||||
Ok(false)
|
||||
});
|
||||
impl Handle<Tui> for TransportSync {
|
||||
fn handle (&mut self, from: &Tui) -> Perhaps<bool> {
|
||||
//TransportFocus::Sync => {
|
||||
//transport.sync.value = next_note_length(transport.sync)
|
||||
//},
|
||||
//TransportFocus::Sync => {
|
||||
//transport.sync.value = prev_note_length(transport.sync);
|
||||
//},
|
||||
}
|
||||
}
|
||||
|
||||
handle!(TransportClock |self, _e| {
|
||||
Ok(false)
|
||||
});
|
||||
impl Handle<Tui> for TransportClock {
|
||||
fn handle (&mut self, from: &Tui) -> Perhaps<bool> {
|
||||
//TransportFocus::Sync => {
|
||||
//transport.sync.value = next_note_length(transport.sync)
|
||||
//},
|
||||
//TransportFocus::Sync => {
|
||||
//transport.sync.value = prev_note_length(transport.sync);
|
||||
//},
|
||||
Ok(false)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@ use crate::*;
|
|||
|
||||
const CORNERS: Corners = Corners(NOT_DIM_GREEN);
|
||||
|
||||
impl<'a> Render<TuiOutput<'a>, Rect> for TransportToolbar {
|
||||
fn render (&self, target: &mut TuiOutput<'a>) -> Perhaps<Rect> {
|
||||
let mut area = target.area;
|
||||
impl Render<Tui> for TransportToolbar {
|
||||
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
|
||||
let mut area = to.area();
|
||||
area.height = 2;
|
||||
let area = Split::right()
|
||||
.add_ref(&self.playing)
|
||||
|
|
@ -12,7 +12,7 @@ impl<'a> Render<TuiOutput<'a>, Rect> for TransportToolbar {
|
|||
.add_ref(&self.quant)
|
||||
.add_ref(&self.sync)
|
||||
.add_ref(&self.clock)
|
||||
.render(target)?;
|
||||
.render(to)?;
|
||||
//if self.is_focused() {
|
||||
//fill_bg(buf, area, COLOR_BG0);
|
||||
//CORNERS_DIM.draw(buf, area)?;
|
||||
|
|
@ -21,9 +21,10 @@ impl<'a> Render<TuiOutput<'a>, Rect> for TransportToolbar {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> Render<TuiOutput<'a>, Rect> for TransportPlayPauseButton {
|
||||
fn render (&self, to: &mut TuiOutput<'a>) -> Perhaps<Rect> {
|
||||
let Rect { x, y, .. } = to.area;
|
||||
impl Render<Tui> for TransportPlayPauseButton {
|
||||
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
|
||||
let area = to.area();
|
||||
let Rect { x, y, .. } = area;
|
||||
let Self { value, focused } = &self;
|
||||
let style = Some(match value {
|
||||
Some(TransportState::Stopped) => GRAY_DIM.bold(),
|
||||
|
|
@ -37,37 +38,40 @@ impl<'a> Render<TuiOutput<'a>, Rect> for TransportPlayPauseButton {
|
|||
Some(TransportState::Stopped) => "⏹ STOPPED",
|
||||
_ => unreachable!(),
|
||||
};
|
||||
let mut area = label.blit(to.buffer, x + 1, y, style)?.unwrap();
|
||||
let mut area = to.blit(&label, x + 1, y, style)?.unwrap();
|
||||
area.width = area.width + 1;
|
||||
area.height = area.height + 1;
|
||||
if *focused {
|
||||
let area = Rect { x: area.x - 1, width: area.width - 1, ..area };
|
||||
CORNERS.draw(to.buffer, to.area)?;
|
||||
fill_bg(to.buffer, to.area, COLOR_BG1);
|
||||
CORNERS.draw(to)?;
|
||||
to.fill_bg(area, COLOR_BG1);
|
||||
}
|
||||
Ok(Some(area))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Render<TuiOutput<'a>, Rect> for TransportBPM {
|
||||
fn render (&self, to: &mut TuiOutput<'a>) -> Perhaps<Rect> {
|
||||
let Rect { x, y, .. } = to.area;
|
||||
impl Render<Tui> for TransportBPM {
|
||||
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
|
||||
let area = to.area();
|
||||
let Rect { x, y, .. } = area;
|
||||
let Self { value, focused } = self;
|
||||
"BPM".blit(to.buffer, x, y, Some(NOT_DIM))?;
|
||||
let width = format!("{}.{:03}", value, (value * 1000.0) % 1000.0)
|
||||
.blit(to.buffer, x, y + 1, Some(NOT_DIM_BOLD))?.width;
|
||||
to.blit(&"BPM", x, y, Some(NOT_DIM))?;
|
||||
let bpm = format!("{}.{:03}", value, (value * 1000.0) % 1000.0);
|
||||
to.blit(&bpm, x, y + 1, Some(NOT_DIM_BOLD))?;
|
||||
let width = bpm.len() as u16;
|
||||
let area = Rect { x, y, width: (width + 2).max(10), height: 2 };
|
||||
if *focused {
|
||||
let area = Rect { x: area.x - 1, width: area.width - 1, ..area };
|
||||
CORNERS.draw(to.buffer, area)?;
|
||||
fill_bg(to.buffer, area, COLOR_BG1);
|
||||
CORNERS.draw(to)?;
|
||||
to.fill_bg(area, COLOR_BG1);
|
||||
}
|
||||
Ok(Some(area))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Render<TuiOutput<'a>, Rect> for TransportQuantize {
|
||||
fn render (&self, to: &mut TuiOutput<'a>) -> Perhaps<Rect> {
|
||||
impl Render<Tui> for TransportQuantize {
|
||||
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
|
||||
let area = to.area();
|
||||
let Rect { x, y, .. } = to.area;
|
||||
let Self { value, focused } = self;
|
||||
"QUANT".blit(to.buffer, x, y, Some(NOT_DIM))?;
|
||||
|
|
@ -75,15 +79,16 @@ impl<'a> Render<TuiOutput<'a>, Rect> for TransportQuantize {
|
|||
let area = Rect { x, y, width: (width + 2).max(10), height: 2 };
|
||||
if *focused {
|
||||
let area = Rect { x: area.x - 1, width: area.width - 1, ..area };
|
||||
CORNERS.draw(to.buffer, area)?;
|
||||
fill_bg(to.buffer, area, COLOR_BG1);
|
||||
CORNERS.draw(to)?;
|
||||
to.fill_bg(area, COLOR_BG1);
|
||||
}
|
||||
Ok(Some(area))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Render<TuiOutput<'a>, Rect> for TransportSync {
|
||||
fn render (&self, to: &mut TuiOutput<'a>) -> Perhaps<Rect> {
|
||||
impl Render<Tui> for TransportSync {
|
||||
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
|
||||
let area = to.area();
|
||||
let Rect { x, y, .. } = to.area;
|
||||
let Self { value, focused } = self;
|
||||
"SYNC".blit(to.buffer, x, y, Some(NOT_DIM))?;
|
||||
|
|
@ -91,31 +96,31 @@ impl<'a> Render<TuiOutput<'a>, Rect> for TransportSync {
|
|||
let area = Rect { x, y, width: (width + 2).max(10), height: 2 };
|
||||
if *focused {
|
||||
let area = Rect { x: area.x - 1, width: area.width - 1, ..area };
|
||||
CORNERS.draw(to.buffer, area)?;
|
||||
fill_bg(to.buffer, area, COLOR_BG1);
|
||||
CORNERS.draw(to)?;
|
||||
to.fill_bg(area, COLOR_BG1);
|
||||
}
|
||||
Ok(Some(area))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Render<TuiOutput<'a>, Rect> for TransportClock {
|
||||
fn render (&self, to: &mut TuiOutput<'a>) -> Perhaps<Rect> {
|
||||
let Rect { x, y, width, .. } = to.area;
|
||||
impl Render<Tui> for TransportClock {
|
||||
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
|
||||
let Rect { x, y, width, .. } = to.area();
|
||||
let Self { frame, pulse, ppq, usecs, focused } = self;
|
||||
let (beats, pulses) = if *ppq > 0 { (pulse / ppq, pulse % ppq) } else { (0, 0) };
|
||||
let (bars, beats) = ((beats / 4) + 1, (beats % 4) + 1);
|
||||
let (seconds, msecs) = (usecs / 1000000, usecs / 1000 % 1000);
|
||||
let (minutes, seconds) = (seconds / 60, seconds % 60);
|
||||
let timer = format!("{bars}.{beats}.{pulses:02}");
|
||||
timer.blit(to.buffer, x + width - timer.len() as u16 - 1, y + 0, Some(NOT_DIM))?;
|
||||
to.blit(&timer, x + width - timer.len() as u16 - 1, y + 0, Some(NOT_DIM))?;
|
||||
let timer = format!("{minutes}:{seconds:02}:{msecs:03}");
|
||||
timer.blit(to.buffer, x + width - timer.len() as u16 - 1, y + 1, Some(NOT_DIM))?;
|
||||
let mut area = to.area;
|
||||
to.blit(&timer, x + width - timer.len() as u16 - 1, y + 1, Some(NOT_DIM))?;
|
||||
let mut area = to.area();
|
||||
area.width = area.width + 1;
|
||||
if *focused {
|
||||
let area = Rect { x: area.x - 1, ..area };
|
||||
CORNERS.draw(to.buffer, area)?;
|
||||
fill_bg(to.buffer, area, COLOR_BG1);
|
||||
CORNERS.draw(to)?;
|
||||
to.fill_bg(area, COLOR_BG1);
|
||||
}
|
||||
Ok(Some(area))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue