diff --git a/crates/tek_core/src/tui.rs b/crates/tek_core/src/tui.rs index f7afaa7c..bb401a2e 100644 --- a/crates/tek_core/src/tui.rs +++ b/crates/tek_core/src/tui.rs @@ -303,155 +303,6 @@ impl Widget for Background { } } -pub const COLOR_BG0: Color = Color::Rgb(30, 33, 36); -pub const COLOR_BG1: Color = Color::Rgb(41, 46, 57); -pub const COLOR_BG2: Color = Color::Rgb(46, 52, 64); -pub const COLOR_BG3: Color = Color::Rgb(59, 66, 82); -pub const COLOR_BG4: Color = Color::Rgb(67, 76, 94); -pub const COLOR_BG5: Color = Color::Rgb(76, 86, 106); - -pub trait Theme { - const BG0: Color; - const BG1: Color; - const BG2: Color; - const BG3: Color; - const BG4: Color; - const RED: Color; - const YELLOW: Color; - const GREEN: Color; - - const PLAYING: Color; - const SEPARATOR: Color; - - fn bg_hier (focused: bool, entered: bool) -> Color { - if focused && entered { - Self::BG3 - } else if focused { - Self::BG2 - } else { - Self::BG1 - } - } - - fn bg_hi (focused: bool, entered: bool) -> Color { - if focused && entered { - Self::BG2 - } else if focused { - Self::BG1 - } else { - Self::BG0 - } - } - - fn bg_lo (focused: bool, entered: bool) -> Color { - if focused && entered { - Self::BG1 - } else if focused { - Self::BG0 - } else { - Color::Reset - } - } - - fn style_hi (focused: bool, highlight: bool) -> Style { - if highlight && focused { - Style::default().yellow().not_dim() - } else if highlight { - Style::default().yellow().dim() - } else { - Style::default() - } - } -} - -pub struct Nord; - -impl Theme for Nord { - const BG0: Color = Color::Rgb(41, 46, 57); - const BG1: Color = Color::Rgb(46, 52, 64); - const BG2: Color = Color::Rgb(59, 66, 82); - const BG3: Color = Color::Rgb(67, 76, 94); - const BG4: Color = Color::Rgb(76, 86, 106); - const RED: Color = Color::Rgb(191, 97, 106); - const YELLOW: Color = Color::Rgb(235, 203, 139); - const GREEN: Color = Color::Rgb(163, 190, 140); - - const PLAYING: Color = Color::Rgb(60, 100, 50); - const SEPARATOR: Color = Color::Rgb(0, 0, 0); -} - -pub const GRAY: Style = Style { - fg: Some(Color::Gray), - bg: None, - underline_color: None, - add_modifier: Modifier::empty(), - sub_modifier: Modifier::empty(), -}; - -pub const GRAY_NOT_DIM: Style = Style { - fg: Some(Color::Gray), - bg: None, - underline_color: None, - add_modifier: Modifier::empty(), - sub_modifier: Modifier::DIM, -}; - -pub const DIM: Style = Style { - fg: None, - bg: None, - underline_color: None, - add_modifier: Modifier::DIM, - sub_modifier: Modifier::empty(), -}; - -pub const GRAY_DIM: Style = Style { - fg: Some(Color::Gray), - bg: None, - underline_color: None, - add_modifier: Modifier::DIM, - sub_modifier: Modifier::empty(), -}; - -pub const WHITE_NOT_DIM_BOLD: Style = Style { - fg: Some(Color::White), - bg: None, - underline_color: None, - add_modifier: Modifier::BOLD, - sub_modifier: Modifier::DIM, -}; - -pub const GRAY_NOT_DIM_BOLD: Style = Style { - fg: Some(Color::Gray), - bg: None, - underline_color: None, - add_modifier: Modifier::BOLD, - sub_modifier: Modifier::DIM, -}; - -pub const NOT_DIM: Style = Style { - fg: None, - bg: None, - underline_color: None, - add_modifier: Modifier::empty(), - sub_modifier: Modifier::DIM, -}; - -pub const NOT_DIM_GREEN: Style = Style { - fg: Some(Color::Rgb(96, 255, 32)), - bg: Some(COLOR_BG1), - underline_color: None, - add_modifier: Modifier::empty(), - sub_modifier: Modifier::DIM, -}; - -pub const NOT_DIM_BOLD: Style = Style { - fg: None, - bg: None, - underline_color: None, - add_modifier: Modifier::BOLD, - sub_modifier: Modifier::DIM, -}; - impl> Widget for Fixed { type Engine = Tui; fn layout (&self, to: [u16;4]) -> Perhaps<[u16;4]> { @@ -578,30 +429,19 @@ impl> Content for Inset { type Engine = Tui; fn content (&self) -> impl Widget { match self { - Self::X(x, inner) => - Plus::X(*x, Shrink::X(*x + *x, Align::X(inner as &dyn Widget))), - Self::Y(y, inner) => - Plus::Y(*y, Shrink::X(*y + *y, Align::Y(inner as &dyn Widget))), - Self::XY(x, y, inner) => - Plus::XY(*x, *y, Shrink::XY(*x, *y, Align::Center(inner as &dyn Widget))), + Self::X(x, inner) => Plus::X( + *x, Shrink::X(*x + *x, Align::X(inner as &dyn Widget)) + ), + Self::Y(y, inner) => Plus::Y( + *y, Shrink::X(*y + *y, Align::Y(inner as &dyn Widget)) + ), + Self::XY(x, y, inner) => Plus::XY( + *x, *y, Shrink::XY(*x, *y, Align::Center(inner as &dyn Widget)) + ), } } } -//impl> Widget for Inset { - //type Engine = Tui; - //fn layout (&self, to: [u16;4]) -> Perhaps<[u16;4]> { - //match self { - //Self::X(x, inner) => Shrink::X(*x + *x, Align::Center(inner as &dyn Widget)), - //Self::Y(y, inner) => Shrink::X(*y + *y, Align::Center(inner as &dyn Widget)), - //Self::XY(x, y, inner) => Shrink::XY(*x, *y, Align::Center(inner as &dyn Widget)), - //}.layout(to) - //} - //fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> { - //Ok(self.layout(to.area())?.map(|a|to.render_in(a, self.inner())).transpose()?.flatten()) - //} -//} - impl> Widget for Outset { type Engine = Tui; fn layout (&self, to: [u16;4]) -> Perhaps<[u16;4]> { @@ -875,3 +715,152 @@ border! { } } } + +pub const COLOR_BG0: Color = Color::Rgb(30, 33, 36); +pub const COLOR_BG1: Color = Color::Rgb(41, 46, 57); +pub const COLOR_BG2: Color = Color::Rgb(46, 52, 64); +pub const COLOR_BG3: Color = Color::Rgb(59, 66, 82); +pub const COLOR_BG4: Color = Color::Rgb(67, 76, 94); +pub const COLOR_BG5: Color = Color::Rgb(76, 86, 106); + +pub trait Theme { + const BG0: Color; + const BG1: Color; + const BG2: Color; + const BG3: Color; + const BG4: Color; + const RED: Color; + const YELLOW: Color; + const GREEN: Color; + + const PLAYING: Color; + const SEPARATOR: Color; + + fn bg_hier (focused: bool, entered: bool) -> Color { + if focused && entered { + Self::BG3 + } else if focused { + Self::BG2 + } else { + Self::BG1 + } + } + + fn bg_hi (focused: bool, entered: bool) -> Color { + if focused && entered { + Self::BG2 + } else if focused { + Self::BG1 + } else { + Self::BG0 + } + } + + fn bg_lo (focused: bool, entered: bool) -> Color { + if focused && entered { + Self::BG1 + } else if focused { + Self::BG0 + } else { + Color::Reset + } + } + + fn style_hi (focused: bool, highlight: bool) -> Style { + if highlight && focused { + Style::default().yellow().not_dim() + } else if highlight { + Style::default().yellow().dim() + } else { + Style::default() + } + } +} + +pub struct Nord; + +impl Theme for Nord { + const BG0: Color = Color::Rgb(41, 46, 57); + const BG1: Color = Color::Rgb(46, 52, 64); + const BG2: Color = Color::Rgb(59, 66, 82); + const BG3: Color = Color::Rgb(67, 76, 94); + const BG4: Color = Color::Rgb(76, 86, 106); + const RED: Color = Color::Rgb(191, 97, 106); + const YELLOW: Color = Color::Rgb(235, 203, 139); + const GREEN: Color = Color::Rgb(163, 190, 140); + + const PLAYING: Color = Color::Rgb(60, 100, 50); + const SEPARATOR: Color = Color::Rgb(0, 0, 0); +} + +pub const GRAY: Style = Style { + fg: Some(Color::Gray), + bg: None, + underline_color: None, + add_modifier: Modifier::empty(), + sub_modifier: Modifier::empty(), +}; + +pub const GRAY_NOT_DIM: Style = Style { + fg: Some(Color::Gray), + bg: None, + underline_color: None, + add_modifier: Modifier::empty(), + sub_modifier: Modifier::DIM, +}; + +pub const DIM: Style = Style { + fg: None, + bg: None, + underline_color: None, + add_modifier: Modifier::DIM, + sub_modifier: Modifier::empty(), +}; + +pub const GRAY_DIM: Style = Style { + fg: Some(Color::Gray), + bg: None, + underline_color: None, + add_modifier: Modifier::DIM, + sub_modifier: Modifier::empty(), +}; + +pub const WHITE_NOT_DIM_BOLD: Style = Style { + fg: Some(Color::White), + bg: None, + underline_color: None, + add_modifier: Modifier::BOLD, + sub_modifier: Modifier::DIM, +}; + +pub const GRAY_NOT_DIM_BOLD: Style = Style { + fg: Some(Color::Gray), + bg: None, + underline_color: None, + add_modifier: Modifier::BOLD, + sub_modifier: Modifier::DIM, +}; + +pub const NOT_DIM: Style = Style { + fg: None, + bg: None, + underline_color: None, + add_modifier: Modifier::empty(), + sub_modifier: Modifier::DIM, +}; + +pub const NOT_DIM_GREEN: Style = Style { + fg: Some(Color::Rgb(96, 255, 32)), + bg: Some(COLOR_BG1), + underline_color: None, + add_modifier: Modifier::empty(), + sub_modifier: Modifier::DIM, +}; + +pub const NOT_DIM_BOLD: Style = Style { + fg: None, + bg: None, + underline_color: None, + add_modifier: Modifier::BOLD, + sub_modifier: Modifier::DIM, +}; diff --git a/crates/tek_sequencer/src/arranger.rs b/crates/tek_sequencer/src/arranger.rs index f2ad46f7..aa449d18 100644 --- a/crates/tek_sequencer/src/arranger.rs +++ b/crates/tek_sequencer/src/arranger.rs @@ -230,8 +230,7 @@ impl Handle for Arranger { match from.event() { // mode_switch: switch the display mode key!(KeyCode::Char('`')) => { - self.mode.to_next(); - Ok(Some(true)) + self.mode.to_next() }, // cursor_up: move cursor up key!(KeyCode::Up) => { @@ -240,7 +239,6 @@ impl Handle for Arranger { _ => self.scene_prev(), }; self.show_phrase()?; - Ok(Some(true)) }, // cursor_down key!(KeyCode::Down) => { @@ -249,7 +247,6 @@ impl Handle for Arranger { _ => self.scene_next(), }; self.show_phrase()?; - Ok(Some(true)) }, // cursor left key!(KeyCode::Left) => { @@ -258,7 +255,6 @@ impl Handle for Arranger { _ => self.track_prev(), }; self.show_phrase()?; - Ok(Some(true)) }, // cursor right key!(KeyCode::Right) => { @@ -267,67 +263,45 @@ impl Handle for Arranger { _ => self.track_next(), }; self.show_phrase()?; - Ok(Some(true)) }, // increment: use next clip here key!(KeyCode::Char('.')) => { self.phrase_next(); - Ok(Some(true)) }, // decrement: use previous next clip here key!(KeyCode::Char(',')) => { self.phrase_prev(); - Ok(Some(true)) }, // decrement: use previous clip here key!(KeyCode::Enter) => { self.activate(); - Ok(Some(true)) }, // scene_add: add a new scene key!(Ctrl-KeyCode::Char('a')) => { self.scene_add(None)?; - Ok(Some(true)) }, // track_add: add a new scene key!(Ctrl-KeyCode::Char('t')) => { self.track_add(None)?; - Ok(Some(true)) }, // rename: add a new scene key!(KeyCode::Char('n')) => { self.rename_selected(); - Ok(Some(true)) }, // length: add a new scene key!(KeyCode::Char('l')) => { todo!(); - Ok(Some(true)) }, // color: set color of item at cursor key!(KeyCode::Char('c')) => { todo!(); - Ok(Some(true)) }, - _ => Ok(None) - } - } -} -/// Display mode of arranger -#[derive(PartialEq)] -pub enum ArrangerViewMode { VerticalExpanded, VerticalCompact1, VerticalCompact2, Horizontal } -/// Arranger display mode can be cycled -impl ArrangerViewMode { - /// Cycle arranger display mode - pub fn to_next (&mut self) { - *self = match self { - Self::VerticalExpanded => Self::VerticalCompact1, - Self::VerticalCompact1 => Self::VerticalCompact2, - Self::VerticalCompact2 => Self::Horizontal, - Self::Horizontal => Self::VerticalExpanded, + _ => return Ok(None) } + Ok(Some(true)) } } + impl Content for Arranger { type Engine = Tui; fn content (&self) -> impl Widget { @@ -360,6 +334,21 @@ impl Content for Arranger { }) } } +/// Display mode of arranger +#[derive(PartialEq)] +pub enum ArrangerViewMode { VerticalExpanded, VerticalCompact1, VerticalCompact2, Horizontal } +/// Arranger display mode can be cycled +impl ArrangerViewMode { + /// Cycle arranger display mode + pub fn to_next (&mut self) { + *self = match self { + Self::VerticalExpanded => Self::VerticalCompact1, + Self::VerticalCompact1 => Self::VerticalCompact2, + Self::VerticalCompact2 => Self::Horizontal, + Self::Horizontal => Self::VerticalExpanded, + } + } +} struct ArrangerViewVertical<'a, 'b, E: Engine>( &'a Arranger, &'b [(usize, usize)], &'b [(usize, usize)] @@ -503,16 +492,16 @@ struct TracksHeader<'a>( impl<'a> Content for TracksHeader<'a> { type Engine = Tui; fn content (&self) -> impl Widget { - let Self(_offset, columns, tracks) = *self; - Split::right(move |add|{ + let Self(offset, columns, tracks) = *self; + Plus::X(offset, Split::right(move |add|{ for (track, (w, _)) in tracks.iter().zip(columns) { - add(&Min::X(*w as u16, Layers::new(|add|{ + add(&Min::XY(*w as u16, 2, Layers::new(|add|{ add(&Background(COLOR_BG1))?; add(&track.name.read().unwrap().as_str()) })))?; } Ok(()) - }) + })) } } @@ -546,15 +535,16 @@ impl<'a> Content for SceneRow<'a> { let playing = scene.is_playing(tracks); Split::right(move |add| { add(&Layers::new(|add|{ - add(&Split::right(|add|{ - add(&if playing { "▶" } else { " " })?; - add(&scene.name.read().unwrap().as_str()) - }))?; - add(&Background(COLOR_BG1)) + //add(&Split::right(|add|{ + //add(&if playing { "▶" } else { " " })?; + add(&scene.name.read().unwrap().as_str())?; + //}))?; + //add(&Background(COLOR_BG1)) + Ok(()) }))?; - for (track, (_w, _x)) in columns.iter().enumerate() { - add(&SceneClip(tracks.get(track), scene.clips.get(track)))?; - } + //for (track, (_w, _x)) in columns.iter().enumerate() { + //add(&SceneClip(tracks.get(track), scene.clips.get(track)))?; + //} Ok(()) }) } @@ -589,8 +579,6 @@ struct ArrangerViewHorizontal<'a, E: Engine>( impl<'a> Content for ArrangerViewHorizontal<'a, Tui> { type Engine = Tui; fn content (&self) -> impl Widget { - //let area = to.area(); - //let area = [area.x(), area.y(), area.w(), area.h().min((2 + state.tracks.len() * 2) as u16)]; let Arranger { tracks, focused, selected, scenes, .. } = self.0; let tracks = tracks.as_slice(); Layers::new(|add|{ diff --git a/crates/tek_sequencer/src/arranger_main.rs b/crates/tek_sequencer/src/arranger_main.rs index f2c9d449..0695ca41 100644 --- a/crates/tek_sequencer/src/arranger_main.rs +++ b/crates/tek_sequencer/src/arranger_main.rs @@ -98,47 +98,35 @@ impl Handle for ArrangerStandalone { key!(KeyCode::Char(' ')) => { if let Some(ref mut transport) = self.transport { transport.toggle_play()?; - Ok(Some(true)) } else { - Ok(None) + return Ok(None) } }, key!(KeyCode::Tab) => { self.focus_next(); - Ok(Some(true)) }, key!(KeyCode::BackTab) => { self.focus_prev(); - Ok(Some(true)) }, key!(KeyCode::Down) => { if self.focus == 0 || ( self.focus == 1 && self.arranger.is_last_row() ) { self.focus_next(); - Ok(Some(true)) } else { - self.focused_mut().handle(from) + return self.focused_mut().handle(from) } }, key!(KeyCode::Up) => { if self.focus == 1 && self.arranger.is_first_row() { self.focus_prev(); - Ok(Some(true)) } else { - self.focused_mut().handle(from) + return self.focused_mut().handle(from) } }, - _ => self.focused_mut().handle(from) + _ => return self.focused_mut().handle(from) } - } -} - -struct SequencerProxy(Arc>>); - -impl Handle for SequencerProxy { - fn handle (&mut self, from: &Tui) -> Perhaps { - self.0.write().unwrap().handle(from) + Ok(Some(true)) } }