wip: tui cleanup

This commit is contained in:
🪞👃🪞 2024-09-05 13:28:05 +03:00
parent df3dac183e
commit 14d619a10a
17 changed files with 345 additions and 306 deletions

View file

@ -1,12 +1,12 @@
use crate::*;
pub struct Mixer<T, U> {
pub struct Mixer<E> {
pub name: String,
pub tracks: Vec<Track<T, U>>,
pub tracks: Vec<Track<E>>,
pub selected_track: usize,
pub selected_column: usize,
}
impl<T, U> Mixer<T, U> {
impl<E> Mixer<E> {
pub fn new (name: &str) -> Usually<Self> {
let (client, _status) = Client::new(name, ClientOptions::NO_START_SERVER)?;
Ok(Self {
@ -21,12 +21,17 @@ impl<T, U> Mixer<T, U> {
self.tracks.push(track);
Ok(self)
}
pub fn track (&self) -> Option<&Track<T, U>> {
pub fn track (&self) -> Option<&Track<E>> {
self.tracks.get(self.selected_track)
}
}
impl<'a> Render<TuiOutput<'a>, Rect> for Mixer<TuiOutput<'a>, Rect> {
fn render (&self, to: &mut TuiOutput<'a>) -> Perhaps<Rect> {
impl<E> Process for Mixer<E> {
fn process (&mut self, _: &Client, _: &ProcessScope) -> Control {
Control::Continue
}
}
impl Render<Tui> for Mixer<Tui> {
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
let mut tracks = Split::right();
for channel in self.tracks.iter() {
tracks = tracks.add_ref(channel)
@ -34,8 +39,3 @@ impl<'a> Render<TuiOutput<'a>, Rect> for Mixer<TuiOutput<'a>, Rect> {
tracks.render(to)
}
}
impl<T, U> Process for Mixer<T, U> {
fn process (&mut self, _: &Client, _: &ProcessScope) -> Control {
Control::Continue
}
}

View file

@ -11,9 +11,10 @@ pub struct Plugin {
}
handle!(Plugin |self, e| handle_keymap(self, e, KEYMAP_PLUGIN));
process!(Plugin = Plugin::process);
impl<'a> Render<TuiOutput<'a>, Rect> for Plugin {
fn render (&self, to: &mut TuiOutput<'a>) -> Perhaps<Rect> {
let Rect { x, y, height, .. } = to.area;
impl Render<Tui> for Plugin {
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
let area = to.area();
let Rect { x, y, height, .. } = area;
let mut width = 20u16;
match &self.plugin {
Some(PluginKind::LV2(LV2Plugin { port_list, instance, .. })) => {
@ -35,7 +36,7 @@ impl<'a> Render<TuiOutput<'a>, Rect> for Plugin {
} else {
None
} ;
label.blit(to.buffer, x + 2, y + 1 + i as u16 - start as u16, style)?;
label.blit(to.buffer(), x + 2, y + 1 + i as u16 - start as u16, style)?;
} else {
break
}
@ -43,8 +44,8 @@ impl<'a> Render<TuiOutput<'a>, Rect> for Plugin {
},
_ => {}
};
draw_header(self, to.buffer, to.area.x, to.area.y, width)?;
Ok(Some(Rect { width, ..to.area }))
draw_header(self, to.buffer(), area.x, area.y, width)?;
Ok(Some(Rect { width, ..to.area() }))
}
}
@ -57,7 +58,7 @@ pub enum PluginKind {
VST3,
}
impl Plugin {
pub fn new_lv2 <T, U> (name: &str, path: &str) -> Usually<JackDevice<T, U>> {
pub fn new_lv2 <E> (name: &str, path: &str) -> Usually<JackDevice<E>> {
let plugin = LV2Plugin::new(path)?;
jack_from_lv2(name, &plugin.plugin)?
.run(|ports|Box::new(Self {

View file

@ -18,12 +18,12 @@ process!(Sampler = Sampler::process);
handle!(Sampler |self, event| handle_keymap(self, event, KEYMAP_SAMPLER));
impl<'a> Render<TuiOutput<'a>, Rect> for Sampler {
fn render (&self, to: &mut TuiOutput<'a>) -> Perhaps<Rect> {
let Rect { x, y, height, .. } = to.area;
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()))?;
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;
@ -36,13 +36,13 @@ impl<'a> Render<TuiOutput<'a>, Rect> for Sampler {
}
let active = j == self.cursor.0;
width = width.max(
draw_sample(to.buffer, x, y + y1, note, &*sample.read().unwrap(), active)?
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 }))
Ok(Some(Rect { x, y, width: (width as u16).min(to.area().width), height }))
}
}
@ -105,7 +105,7 @@ pub const KEYMAP_SAMPLER: &'static [KeyBinding<Sampler>] = keymap!(Sampler {
});
impl Sampler {
pub fn from_edn <'e, T, U> (args: &[Edn<'e>]) -> Usually<JackDevice<T, U>> {
pub fn from_edn <'e, E> (args: &[Edn<'e>]) -> Usually<JackDevice<E>> {
let mut name = String::new();
let mut dir = String::new();
let mut samples = BTreeMap::new();
@ -134,9 +134,9 @@ impl Sampler {
Self::new(&name, Some(samples))
}
pub fn new <T, U> (
pub fn new <E> (
name: &str, mapped: Option<BTreeMap<u7, Arc<RwLock<Sample>>>>
) -> Usually<JackDevice<T, U>> {
) -> Usually<JackDevice<E>> {
Jack::new(name)?
.midi_in("midi")
.audio_in("recL")

View file

@ -3,16 +3,16 @@ use tek_core::edn;
/// A sequencer track.
#[derive(Debug)]
pub struct Track<T, U> {
pub struct Track<E: Engine> {
pub name: String,
/// Inputs and outputs of 1st and last device
pub ports: JackPorts,
/// Device chain
pub devices: Vec<JackDevice<T, U>>,
pub devices: Vec<JackDevice<E>>,
/// Device selector
pub device: usize,
}
impl<T, U> Track<T, U> {
impl<E: Engine> Track<E> {
pub fn new (name: &str) -> Usually<Self> {
Ok(Self {
name: name.to_string(),
@ -21,14 +21,14 @@ impl<T, U> Track<T, U> {
device: 0,
})
}
fn get_device_mut (&self, i: usize) -> Option<RwLockWriteGuard<Box<dyn Device<T, U>>>> {
fn get_device_mut (&self, i: usize) -> Option<RwLockWriteGuard<Box<dyn Device<E>>>> {
self.devices.get(i).map(|d|d.state.write().unwrap())
}
pub fn device_mut (&self) -> Option<RwLockWriteGuard<Box<dyn Device<T, U>>>> {
pub fn device_mut (&self) -> Option<RwLockWriteGuard<Box<dyn Device<E>>>> {
self.get_device_mut(self.device)
}
/// Add a device to the end of the chain.
pub fn append_device (&mut self, device: JackDevice<T, U>) -> Usually<&mut JackDevice<T, U>> {
pub fn append_device (&mut self, device: JackDevice<E>) -> Usually<&mut JackDevice<E>> {
self.devices.push(device);
let index = self.devices.len() - 1;
Ok(&mut self.devices[index])
@ -54,7 +54,7 @@ impl<T, U> Track<T, U> {
let mut _gain = 0.0f64;
let mut track = Self::new("")?;
#[allow(unused_mut)]
let mut devices: Vec<JackDevice<T, U>> = vec![];
let mut devices: Vec<JackDevice<E>> = vec![];
edn!(edn in args {
Edn::Map(map) => {
if let Some(Edn::Str(n)) = map.get(&Edn::Key(SYM_NAME)) {
@ -95,7 +95,7 @@ impl<T, U> Track<T, U> {
}
Ok(track)
}
pub fn add_device (&mut self, device: JackDevice<T, U>) {
pub fn add_device (&mut self, device: JackDevice<E>) {
self.devices.push(device);
}
}

View file

@ -1,7 +1,7 @@
use crate::*;
use tek_core::Direction;
impl<'a> Render<TuiOutput<'a>, Rect> for Track<TuiOutput<'a>, Rect> {
impl<'a> Render<Tui> for Track<Tui> {
fn render (&self, to: &mut TuiOutput<'a>) -> Perhaps<Rect> {
TrackView {
chain: Some(&self),
@ -30,15 +30,16 @@ pub struct TrackView<'a, T, U> {
pub focused: bool,
pub entered: bool,
}
impl<'a> Render<TuiOutput<'a>, Rect> for TrackView<'a, TuiOutput<'a>, Rect> {
fn render (&self, to: &mut TuiOutput<'a>) -> Perhaps<Rect> {
impl<'a> Render<Tui> for TrackView<'a, Tui> {
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
let mut area = to.area();
if let Some(chain) = self.chain {
match self.direction {
Direction::Down => to.area.width = to.area.width.min(40),
Direction::Right => to.area.width = to.area.width.min(10),
Direction::Down => area.width = area.width.min(40),
Direction::Right => area.width = area.width.min(10),
_ => { unimplemented!() },
}
fill_bg(to.buffer, to.area, Nord::bg_lo(self.focused, self.entered));
to.fill_bg(to.area(), Nord::bg_lo(self.focused, self.entered));
let mut split = Split::new(self.direction);
for device in chain.devices.as_slice().iter() {
split = split.add_ref(device);
@ -49,12 +50,12 @@ impl<'a> Render<TuiOutput<'a>, Rect> for TrackView<'a, TuiOutput<'a>, Rect> {
}
Ok(Some(area))
} else {
let Rect { x, y, width, height } = to.area;
let Rect { x, y, width, height } = area;
let label = "No chain selected";
let x = x + (width - label.len() as u16) / 2;
let y = y + height / 2;
label.blit(to.buffer, x, y, Some(Style::default().dim().bold()))?;
Ok(Some(to.area))
label.blit(to.buffer(), x, y, Some(Style::default().dim().bold()))?;
Ok(Some(area))
}
}
}