wip: 21 errors!

This commit is contained in:
🪞👃🪞 2024-09-05 17:38:32 +03:00
parent 694970bf0d
commit ea5bc2e3b1
30 changed files with 392 additions and 362 deletions

View file

@ -8,7 +8,7 @@ pub struct MixerCli {
/// Number of tracks
#[arg(short, long)] channels: Option<usize>,
}
impl<T, U> Mixer<T, U> {
impl<E: Engine> Mixer<E> {
pub fn from_args () -> Usually<Self> {
let args = MixerCli::parse();
let mut mix = Self::new("")?;

View file

@ -1,8 +1,8 @@
use crate::*;
impl <T, U> Handle for Mixer<T, U> {
fn handle (&mut self, event: &AppEvent) -> Usually<bool> {
if let AppEvent::Input(crossterm::event::Event::Key(event)) = event {
impl Handle<Tui> for Mixer<Tui> {
fn handle (&mut self, engine: &Tui) -> Perhaps<bool> {
if let TuiEvent::Input(crossterm::event::Event::Key(event)) = engine.event() {
match event.code {
//KeyCode::Char('c') => {
@ -13,7 +13,7 @@ impl <T, U> Handle for Mixer<T, U> {
KeyCode::Down => {
self.selected_track = (self.selected_track + 1) % self.tracks.len();
println!("{}", self.selected_track);
return Ok(true)
return Ok(Some(true))
},
KeyCode::Up => {
if self.selected_track == 0 {
@ -22,7 +22,7 @@ impl <T, U> Handle for Mixer<T, U> {
self.selected_track -= 1;
}
println!("{}", self.selected_track);
return Ok(true)
return Ok(Some(true))
},
KeyCode::Left => {
if self.selected_column == 0 {
@ -30,7 +30,7 @@ impl <T, U> Handle for Mixer<T, U> {
} else {
self.selected_column -= 1;
}
return Ok(true)
return Ok(Some(true))
},
KeyCode::Right => {
if self.selected_column == 6 {
@ -38,7 +38,7 @@ impl <T, U> Handle for Mixer<T, U> {
} else {
self.selected_column += 1;
}
return Ok(true)
return Ok(Some(true))
},
_ => {
println!("\n{event:?}");
@ -46,7 +46,7 @@ impl <T, U> Handle for Mixer<T, U> {
}
}
Ok(false)
Ok(None)
}
}

View file

@ -9,7 +9,11 @@ pub struct Plugin {
pub mapping: bool,
pub ports: JackPorts,
}
handle!(Plugin |self, e| handle_keymap(self, e, KEYMAP_PLUGIN));
impl Handle<Tui> for Plugin {
fn handle (&mut self, e: &Tui) -> Perhaps<bool> {
handle_keymap(self, event, KEYMAP_PLUGIN)
}
}
process!(Plugin = Plugin::process);
impl Render<Tui> for Plugin {
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
@ -36,7 +40,7 @@ impl Render<Tui> for Plugin {
} else {
None
} ;
label.blit(to.buffer(), x + 2, y + 1 + i as u16 - start as u16, style)?;
to.blit(&label, x + 2, y + 1 + i as u16 - start as u16, style)?;
} else {
break
}
@ -44,7 +48,7 @@ impl Render<Tui> for Plugin {
},
_ => {}
};
draw_header(self, to.buffer(), area.x, area.y, width)?;
draw_header(self, to, area.x, area.y, width)?;
Ok(Some(Rect { width, ..to.area() }))
}
}
@ -58,7 +62,7 @@ pub enum PluginKind {
VST3,
}
impl Plugin {
pub fn new_lv2 <E> (name: &str, path: &str) -> Usually<JackDevice<E>> {
pub fn new_lv2 (name: &str, path: &str) -> Usually<JackDevice<Tui>> {
let plugin = LV2Plugin::new(path)?;
jack_from_lv2(name, &plugin.plugin)?
.run(|ports|Box::new(Self {
@ -137,13 +141,13 @@ impl Plugin {
Control::Continue
}
}
fn draw_header (state: &Plugin, buf: &mut Buffer, x: u16, y: u16, w: u16) -> Usually<Rect> {
fn draw_header (state: &Plugin, to: &mut Tui, x: u16, y: u16, w: u16) -> Usually<Rect> {
let style = Style::default().gray();
let label1 = format!(" {}", state.name);
label1.blit(buf, x + 1, y, Some(style.white().bold()))?;
to.blit(&label1, x + 1, y, Some(style.white().bold()))?;
if let Some(ref path) = state.path {
let label2 = format!("{}", &path[..((w as usize - 10).min(path.len()))]);
label2.blit(buf, x + 2 + label1.len() as u16, y, Some(style.not_dim()))?;
to.blit(&label2, x + 2 + label1.len() as u16, y, Some(style.not_dim()))?;
}
Ok(Rect { x, y, width: w, height: 1 })
}

View file

@ -22,7 +22,7 @@ pub struct LV2Plugin {
}
impl LV2Plugin {
pub fn from_edn <'e, T, U> (args: &[Edn<'e>]) -> Usually<JackDevice<T, U>> {
pub fn from_edn <'e, E: Engine> (args: &[Edn<'e>]) -> Usually<JackDevice<E>> {
let mut name = String::new();
let mut path = String::new();
edn!(edn in args {

View file

@ -13,8 +13,8 @@ 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> {
impl Handle<Tui> for Sampler {
fn handle (&mut self, e: &Tui) -> Perhaps<bool> {
handle_keymap(self, event, KEYMAP_SAMPLER)
}
}
@ -69,7 +69,7 @@ pub const KEYMAP_SAMPLER: &'static [KeyBinding<Sampler>] = keymap!(Sampler {
});
impl Sampler {
pub fn from_edn <'e, E: Engine> (args: &[Edn<'e>]) -> Usually<JackDevice<E>> {
pub fn from_edn <'e> (args: &[Edn<'e>]) -> Usually<JackDevice<Tui>> {
let mut name = String::new();
let mut dir = String::new();
let mut samples = BTreeMap::new();
@ -98,9 +98,9 @@ impl Sampler {
Self::new(&name, Some(samples))
}
pub fn new <E: Engine> (
pub fn new (
name: &str, mapped: Option<BTreeMap<u7, Arc<RwLock<Sample>>>>
) -> Usually<JackDevice<E>> {
) -> Usually<JackDevice<Tui>> {
Jack::new(name)?
.midi_in("midi")
.audio_in("recL")

View file

@ -1,9 +1,9 @@
use crate::*;
impl <T, U> Handle for Track<T, U> {
fn handle (&mut self, event: &AppEvent) -> Usually<bool> {
match event {
AppEvent::Input(crossterm::event::Event::Key(event)) => {
impl Handle<Tui> for Track<Tui> {
fn handle (&mut self, from: &Tui) -> Perhaps<bool> {
match from.event() {
TuiEvent::Input(crossterm::event::Event::Key(event)) => {
for (code, modifiers, _, _, command) in [
key!(Up, NONE, "chain_cursor_up", "move cursor up", || {
Ok(true)
@ -34,9 +34,9 @@ impl <T, U> Handle for Track<T, U> {
return command()
}
}
return Ok(false)
return Ok(None)
},
_ => Ok(false)
_ => Ok(None)
}
}
}

View file

@ -46,7 +46,7 @@ impl<'a> Render<Tui> for TrackView<'a, Tui> {
}
let (area, areas) = split.render_areas(to)?;
if self.focused && self.entered && areas.len() > 0 {
Corners(Style::default().green().not_dim()).draw(to.buffer, areas[0])?;
Corners(Style::default().green().not_dim()).draw(to.with_rect(areas[0]))?;
}
Ok(Some(area))
} else {
@ -54,7 +54,7 @@ impl<'a> Render<Tui> for TrackView<'a, Tui> {
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()))?;
to.blit(&label, x, y, Some(Style::default().dim().bold()))?;
Ok(Some(area))
}
}