lanes and grids

This commit is contained in:
🪞👃🪞 2024-06-12 18:38:16 +03:00
parent 788dc1ccde
commit ac865824cc
12 changed files with 213 additions and 112 deletions

View file

@ -74,7 +74,7 @@ pub fn run (device: impl Device + Send + Sync + 'static) -> Result<(), Box<dyn E
terminal.draw(|frame|{
let area = frame.size();
let buffer = frame.buffer_mut();
device.lock().unwrap().render(buffer, area)
device.lock().unwrap().render(buffer, area).expect("Failed to render content.");
}).expect("Failed to render frame");
if exited.fetch_and(true, Ordering::Relaxed) {
break
@ -90,15 +90,19 @@ pub fn run (device: impl Device + Send + Sync + 'static) -> Result<(), Box<dyn E
}
pub trait Device: Send + Sync {
fn handle (&mut self, _event: &EngineEvent) -> Result<(), Box<dyn Error>> { Ok(()) }
fn render (&self, _buffer: &mut Buffer, _area: Rect) {}
fn handle (&mut self, _event: &EngineEvent) -> Usually<()> {
Ok(())
}
fn render (&self, _buffer: &mut Buffer, _area: Rect) -> Usually<(u16, u16)> {
Ok((0,0))
}
fn process (&mut self, _client: Client, _scope: ProcessScope) {}
}
pub struct DynamicDevice<T> {
pub state: Mutex<T>,
pub render: Mutex<Box<dyn FnMut(&T, &mut Buffer, Rect) + Send>>,
pub handle: Mutex<Box<dyn FnMut(&mut T, &EngineEvent)->Result<(), Box<dyn Error>> + Send>>,
pub render: Mutex<Box<dyn FnMut(&T, &mut Buffer, Rect)->Usually<(u16, u16)> + Send>>,
pub handle: Mutex<Box<dyn FnMut(&mut T, &EngineEvent)->Usually<()> + Send>>,
pub process: Mutex<Box<dyn FnMut(&mut T) + Send>>
}
@ -109,7 +113,7 @@ impl<T> DynamicDevice<T> {
process: P,
state: T
) -> Self where
R: FnMut(&T, &mut Buffer, Rect) + Send + 'static,
R: FnMut(&T, &mut Buffer, Rect)->Usually<(u16, u16)> + Send + 'static,
H: FnMut(&mut T, &EngineEvent) -> Result<(), Box<dyn Error>> + Send + 'static,
P: FnMut(&mut T) + Send + 'static
{
@ -126,23 +130,23 @@ impl<T> DynamicDevice<T> {
}
impl<T: Send + Sync> Device for DynamicDevice<T> {
fn handle (&mut self, event: &EngineEvent) -> Result<(), Box<dyn Error>> {
fn handle (&mut self, event: &EngineEvent) -> Usually<()> {
self.handle.lock().unwrap()(&mut *self.state.lock().unwrap(), event)
}
fn render (&self, buf: &mut Buffer, area: Rect) {
fn render (&self, buf: &mut Buffer, area: Rect) -> Usually<(u16, u16)> {
self.render.lock().unwrap()(&*self.state.lock().unwrap(), buf, area)
}
}
impl WidgetRef for &dyn Device {
fn render_ref (&self, area: Rect, buf: &mut Buffer) {
Device::render(*self, buf, area)
Device::render(*self, buf, area).expect("Failed to render device.");
}
}
impl WidgetRef for dyn Device {
fn render_ref (&self, area: Rect, buf: &mut Buffer) {
Device::render(self, buf, area)
Device::render(self, buf, area).expect("Failed to render device.");
}
}

View file

@ -14,7 +14,38 @@ impl Chain {
}
}
pub fn render (state: &Chain, buf: &mut Buffer, area: Rect) {}
pub fn render (state: &Chain, buf: &mut Buffer, area: Rect)
-> Usually<(u16, u16)>
{
let Rect { x, y, width, height } = area;
let area = Rect { x, y, width: 40, height: 30 };
let mut y = area.y;
buf.set_string(area.x, y, "", Style::default().black());
buf.set_string(area.x + area.width - 1, y, "", Style::default().black());
buf.set_string(area.x + 2, y, "Input...", Style::default().dim());
let mut x = 0u16;
y = y + 1;
for device in state.devices.iter() {
let (w, h) = device.render(buf, Rect {
x: area.x,
y: area.y + y,
width: area.width,
height: area.height - y
})?;
//buf.set_string(area.x, y, format!("{y}---TOP---+{h}"), Style::default().red());
x = x.max(w);
y = y + h;
y = y + 1;
buf.set_string(area.x, y, "", Style::default().black());
buf.set_string(area.x + area.width - 1, y, "", Style::default().black());
buf.set_string(area.x + 2, y, "Patch in... │ Patch out...", Style::default().dim());
y = y + 1;
//buf.set_string(area.x, y, format!("{y}---BOT---"), Style::default().red());
//buf.set_string(area.x + area.width - 1, area.y + 1, "│", Style::default().black());
//buf.set_string(area.x + 2, y, "Patch...", Style::default().dim());
}
Ok((x, y))
}
pub fn handle (state: &mut Chain, event: &EngineEvent) -> Result<(), Box<dyn Error>> {
Ok(())

View file

@ -12,7 +12,9 @@ impl Looper {
}
}
pub fn render (state: &Looper, buf: &mut Buffer, area: Rect) {
pub fn render (state: &Looper, buf: &mut Buffer, area: Rect)
-> Usually<(u16, u16)>
{
//let move_to = |col, row| MoveTo(offset.0 + col, offset.1 + row);
//stdout
//.queue(move_to(0, 0))?.queue(Print(" Name Input Length Route"))?
@ -20,6 +22,7 @@ pub fn render (state: &Looper, buf: &mut Buffer, area: Rect) {
//.queue(move_to(0, 2))?.queue(PrintStyledContent(" Loop 1 [ ] ████ Track 1".bold()))?
//.queue(move_to(0, 3))?.queue(PrintStyledContent(" Loop 2 [ ] ████████ Track 2".bold()))?
//.queue(move_to(0, 4))?.queue(PrintStyledContent(" Loop 3 [ ] ████████ Track 3".bold()))?;
Ok((20, 10))
}
pub fn handle (state: &mut Looper, event: &EngineEvent) -> Result<(), Box<dyn Error>> {

View file

@ -41,7 +41,15 @@ impl Mixer {
}
}
pub fn render (state: &Mixer, buf: &mut Buffer, area: Rect) {
pub fn render (state: &Mixer, buf: &mut Buffer, mut area: Rect)
-> Usually<(u16, u16)>
{
if area.height < 2 {
return Ok((0, 0))
}
area.x = area.width.saturating_sub(80) / 2;
area.width = area.width.min(80);
area.height = state.tracks.len() as u16 + 2;
draw_box(buf, area);
let x = area.x + 1;
let y = area.y + 1;
@ -52,7 +60,7 @@ pub fn render (state: &Mixer, buf: &mut Buffer, area: Rect) {
//&track.name, Style::default().bold().not_dim()
//);
for (j, (column, field)) in [
(0, format!(" {:7} ", track.name)),
(0, format!(" {:10} ", track.name)),
(12, format!(" {:.1}dB ", track.gain)),
(22, format!(" [ ] ")),
(30, format!(" C ")),
@ -94,6 +102,7 @@ pub fn render (state: &Mixer, buf: &mut Buffer, area: Rect) {
//}
}
}
Ok((20,10))
}
pub fn handle (state: &mut Mixer, event: &EngineEvent) -> Result<(), Box<dyn Error>> {

View file

@ -12,7 +12,20 @@ impl Plugin {
}
}
pub fn render (state: &Plugin, buf: &mut Buffer, area: Rect) {}
pub fn render (state: &Plugin, buf: &mut Buffer, Rect { x, y, width, height }: Rect)
-> Usually<(u16, u16)>
{
let style = Style::default().gray();
draw_box(buf, Rect { x, y: y, width: 40, height: 8 });
buf.set_string(x + 1, y + 1, &format!(" {}", state.name), style.white().bold());
buf.set_string(x + 13, y + 1, &format!("│ Plugin Name"), style.not_dim());
buf.set_string(x + 0, y + 2, &format!("├--------------------------------------┤"), style.dim());
buf.set_string(x + 1, y + 3, &format!(" Parameter 1 0.0"), style);
buf.set_string(x + 1, y + 4, &format!(" Parameter 2 0.0"), style);
buf.set_string(x + 1, y + 5, &format!(" Parameter 3 0.0"), style);
buf.set_string(x + 1, y + 6, &format!(" Parameter 4 0.0"), style);
Ok((40, 7))
}
pub fn handle (state: &mut Plugin, event: &EngineEvent) -> Result<(), Box<dyn Error>> {
Ok(())

View file

@ -106,9 +106,29 @@ impl Sample {
}
pub fn render (state: &Sampler, buf: &mut Buffer, area: Rect) {
pub fn render (state: &Sampler, buf: &mut Buffer, Rect { x, y, width, height }: Rect)
-> Usually<(u16, u16)>
{
let style = Style::default().gray();
draw_box(buf, Rect { x, y: y, width: 40, height: 12 });
buf.set_string(x + 1, y + 1, &format!(" {}", state.name), style.white().bold());
buf.set_string(x + 0, y + 2, &format!("├--------------------------------------┤"), style.dim());
buf.set_string(x + 2, y + 3, &format!("C0 Sample#000"), style.bold());
buf.set_string(x + 2, y + 4, &format!(" {:.03}s",
100000.0/44100.0), style);
buf.set_string(x + 2, y + 5, &format!("C#0 Sample#001"), style.bold());
buf.set_string(x + 2, y + 6, &format!(" {:.03}-{:.03}s",
50000.0/44100.0, 100000.0/44100.0), style);
buf.set_string(x + 2, y + 7, &format!("D0 Sample#002"), style.bold());
buf.set_string(x + 2, y + 8, &format!(" {:.03}-{:.03}/{:.03}s",
0.0, 50000.0/44100.0, 100000.0/44100.0), style);
buf.set_string(x + 2, y + 9, &format!("D#0 Sample#003"), style.bold());
buf.set_string(x + 2, y + 10, &format!(" {:.03}-[{:.03}-{:.03}]/{:.03}s ",
10000.0/44100.0, 25000.0/44100.0, 50000.0/44100.0, 100000.0/44100.0), style);
//buf.set_string(x + 1, y + 7 + 6, &format!(" Inputs... │ Outputs... "), style.dim());
//render_table(state, stdout, offset)?;
//render_meters(state, stdout, offset)?;
Ok((40, 11))
}
//fn render_table (

View file

@ -205,10 +205,53 @@ const KEYS_VERTICAL: [&'static str; 6] = [
"", "", "", "", "", "",
];
fn render (sequencer: &Sequencer, buf: &mut Buffer, mut area: Rect) {
fn render (sequencer: &Sequencer, buf: &mut Buffer, mut area: Rect)
-> Usually<(u16, u16)>
{
let style = Style::default().gray();
area.height = 18;
//draw_box(buf, area);
let Rect { x, y, width, height } = area;
buf.set_string(x + 1, y + 1, &format!(" │ 00:00.00 / 00:00.00"), style);
buf.set_string(x + 2, y + 1, &format!("{}", &sequencer.name), style.white().bold());
buf.set_string(x + 1, y + 2, &format!(" ▶ PLAY │ ⏹ STOP │ ⏺ REC │ ⏺ DUB "), style);
//buf.set_string(x + 1, y + 6, &format!(" │ Outputs... "), style.dim());
let mut h = 9;
let toggle = true;
if toggle {
for i in 0..16 {
buf.set_string(x + 2, y + 4 + i, &format!(" "), Style::default().on_black());
h = h + 1;
}
}
for i in 0..3 {
buf.set_string(1 + i * 12 + x + 1, y + h - 5, &format!(""), Style::default().white());
buf.set_string(1 + i * 12 + x + 2, y + h - 5, &format!(""), Style::default().black());
buf.set_string(1 + i * 12 + x + 3, y + h - 5, &format!(""), Style::default().white());
buf.set_string(1 + i * 12 + x + 4, y + h - 5, &format!(""), Style::default().black());
buf.set_string(1 + i * 12 + x + 5, y + h - 5, &format!(""), Style::default().white());
buf.set_string(1 + i * 12 + x + 6, y + h - 5, &format!(""), Style::default().white());
buf.set_string(1 + i * 12 + x + 7, y + h - 5, &format!(""), Style::default().black());
buf.set_string(1 + i * 12 + x + 8, y + h - 5, &format!(""), Style::default().white());
buf.set_string(1 + i * 12 + x + 9, y + h - 5, &format!(""), Style::default().black());
buf.set_string(1 + i * 12 + x + 10, y + h - 5, &format!(""), Style::default().white());
buf.set_string(1 + i * 12 + x + 11, y + h - 5, &format!(""), Style::default().black());
buf.set_string(1 + i * 12 + x + 12, y + h - 5, &format!(""), Style::default().white());
buf.set_string(1 + i * 12 + x + 1, y + h - 4, &format!(""), Style::default().white());
buf.set_string(1 + i * 12 + x + 2, y + h -4, &format!(""), Style::default().black());
buf.set_string(1 + i * 12 + x + 3, y + h -4, &format!(""), Style::default().white());
buf.set_string(1 + i * 12 + x + 4, y + h -4, &format!(""), Style::default().black());
buf.set_string(1 + i * 12 + x + 5, y + h -4, &format!(""), Style::default().white());
buf.set_string(1 + i * 12 + x + 6, y + h -4, &format!(""), Style::default().white());
buf.set_string(1 + i * 12 + x + 7, y + h -4, &format!(""), Style::default().black());
buf.set_string(1 + i * 12 + x + 8, y + h -4, &format!(""), Style::default().white());
buf.set_string(1 + i * 12 + x + 9, y + h -4, &format!(""), Style::default().black());
buf.set_string(1 + i * 12 + x + 10, y + h -4, &format!(""), Style::default().white());
buf.set_string(1 + i * 12 + x + 11, y + h -4, &format!(""), Style::default().black());
buf.set_string(1 + i * 12 + x + 12, y + h -4, &format!(""), Style::default().white());
}
draw_box(buf, Rect { x, y, width: 40, height: h - 2 });
Ok((40,h-3))
//{
//let mut area = area.clone();
//area.y = area.y + 3;
@ -223,29 +266,7 @@ fn render (sequencer: &Sequencer, buf: &mut Buffer, mut area: Rect) {
//}
//draw_box(buf, Rect { x, y, width: 18, height });
draw_box(buf, Rect { x, y, width: 40, height: 8 });
draw_box(buf, Rect { x, y, width: 40, height: 6 });
let style = Style::default().gray();
buf.set_string(x + 1, y + 1, &format!(" │ 00:00.00 / 00:00.00"), style);
buf.set_string(x + 2, y + 1, &format!("{}", &sequencer.name), style.bold());
buf.set_string(x + 1, y + 2, &format!(" ▶ PLAY │ ⏹ STOP │ ⏺ REC │ ⏺ DUB "), style);
buf.set_string(x + 0, y + 3, &format!("├--------------------------------------┤"), style.dim());
buf.set_string(x + 1, y + 6, &format!(" Inputs... │ Outputs... "), style);
buf.set_string(x + 0, y + 5, &format!("├--------------------------------------┤"), style.dim());
for i in 0..3 {
buf.set_string(1 + i * 12 + x + 1, y + 4, &format!(" "), Style::default().on_white());
buf.set_string(1 + i * 12 + x + 2, y + 4, &format!(" "), Style::default().on_black());
buf.set_string(1 + i * 12 + x + 3, y + 4, &format!(" "), Style::default().on_white());
buf.set_string(1 + i * 12 + x + 4, y + 4, &format!(" "), Style::default().on_black());
buf.set_string(1 + i * 12 + x + 5, y + 4, &format!(" "), Style::default().on_white());
buf.set_string(1 + i * 12 + x + 6, y + 4, &format!(" "), Style::default().on_white());
buf.set_string(1 + i * 12 + x + 7, y + 4, &format!(" "), Style::default().on_black());
buf.set_string(1 + i * 12 + x + 8, y + 4, &format!(" "), Style::default().on_white());
buf.set_string(1 + i * 12 + x + 9, y + 4, &format!(" "), Style::default().on_black());
buf.set_string(1 + i * 12 + x + 10, y + 4, &format!(" "), Style::default().on_white());
buf.set_string(1 + i * 12 + x + 11, y + 4, &format!(" "), Style::default().on_black());
buf.set_string(1 + i * 12 + x + 12, y + 4, &format!(" "), Style::default().on_white());
}
//draw_box(buf, Rect { x, y, width: 40, height: 8 });
//buf.set_string(x + 1, y + 3,
//&format!(" │ INPUT │ OUTPUT │"),
//Style::default().gray());
@ -259,11 +280,11 @@ fn render (sequencer: &Sequencer, buf: &mut Buffer, mut area: Rect) {
//buf.set_string(x + 54, y + 1, "OUT", Style::default().green().bold());
//}
let mut command = |y2: u16, c: &str, ommand: &str, value: &str| {
buf.set_string(x + 1, y + y2, c, Style::default().bold());
buf.set_string(x + 2, y + y2, ommand, Style::default().dim());
buf.set_string(x + 4 + ommand.len() as u16, y + y2, value, Style::default().bold());
};
//let mut command = |y2: u16, c: &str, ommand: &str, value: &str| {
//buf.set_string(x + 1, y + y2, c, Style::default().bold());
//buf.set_string(x + 2, y + y2, ommand, Style::default().dim());
//buf.set_string(x + 4 + ommand.len() as u16, y + y2, value, Style::default().bold());
//};
//for (y, c, ommand, value) in [
////(5, "I", "nputs", "[+]"),
////(6, "O", "utputs", "[+]"),
@ -308,36 +329,6 @@ fn render (sequencer: &Sequencer, buf: &mut Buffer, mut area: Rect) {
//}
//}
//
let y = y + 8;
draw_box(buf, Rect { x, y: y, width: 40, height: 10 });
buf.set_string(x + 1, y + 1, &format!(" LV2Host#00"), style.bold());
buf.set_string(x + 13, y + 1, &format!("│ Plugin Name"), style.not_dim());
buf.set_string(x + 0, y + 2, &format!("├--------------------------------------┤"), style.dim());
buf.set_string(x + 1, y + 3, &format!(" Parameter 1 0.0"), style);
buf.set_string(x + 1, y + 4, &format!(" Parameter 2 0.0"), style);
buf.set_string(x + 1, y + 5, &format!(" Parameter 3 0.0"), style);
buf.set_string(x + 1, y + 6, &format!(" Parameter 4 0.0"), style);
buf.set_string(x + 0, y + 7, &format!("├--------------------------------------┤"), style.dim());
buf.set_string(x + 1, y + 8, &format!(" Inputs... │ Outputs... "), style);
let y = y + 10;
draw_box(buf, Rect { x, y: y, width: 40, height: 14 });
buf.set_string(x + 1, y + 1, &format!(" Sampler#00 │"), style.bold());
buf.set_string(x + 0, y + 2, &format!("├--------------------------------------┤"), style.dim());
buf.set_string(x + 2, y + 3, &format!("C0 Sample#000"), style.bold());
buf.set_string(x + 2, y + 4, &format!(" {:.03}s",
100000.0/44100.0), style);
buf.set_string(x + 2, y + 5, &format!("C#0 Sample#001"), style.bold());
buf.set_string(x + 2, y + 6, &format!(" {:.03}-{:.03}s",
50000.0/44100.0, 100000.0/44100.0), style);
buf.set_string(x + 2, y + 7, &format!("D0 Sample#002"), style.bold());
buf.set_string(x + 2, y + 8, &format!(" {:.03}-{:.03}/{:.03}s",
0.0, 50000.0/44100.0, 100000.0/44100.0), style);
buf.set_string(x + 2, y + 9, &format!("D#0 Sample#003"), style.bold());
buf.set_string(x + 2, y + 10, &format!(" {:.03}-[{:.03}-{:.03}]/{:.03}s ",
10000.0/44100.0, 25000.0/44100.0, 50000.0/44100.0, 100000.0/44100.0), style);
buf.set_string(x + 0, y + 7 + 4, &format!("├--------------------------------------┤"), style.dim());
buf.set_string(x + 1, y + 7 + 5, &format!(" Inputs... │ Outputs... "), style);
}
fn draw_sequence_button (

View file

@ -5,11 +5,10 @@ pub struct Transport {
transport: Option<::jack::Transport>,
bpm: f64,
timesig: (f32, f32),
devices: Vec<Box<dyn Device>>,
}
impl Transport {
pub fn new (devices: Vec<Box<dyn Device>>)
pub fn new ()
-> Result<DynamicDevice<Self>, Box<dyn Error>>
{
//let transport = client.transport();
@ -18,7 +17,6 @@ impl Transport {
bpm: 113.0,
timesig: (4.0, 4.0),
transport: None,
devices
}))
}
@ -42,14 +40,20 @@ impl Transport {
}
}
pub fn render (state: &Transport, buf: &mut Buffer, area: Rect) {
draw_leaf(buf, area, 0, 0, "REC");
draw_leaf(buf, area, 0, 5, "DUB");
draw_leaf(buf, area, 0, 10, "STOP");
draw_leaf(buf, area, 0, 16, "PLAY/PAUSE");
draw_leaf(buf, area, 0, 28, "START");
draw_leaf(buf, area, 0, 35, "Project: Witty Gerbil - Sha Na Na ");
draw_leaf(buf, area, 2, 0, &format!("BPM {:03}.{:03}",
pub fn render (state: &Transport, buf: &mut Buffer, mut area: Rect)
-> Usually<(u16, u16)>
{
area.x = area.width.saturating_sub(80) / 2;
area.width = area.width.min(80);
area.height = 5;
draw_box(buf, area);
draw_leaf(buf, area, 1, 0, "REC");
draw_leaf(buf, area, 1, 5, "DUB");
draw_leaf(buf, area, 1, 10, "STOP");
draw_leaf(buf, area, 1, 16, "PLAY/PAUSE");
draw_leaf(buf, area, 1, 28, "START");
draw_leaf(buf, area, 1, 35, "Project: Witty Gerbil - Sha Na Na ");
draw_leaf(buf, area, 3, 0, &format!("BPM {:03}.{:03}",
state.bpm as u64,
((state.bpm % 1.0) * 1000.0) as u64
));
@ -70,7 +74,7 @@ pub fn render (state: &Transport, buf: &mut Buffer, area: Rect) {
//format!("BBT {bars:04}:{beat:02}.{:02}", (beat_sub * 16.0) as u32),
//Style::default()
//);
draw_leaf(buf, area, 2, 13, &format!("BBT {bars:04}:{beat:02}.{:02}",
draw_leaf(buf, area, 3, 13, &format!("BBT {bars:04}:{beat:02}.{:02}",
(beat_sub * 16.0) as u32
));
let time = frame as f64 / rate as f64;
@ -78,15 +82,16 @@ pub fn render (state: &Transport, buf: &mut Buffer, area: Rect) {
let msec = seconds % 1.0;
let minutes = (time / 60.0) % 60.0;
let hours = time / 3600.0;
draw_leaf(buf, area, 2, 29, &format!("Time {:02}:{:02}:{:02}.{:03}",
draw_leaf(buf, area, 3, 29, &format!("Time {:02}:{:02}:{:02}.{:03}",
hours as u64,
minutes as u64,
seconds as u64,
(msec * 1000.0) as u64
));
draw_leaf(buf, area, 2, 48, &format!("Rate {:>6}Hz", rate));
draw_leaf(buf, area, 2, 63, &format!("Frame {:>10}", frame));
draw_leaf(buf, area, 3, 48, &format!("Rate {:>6}Hz", rate));
draw_leaf(buf, area, 3, 63, &format!("Frame {:>10}", frame));
}
Ok((area.width, area.height))
//let bbt = position.pos.bbt().map(|mut bbt|*bbt
//.with_bpm(state.bpm)
//.with_timesig(state.timesig.0, state.timesig.1));

View file

@ -5,18 +5,23 @@ pub struct Rows(pub Vec<Box<dyn Device>>);
pub struct Columns(pub Vec<Box<dyn Device>>);
impl Device for Rows {
fn handle (&mut self, event: &EngineEvent) -> Result<(), Box<dyn Error>> {
fn handle (&mut self, event: &EngineEvent) -> Usually<()> {
Ok(())
}
fn render (&self, buf: &mut Buffer, area: Rect) {
for i in 0..3 {
self.0[i].render(buf, Rect {
fn render (&self, buf: &mut Buffer, area: Rect) -> Usually<(u16, u16)> {
let mut x = 0u16;
let mut y = 0u16;
for device in self.0.iter() {
let (w, h) = device.render(buf, Rect {
x: area.x,
y: area.height / 3 * i as u16,
y: area.y + y,
width: area.width,
height: area.height / 3
})
height: area.height - y
})?;
x = x.max(w);
y = y + h;
}
Ok((x, y))
}
}
@ -24,14 +29,19 @@ impl Device for Columns {
fn handle (&mut self, event: &EngineEvent) -> Result<(), Box<dyn Error>> {
Ok(())
}
fn render (&self, buf: &mut Buffer, area: Rect) {
for i in 0..3 {
self.0[i].render(buf, Rect {
x: area.width / 3 * i as u16,
fn render (&self, buf: &mut Buffer, area: Rect) -> Usually<(u16, u16)> {
let mut x = 0u16;
let mut y = 0u16;
for device in self.0.iter() {
let (w, h) = device.render(buf, Rect {
x: area.x + x,
y: area.y,
width: area.width / 3,
width: area.width - x,
height: area.height
})
})?;
x = x + w;
y = y.max(h);
}
Ok((x, y))
}
}

View file

@ -29,10 +29,24 @@ fn main () -> Result<(), Box<dyn Error>> {
Box::new(Sequencer::new("Melody#000")?),
Box::new(Plugin::new("Plugin#000")?),
])?),
Box::new(Chain::new("Chain#02", vec![])?),
Box::new(Chain::new("Chain#03", vec![])?),
])),
Box::new(Mixer::new("Mixer#00")?),
Box::new(Transport::new(vec![])?),
Box::new(Mixer::new("Mixer#000")?),
Box::new(Transport::new()?),
]))
//crate::device::run(Rows(vec![
////Box::new(Columns(vec![
////Box::new(Chain::new("Chain#00", vec![
////Box::new(Sequencer::new("Rhythm#000")?),
////Box::new(Sampler::new("Sampler#00")?),
////])?),
////Box::new(Chain::new("Chain#01", vec![
////Box::new(Sequencer::new("Melody#000")?),
////Box::new(Plugin::new("Plugin#000")?),
////])?),
////Box::new(Chain::new("Chain#02", vec![])?),
////Box::new(Chain::new("Chain#03", vec![])?),
////])),
////Box::new(Mixer::new("Mixer#00")?),
//Box::new(Transport::new()?),
//]))
}

View file

@ -63,3 +63,4 @@ pub use crate::device::{
DynamicDevice,
EngineEvent
};
pub type Usually<T> = Result<T, Box<dyn Error>>;

View file

@ -28,7 +28,6 @@ impl<'a> WidgetRef for ActionBar<'a> {
}
pub fn draw_leaf (buffer: &mut Buffer, area: Rect, y: u16, x: u16, text: &str) {
use ratatui::style::{Style, Stylize};
let border = Style::default().gray().dim();
let label = Style::default();
let side = String::from("");
@ -40,7 +39,9 @@ pub fn draw_leaf (buffer: &mut Buffer, area: Rect, y: u16, x: u16, text: &str) {
}
pub fn draw_box (buffer: &mut Buffer, area: Rect) {
use ratatui::style::{Style, Stylize};
if area.width < 1 || area.height < 1 {
return
}
let border = Style::default().gray().dim();
let top = format!("{}", "".repeat((area.width - 2).into()));
let bottom = format!("{}", "".repeat((area.width - 2).into()));
@ -53,7 +54,6 @@ pub fn draw_box (buffer: &mut Buffer, area: Rect) {
}
pub fn draw_focus_corners (buffer: &mut Buffer, area: Rect) {
use ratatui::style::{Style, Stylize};
let focus = Style::default().yellow().bold().not_dim();
buffer.set_string(area.x, area.y, "", focus);
buffer.set_string(area.x + area.width - 1, area.y, "", focus);