wip: remodularize 2

This commit is contained in:
🪞👃🪞 2025-01-08 19:19:35 +01:00
parent 3b6ff81dad
commit d38dc14e84
27 changed files with 564 additions and 563 deletions

View file

@ -5,6 +5,20 @@
#![feature(impl_trait_in_assoc_type)]
#![feature(associated_type_defaults)]
pub mod arranger; pub use self::arranger::*;
pub mod file; pub use self::file::*;
pub mod focus; pub use self::focus::*;
pub mod groovebox; pub use self::groovebox::*;
pub mod meter; pub use self::meter::*;
pub mod mixer; pub use self::mixer::*;
pub mod plugin; pub use self::plugin::*;
pub mod pool; pub use self::pool::*;
pub mod sampler; pub use self::sampler::*;
pub mod sequencer; pub use self::sequencer::*;
pub use ::tek_time; pub(crate) use ::tek_time::*;
pub use ::tek_jack; pub(crate) use ::tek_jack::{*, jack::{*, contrib::*}};
pub use ::tek_midi; pub(crate) use ::tek_midi::{*, midly::{*, num::*, live::*}};
pub use ::tek_tui::{self, tek_edn, tek_input, tek_output};
pub(crate) use ::tek_tui::{
*,
@ -24,8 +38,6 @@ pub(crate) use ::tek_tui::{
buffer::Cell,
}
};
pub use ::tek_jack;
pub(crate) use ::tek_jack::{*, jack::{*, contrib::*}};
pub(crate) use std::cmp::{Ord, Eq, PartialEq};
pub(crate) use std::collections::BTreeMap;
@ -41,55 +53,235 @@ pub(crate) use std::sync::{Arc, Mutex, RwLock};
pub(crate) use std::thread::{spawn, JoinHandle};
pub(crate) use std::time::Duration;
pub mod arranger; pub use self::arranger::*;
pub mod file; pub use self::file::*;
pub mod focus; pub use self::focus::*;
pub mod groovebox; pub use self::groovebox::*;
pub mod meter; pub use self::meter::*;
pub mod mixer; pub use self::mixer::*;
pub mod piano; pub use self::piano::*;
pub mod plugin; pub use self::plugin::*;
pub mod pool; pub use self::pool::*;
pub mod sampler; pub use self::sampler::*;
pub mod sequencer; pub use self::sequencer::*;
//#[cfg(test)] mod test_focus {
//use super::focus::*;
//#[test] fn test_focus () {
pub use ::midly::{self, num::u7};
pub(crate) use ::midly::{
Smf,
MidiMessage,
TrackEventKind,
live::LiveEvent,
};
//struct FocusTest {
//focused: char,
//cursor: (usize, usize)
//}
testmod! { test }
//impl HasFocus for FocusTest {
//type Item = char;
//fn focused (&self) -> Self::Item {
//self.focused
//}
//fn set_focused (&mut self, to: Self::Item) {
//self.focused = to
//}
//}
/// Define test modules.
#[macro_export] macro_rules! testmod {
($($name:ident)*) => { $(#[cfg(test)] mod $name;)* };
}
//impl FocusGrid for FocusTest {
//fn focus_cursor (&self) -> (usize, usize) {
//self.cursor
//}
//fn focus_cursor_mut (&mut self) -> &mut (usize, usize) {
//&mut self.cursor
//}
//fn focus_layout (&self) -> &[&[Self::Item]] {
//&[
//&['a', 'a', 'a', 'b', 'b', 'd'],
//&['a', 'a', 'a', 'b', 'b', 'd'],
//&['a', 'a', 'a', 'c', 'c', 'd'],
//&['a', 'a', 'a', 'c', 'c', 'd'],
//&['e', 'e', 'e', 'e', 'e', 'e'],
//]
//}
//}
#[derive(Default)]
pub struct BigBuffer {
pub width: usize,
pub height: usize,
pub content: Vec<Cell>
}
//let mut tester = FocusTest { focused: 'a', cursor: (0, 0) };
impl BigBuffer {
pub fn new (width: usize, height: usize) -> Self {
Self { width, height, content: vec![Cell::default(); width*height] }
}
pub fn get (&self, x: usize, y: usize) -> Option<&Cell> {
let i = self.index_of(x, y);
self.content.get(i)
}
pub fn get_mut (&mut self, x: usize, y: usize) -> Option<&mut Cell> {
let i = self.index_of(x, y);
self.content.get_mut(i)
}
pub fn index_of (&self, x: usize, y: usize) -> usize {
y * self.width + x
}
}
//tester.focus_right();
//assert_eq!(tester.cursor.0, 3);
//assert_eq!(tester.focused, 'b');
from!(|size:(usize, usize)| BigBuffer = Self::new(size.0, size.1));
//tester.focus_down();
//assert_eq!(tester.cursor.1, 2);
//assert_eq!(tester.focused, 'c');
//}
//}
//use crate::*;
//struct TestEngine([u16;4], Vec<Vec<char>>);
//impl Engine for TestEngine {
//type Unit = u16;
//type Size = [Self::Unit;2];
//type Area = [Self::Unit;4];
//type Input = Self;
//type Handled = bool;
//fn exited (&self) -> bool {
//true
//}
//}
//#[derive(Copy, Clone)]
//struct TestArea(u16, u16);
//impl Render<TestEngine> for TestArea {
//fn min_size (&self, to: [u16;2]) -> Perhaps<[u16;2]> {
//Ok(Some([to[0], to[1], self.0, self.1]))
//}
//fn render (&self, to: &mut TestEngine) -> Perhaps<[u16;4]> {
//if let Some(layout) = self.layout(to.area())? {
//for y in layout.y()..layout.y()+layout.h()-1 {
//for x in layout.x()..layout.x()+layout.w()-1 {
//to.1[y as usize][x as usize] = '*';
//}
//}
//Ok(Some(layout))
//} else {
//Ok(None)
//}
//}
//}
//#[test]
//fn test_plus_minus () -> Usually<()> {
//let area = [0, 0, 10, 10];
//let engine = TestEngine(area, vec![vec![' ';10];10]);
//let test = TestArea(4, 4);
//assert_eq!(test.layout(area)?, Some([0, 0, 4, 4]));
//assert_eq!(Push::X(1, test).layout(area)?, Some([1, 0, 4, 4]));
//Ok(())
//}
//#[test]
//fn test_outset_align () -> Usually<()> {
//let area = [0, 0, 10, 10];
//let engine = TestEngine(area, vec![vec![' ';10];10]);
//let test = TestArea(4, 4);
//assert_eq!(test.layout(area)?, Some([0, 0, 4, 4]));
//assert_eq!(Margin::X(1, test).layout(area)?, Some([0, 0, 6, 4]));
//assert_eq!(Align::X(test).layout(area)?, Some([3, 0, 4, 4]));
//assert_eq!(Align::X(Margin::X(1, test)).layout(area)?, Some([2, 0, 6, 4]));
//assert_eq!(Margin::X(1, Align::X(test)).layout(area)?, Some([2, 0, 6, 4]));
//Ok(())
//}
////#[test]
////fn test_misc () -> Usually<()> {
////let area: [u16;4] = [0, 0, 10, 10];
////let test = TestArea(4, 4);
////assert_eq!(test.layout(area)?,
////Some([0, 0, 4, 4]));
////assert_eq!(Align::Center(test).layout(area)?,
////Some([3, 3, 4, 4]));
////assert_eq!(Align::Center(Stack::down(|add|{
////add(&test)?;
////add(&test)
////})).layout(area)?,
////Some([3, 1, 4, 8]));
////assert_eq!(Align::Center(Stack::down(|add|{
////add(&Margin::XY(2, 2, test))?;
////add(&test)
////})).layout(area)?,
////Some([2, 0, 6, 10]));
////assert_eq!(Align::Center(Stack::down(|add|{
////add(&Margin::XY(2, 2, test))?;
////add(&Padding::XY(2, 2, test))
////})).layout(area)?,
////Some([2, 1, 6, 8]));
////assert_eq!(Stack::down(|add|{
////add(&Margin::XY(2, 2, test))?;
////add(&Padding::XY(2, 2, test))
////}).layout(area)?,
////Some([0, 0, 6, 8]));
////assert_eq!(Stack::right(|add|{
////add(&Stack::down(|add|{
////add(&Margin::XY(2, 2, test))?;
////add(&Padding::XY(2, 2, test))
////}))?;
////add(&Align::Center(TestArea(2 ,2)))
////}).layout(area)?,
////Some([0, 0, 8, 8]));
////Ok(())
////}
////#[test]
////fn test_offset () -> Usually<()> {
////let area: [u16;4] = [50, 50, 100, 100];
////let test = TestArea(3, 3);
////assert_eq!(Push::X(1, test).layout(area)?, Some([51, 50, 3, 3]));
////assert_eq!(Push::Y(1, test).layout(area)?, Some([50, 51, 3, 3]));
////assert_eq!(Push::XY(1, 1, test).layout(area)?, Some([51, 51, 3, 3]));
////Ok(())
////}
////#[test]
////fn test_outset () -> Usually<()> {
////let area: [u16;4] = [50, 50, 100, 100];
////let test = TestArea(3, 3);
////assert_eq!(Margin::X(1, test).layout(area)?, Some([49, 50, 5, 3]));
////assert_eq!(Margin::Y(1, test).layout(area)?, Some([50, 49, 3, 5]));
////assert_eq!(Margin::XY(1, 1, test).layout(area)?, Some([49, 49, 5, 5]));
////Ok(())
////}
////#[test]
////fn test_padding () -> Usually<()> {
////let area: [u16;4] = [50, 50, 100, 100];
////let test = TestArea(3, 3);
////assert_eq!(Padding::X(1, test).layout(area)?, Some([51, 50, 1, 3]));
////assert_eq!(Padding::Y(1, test).layout(area)?, Some([50, 51, 3, 1]));
////assert_eq!(Padding::XY(1, 1, test).layout(area)?, Some([51, 51, 1, 1]));
////Ok(())
////}
////#[test]
////fn test_stuff () -> Usually<()> {
////let area: [u16;4] = [0, 0, 100, 100];
////assert_eq!("1".layout(area)?,
////Some([0, 0, 1, 1]));
////assert_eq!("333".layout(area)?,
////Some([0, 0, 3, 1]));
////assert_eq!(Layers::new(|add|{add(&"1")?;add(&"333")}).layout(area)?,
////Some([0, 0, 3, 1]));
////assert_eq!(Stack::down(|add|{add(&"1")?;add(&"333")}).layout(area)?,
////Some([0, 0, 3, 2]));
////assert_eq!(Stack::right(|add|{add(&"1")?;add(&"333")}).layout(area)?,
////Some([0, 0, 4, 1]));
////assert_eq!(Stack::down(|add|{
////add(&Stack::right(|add|{add(&"1")?;add(&"333")}))?;
////add(&"55555")
////}).layout(area)?,
////Some([0, 0, 5, 2]));
////let area: [u16;4] = [1, 1, 100, 100];
////assert_eq!(Margin::X(1, Stack::right(|add|{add(&"1")?;add(&"333")})).layout(area)?,
////Some([0, 1, 6, 1]));
////assert_eq!(Margin::Y(1, Stack::right(|add|{add(&"1")?;add(&"333")})).layout(area)?,
////Some([1, 0, 4, 3]));
////assert_eq!(Margin::XY(1, 1, Stack::right(|add|{add(&"1")?;add(&"333")})).layout(area)?,
////Some([0, 0, 6, 3]));
////assert_eq!(Stack::down(|add|{
////add(&Margin::XY(1, 1, "1"))?;
////add(&Margin::XY(1, 1, "333"))
////}).layout(area)?,
////Some([1, 1, 5, 6]));
////let area: [u16;4] = [1, 1, 95, 100];
////assert_eq!(Align::Center(Stack::down(|add|{
////add(&Margin::XY(1, 1, "1"))?;
////add(&Margin::XY(1, 1, "333"))
////})).layout(area)?,
////Some([46, 48, 5, 6]));
////assert_eq!(Align::Center(Stack::down(|add|{
////add(&Layers::new(|add|{
//////add(&Margin::XY(1, 1, Background(Color::Rgb(0,128,0))))?;
////add(&Margin::XY(1, 1, "1"))?;
////add(&Margin::XY(1, 1, "333"))?;
//////add(&Background(Color::Rgb(0,128,0)))?;
////Ok(())
////}))?;
////add(&Layers::new(|add|{
//////add(&Margin::XY(1, 1, Background(Color::Rgb(0,0,128))))?;
////add(&Margin::XY(1, 1, "555"))?;
////add(&Margin::XY(1, 1, "777777"))?;
//////add(&Background(Color::Rgb(0,0,128)))?;
////Ok(())
////}))
////})).layout(area)?,
////Some([46, 48, 5, 6]));
////Ok(())
////}