mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 19:56:42 +01:00
cleanup ports; horizontal scenes
This commit is contained in:
parent
b4fdddc0aa
commit
c3c6c13f57
5 changed files with 174 additions and 82 deletions
|
|
@ -50,9 +50,13 @@ impl AppPaths {
|
|||
pub struct SetupModal(pub Option<Arc<XdgApp>>);
|
||||
|
||||
render!(SetupModal |self, buf, area| {
|
||||
for cell in buf.content.iter_mut() {
|
||||
cell.fg = ratatui::style::Color::Gray;
|
||||
cell.modifier = ratatui::style::Modifier::DIM;
|
||||
}
|
||||
let lines = [
|
||||
(" ", Style::default().white().on_black().not_dim().bold()),
|
||||
(" Welcome to TEK. ", Style::default().white().on_black().not_dim().bold()),
|
||||
(" Welcome to TEK! ", Style::default().white().on_black().not_dim().bold()),
|
||||
(" ", Style::default().white().on_black().not_dim().bold()),
|
||||
(" Press ENTER to create the ", Style::default().white().on_black().not_dim()),
|
||||
(" following directories: ", Style::default().white().on_black().not_dim()),
|
||||
|
|
@ -62,6 +66,8 @@ render!(SetupModal |self, buf, area| {
|
|||
(" ", Style::default().white().on_black().not_dim()),
|
||||
(" Data directory: ", Style::default().white().on_black().not_dim()),
|
||||
(" ~/.local/share/tek ", Style::default().white().on_black().not_dim().bold()),
|
||||
(" ", Style::default().white().on_black().not_dim().bold()),
|
||||
(" Or press CTRL-C to exit. ", Style::default().white().on_black().not_dim()),
|
||||
(" ", Style::default().white().on_black().not_dim()),
|
||||
];
|
||||
let width = lines[0].0.len() as u16;
|
||||
|
|
|
|||
|
|
@ -42,4 +42,3 @@ fn select (state: &mut Sampler) -> Usually<bool> {
|
|||
}
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
|
|
|
|||
97
src/main.rs
97
src/main.rs
|
|
@ -78,6 +78,9 @@ pub fn main () -> Usually<()> {
|
|||
})),
|
||||
]))?,
|
||||
];
|
||||
state.track_cursor = 1;
|
||||
state.scene_cursor = 1;
|
||||
state.midi_in = Some(jack.as_client().register_port("midi-in", MidiIn)?);
|
||||
state.jack = Some(jack);
|
||||
Ok(())
|
||||
}))
|
||||
|
|
@ -85,17 +88,21 @@ pub fn main () -> Usually<()> {
|
|||
|
||||
#[derive(Default)]
|
||||
pub struct App {
|
||||
pub xdg: Option<Arc<XdgApp>>,
|
||||
pub jack: Option<DynamicAsyncClient>,
|
||||
pub scene: usize,
|
||||
pub scenes: Vec<Scene>,
|
||||
pub xdg: Option<Arc<XdgApp>>,
|
||||
pub jack: Option<DynamicAsyncClient>,
|
||||
pub grid_mode: bool,
|
||||
pub chain_mode: bool,
|
||||
pub seq_mode: bool,
|
||||
pub scenes: Vec<Scene>,
|
||||
pub scene_cursor: usize,
|
||||
pub tracks: Vec<Track>,
|
||||
pub track_cursor: usize,
|
||||
pub tracks: Vec<Track>,
|
||||
pub frame: usize,
|
||||
pub timebase: Arc<Timebase>,
|
||||
pub modal: Option<Box<dyn Component>>,
|
||||
pub section: usize,
|
||||
pub entered: bool,
|
||||
pub frame: usize,
|
||||
pub timebase: Arc<Timebase>,
|
||||
pub modal: Option<Box<dyn Component>>,
|
||||
pub section: usize,
|
||||
pub entered: bool,
|
||||
pub midi_in: Option<Port<MidiIn>>,
|
||||
}
|
||||
|
||||
process!(App);
|
||||
|
|
@ -116,10 +123,11 @@ render!(App |self, buf, area| {
|
|||
buf,
|
||||
area: Rect { x, y, width, height: height / 3 },
|
||||
name: "",
|
||||
mode: self.grid_mode,
|
||||
focused: self.section == 0,
|
||||
scenes: &self.scenes,
|
||||
tracks: &self.tracks,
|
||||
cursor: &(self.track_cursor, self.scene + 1)
|
||||
cursor: &(self.track_cursor, self.scene_cursor),
|
||||
}.draw()?.height;
|
||||
|
||||
if self.track_cursor > 0 {
|
||||
|
|
@ -138,10 +146,6 @@ render!(App |self, buf, area| {
|
|||
}
|
||||
|
||||
if let Some(ref modal) = self.modal {
|
||||
for cell in buf.content.iter_mut() {
|
||||
cell.fg = ratatui::style::Color::Gray;
|
||||
cell.modifier = ratatui::style::Modifier::DIM;
|
||||
}
|
||||
modal.render(buf, area)?;
|
||||
}
|
||||
|
||||
|
|
@ -155,29 +159,41 @@ handle!(App |self, e| {
|
|||
return Ok(true)
|
||||
};
|
||||
}
|
||||
handle_keymap(self, e, keymap!(App {
|
||||
[F(1), NONE, "toggle_help", "toggle help", toggle_help],
|
||||
[Tab, NONE, "focus_next", "focus next area", focus_next],
|
||||
[Tab, SHIFT, "focus_prev", "focus previous area", focus_prev],
|
||||
[Up, NONE, "cursor_up", "move cursor up", cursor_up],
|
||||
[Down, NONE, "cursor_down", "move cursor down", cursor_down],
|
||||
[Left, NONE, "cursor_left", "move cursor left", cursor_left],
|
||||
[Right, NONE, "cursor_right", "move cursor right", cursor_right],
|
||||
[Char('.'), NONE, "increment", "increment value at cursor", increment],
|
||||
[Char(','), NONE, "decrement", "decrement value at cursor", decrement],
|
||||
[Delete, CONTROL, "delete", "delete track", delete],
|
||||
[Char('d'), CONTROL, "duplicate", "duplicate scene or track", duplicate],
|
||||
[Enter, NONE, "activate", "activate item at cursor", activate],
|
||||
[Char(' '), NONE, "play_toggle", "play or pause", play_toggle],
|
||||
[Char('r'), NONE, "record_toggle", "toggle recording", record_toggle],
|
||||
[Char('d'), NONE, "overdub_toggle", "toggle overdub", overdub_toggle],
|
||||
[Char('m'), NONE, "monitor_toggle", "toggle input monitoring", monitor_toggle],
|
||||
[Char('r'), CONTROL, "rename", "rename current element", rename],
|
||||
[Char('t'), CONTROL, "add_track", "add a new track", add_track],
|
||||
//[Char(' '), SHIFT, "play_start", "play from start", play_start],
|
||||
}))
|
||||
handle_keymap(self, e, KEYMAP)
|
||||
});
|
||||
|
||||
const KEYMAP: &'static [KeyBinding<App>] = keymap!(App {
|
||||
[F(1), NONE, "toggle_help", "toggle help", toggle_help],
|
||||
[Tab, NONE, "focus_next", "focus next area", focus_next],
|
||||
[Tab, SHIFT, "focus_prev", "focus previous area", focus_prev],
|
||||
[Up, NONE, "cursor_up", "move cursor up", cursor_up],
|
||||
[Down, NONE, "cursor_down", "move cursor down", cursor_down],
|
||||
[Left, NONE, "cursor_left", "move cursor left", cursor_left],
|
||||
[Right, NONE, "cursor_right", "move cursor right", cursor_right],
|
||||
[Char('.'), NONE, "increment", "increment value at cursor", increment],
|
||||
[Char(','), NONE, "decrement", "decrement value at cursor", decrement],
|
||||
[Delete, CONTROL, "delete", "delete track", delete],
|
||||
[Char('d'), CONTROL, "duplicate", "duplicate scene or track", duplicate],
|
||||
[Enter, NONE, "activate", "activate item at cursor", activate],
|
||||
[Char(' '), NONE, "play_toggle", "play or pause", play_toggle],
|
||||
[Char('r'), NONE, "record_toggle", "toggle recording", record_toggle],
|
||||
[Char('d'), NONE, "overdub_toggle", "toggle overdub", overdub_toggle],
|
||||
[Char('m'), NONE, "monitor_toggle", "toggle input monitoring", monitor_toggle],
|
||||
[Char('r'), CONTROL, "rename", "rename current element", rename],
|
||||
[Char('t'), CONTROL, "add_track", "add a new track", add_track],
|
||||
[Char('a'), CONTROL, "add_scene", "add a new scene", add_scene],
|
||||
[Char('`'), NONE, "switch_mode", "switch the display mode", switch_mode],
|
||||
//[Char(' '), SHIFT, "play_start", "play from start", play_start],
|
||||
});
|
||||
|
||||
fn switch_mode (app: &mut App) -> Usually<bool> {
|
||||
match app.section {
|
||||
0 => {app.grid_mode = !app.grid_mode; Ok(true)},
|
||||
1 => {app.chain_mode = !app.chain_mode; Ok(true)},
|
||||
2 => {app.seq_mode = !app.seq_mode; Ok(true)},
|
||||
_ => Ok(false)
|
||||
}
|
||||
}
|
||||
fn focus_next (app: &mut App) -> Usually<bool> {
|
||||
if app.section >= 2 {
|
||||
app.section = 0;
|
||||
|
|
@ -247,6 +263,12 @@ fn delete (app: &mut App) -> Usually<bool> {
|
|||
fn duplicate (_: &mut App) -> Usually<bool> { Ok(true) }
|
||||
fn activate (_: &mut App) -> Usually<bool> { Ok(true) }
|
||||
fn rename (_: &mut App) -> Usually<bool> { Ok(true) }
|
||||
fn add_scene (app: &mut App) -> Usually<bool> {
|
||||
let name = format!("Scene {}", app.scenes.len() + 1);
|
||||
app.scenes.push(Scene::new(&name, vec![]));
|
||||
app.scene_cursor = app.scenes.len() - 1;
|
||||
Ok(true)
|
||||
}
|
||||
fn add_track (app: &mut App) -> Usually<bool> {
|
||||
let name = format!("Track {}", app.tracks.len() + 1);
|
||||
app.tracks.push(Track::new(&name, app.jack.as_ref().unwrap().as_client(), &app.timebase, None, None)?);
|
||||
|
|
@ -255,8 +277,9 @@ fn add_track (app: &mut App) -> Usually<bool> {
|
|||
}
|
||||
fn delete_track (app: &mut App) -> Usually<bool> {
|
||||
if app.tracks.len() > 0 {
|
||||
app.tracks.remove(app.track_cursor);
|
||||
let track = app.tracks.remove(app.track_cursor);
|
||||
app.track_cursor = app.track_cursor.saturating_sub(1);
|
||||
app.jack.as_ref().unwrap().as_client().unregister_port(track.midi_out)?;
|
||||
return Ok(true)
|
||||
}
|
||||
Ok(false)
|
||||
|
|
|
|||
147
src/view/grid.rs
147
src/view/grid.rs
|
|
@ -9,38 +9,105 @@ pub struct SceneGridView<'a> {
|
|||
pub scenes: &'a[Scene],
|
||||
pub tracks: &'a[Track],
|
||||
pub cursor: &'a(usize, usize),
|
||||
pub mode: bool,
|
||||
}
|
||||
impl<'a> SceneGridView<'a> {
|
||||
pub fn new (
|
||||
buf: &'a mut Buffer,
|
||||
area: Rect,
|
||||
name: &'a str,
|
||||
focused: bool,
|
||||
scenes: &'a[Scene],
|
||||
tracks: &'a[Track],
|
||||
cursor: &'a(usize, usize),
|
||||
) -> Self {
|
||||
Self {
|
||||
buf,
|
||||
area,
|
||||
name,
|
||||
focused,
|
||||
scenes,
|
||||
tracks,
|
||||
cursor,
|
||||
fn longest_scene_name (&self) -> u16 {
|
||||
let mut w = 3u16;
|
||||
for scene in self.scenes.iter() {
|
||||
w = w.max(scene.name.len() as u16);
|
||||
}
|
||||
w
|
||||
}
|
||||
|
||||
fn longest_track_name (&self) -> u16 {
|
||||
let mut w = 3u16;
|
||||
for track in self.tracks.iter() {
|
||||
w = w.max(track.name.len() as u16);
|
||||
}
|
||||
w
|
||||
}
|
||||
|
||||
pub fn size_horizontal (&mut self) -> (u16, u16) {
|
||||
let (mut w, mut h) = (4, 2);
|
||||
w = w + self.longest_track_name();
|
||||
w = w + self.scenes.len() as u16 * 10;
|
||||
h = h + self.tracks.len();
|
||||
(w as u16, h as u16)
|
||||
}
|
||||
|
||||
pub fn draw (&mut self) -> Usually<Rect> {
|
||||
match self.mode {
|
||||
true => self.draw_horizontal(),
|
||||
false => self.draw_vertical(),
|
||||
}
|
||||
}
|
||||
pub fn draw (&mut self) -> Usually<Rect> {
|
||||
self.area.height = self.scenes.len() as u16 + 2;
|
||||
|
||||
pub fn draw_horizontal (&mut self) -> Usually<Rect> {
|
||||
let (w, h) = self.size_horizontal();
|
||||
//self.area.x = self.area.x + self.area.width.saturating_sub(w) / 2;
|
||||
self.area.height = self.tracks.len() as u16 + 2;
|
||||
//self.area.width = w;
|
||||
let style = Some(Style::default().green().dim());
|
||||
if self.focused {
|
||||
let Rect { x, y, width, height } = self.area;
|
||||
lozenge_left(self.buf, x, y, height, style);
|
||||
lozenge_right(self.buf, x + width - 1, y, height, style);
|
||||
}
|
||||
let columns = self.column_names();
|
||||
" Mix ".blit(self.buf,self.area.x+1,self.area.y,Some(Style::default().bold().not_dim().white()));
|
||||
let mut x2 = 0;
|
||||
for (i, track) in self.tracks.iter().enumerate() {
|
||||
let label = format!(" {} ", &track.name);
|
||||
label.blit(self.buf, self.area.x+1, self.area.y+1+i as u16, Some(Style::default().bold()));
|
||||
x2 = x2.max(label.len() as u16 + 1);
|
||||
}
|
||||
"╷".blit(self.buf, self.area.x + x2, self.area.y, style);
|
||||
for y in self.area.y+1..self.area.y+self.area.height-1 {
|
||||
"│".blit(self.buf, self.area.x + x2, y, style);
|
||||
}
|
||||
//"╵".blit(self.buf, self.area.x + x2, self.area.y+self.area.height-1, style);
|
||||
x2 = x2 + 1;
|
||||
for scene in self.scenes.iter() {
|
||||
let label = format!("{}", &scene.name);
|
||||
let mut x3 = label.len() as u16;
|
||||
label.blit(self.buf, self.area.x + x2, self.area.y, Some(Style::default().bold()));
|
||||
for (i, clip) in scene.clips.iter().enumerate() {
|
||||
if let Some(clip) = clip {
|
||||
if let Some(phrase) = self.tracks[i].sequencer.phrases.get(*clip) {
|
||||
let label = format!("{}", &phrase.name);
|
||||
label.blit(self.buf, self.area.x + x2, self.area.y + 1 + i as u16, None);
|
||||
x3 = x3.max(label.len() as u16)
|
||||
}
|
||||
}
|
||||
}
|
||||
x2 = x2 + x3;
|
||||
|
||||
"╷".blit(self.buf, self.area.x + x2, self.area.y, style);
|
||||
for y in self.area.y+1..self.area.y+self.area.height-1 {
|
||||
"┊".blit(self.buf, self.area.x + x2, y, style);
|
||||
}
|
||||
//"╵".blit(self.buf, self.area.x + x2, self.area.y+self.area.height-1, style);
|
||||
x2 = x2 + 1;
|
||||
}
|
||||
if self.focused {
|
||||
HELP.blit(self.buf, self.area.x + 2, self.area.y + self.area.height - 1, Some(Style::default().dim()));
|
||||
}
|
||||
Ok(self.area)
|
||||
}
|
||||
|
||||
pub fn draw_vertical (&mut self) -> Usually<Rect> {
|
||||
let width = self.area.width.min(4 + HELP.len() as u16);
|
||||
self.area.height = self.scenes.len() as u16 + 2;
|
||||
//self.area.x = self.area.x + self.area.width.saturating_sub(width) / 2;
|
||||
let style = Some(Style::default().green().dim());
|
||||
if self.focused {
|
||||
let Rect { x, y, width, height } = self.area;
|
||||
lozenge_left(self.buf, x, y, height, style);
|
||||
lozenge_right(self.buf, x + width - 1, y, height, style);
|
||||
}
|
||||
let columns = self.track_names();
|
||||
let mut x = self.area.x;
|
||||
for (i, w) in self.column_widths().iter().enumerate() {
|
||||
for (i, w) in self.track_widths().iter().enumerate() {
|
||||
if x >= self.area.x + self.area.width {
|
||||
break
|
||||
}
|
||||
|
|
@ -64,20 +131,22 @@ impl<'a> SceneGridView<'a> {
|
|||
let w = (title.len() as u16).max(10) + 3;
|
||||
x = x + w;
|
||||
}
|
||||
"[C-t] Add track…".blit(self.buf, x + 2, y + 1, Some(Style::default().dim()));
|
||||
if self.focused {
|
||||
HELP.blit(self.buf, self.area.x + 2, self.area.y + self.area.height - 1, Some(Style::default().dim()));
|
||||
}
|
||||
Ok(self.area)
|
||||
}
|
||||
|
||||
fn column_names (&self) -> Vec<&'a str> {
|
||||
let mut column_names = vec![self.name];
|
||||
fn track_names (&self) -> Vec<&'a str> {
|
||||
let mut track_names = vec!["Mix"];
|
||||
for track in self.tracks.iter() {
|
||||
column_names.push(track.name.as_str());
|
||||
track_names.push(track.name.as_str());
|
||||
}
|
||||
column_names
|
||||
track_names
|
||||
}
|
||||
|
||||
fn column_widths (&self) -> Vec<u16> {
|
||||
self.column_names().iter().map(|name|(name.len() as u16).max(10) + 3).collect()
|
||||
fn track_widths (&self) -> Vec<u16> {
|
||||
self.track_names().iter().map(|name|(name.len() as u16).max(10) + 3).collect()
|
||||
}
|
||||
|
||||
fn scenes (&mut self, x: u16, y: u16) -> u16 {
|
||||
|
|
@ -98,13 +167,6 @@ impl<'a> SceneGridView<'a> {
|
|||
}
|
||||
index = index + 1;
|
||||
}
|
||||
let hi = (0 == self.cursor.0) &&
|
||||
(self.scenes.len() + 1 == self.cursor.1);
|
||||
"[Add scene…]".blit(self.buf, x, y + index as u16, Some(if hi {
|
||||
self.highlight(true)
|
||||
} else {
|
||||
Style::default().dim()
|
||||
}));
|
||||
index as u16
|
||||
}
|
||||
|
||||
|
|
@ -136,13 +198,13 @@ impl<'a> SceneGridView<'a> {
|
|||
}
|
||||
index = index + 1;
|
||||
}
|
||||
let hi = (track + 1 == self.cursor.0) &&
|
||||
(self.scenes.len() + 1 == self.cursor.1);
|
||||
"[Add clip…]".blit(self.buf, x, y + index as u16, Some(if hi {
|
||||
self.highlight(true)
|
||||
} else {
|
||||
Style::default().dim()
|
||||
}));
|
||||
//let hi = (track + 1 == self.cursor.0) &&
|
||||
//(self.scenes.len() + 1 == self.cursor.1);
|
||||
//"[Add clip…]".blit(self.buf, x, y + index as u16, Some(if hi {
|
||||
//self.highlight(true)
|
||||
//} else {
|
||||
//Style::default().dim()
|
||||
//}));
|
||||
index as u16
|
||||
}
|
||||
|
||||
|
|
@ -166,3 +228,4 @@ impl<'a> SceneGridView<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
const HELP: &'static str = "[C-t] Add track [C-a] Add scene [v] Show/hide track";
|
||||
|
|
|
|||
|
|
@ -17,12 +17,13 @@ pub fn render (state: &Launcher, buf: &mut Buffer, mut area: Rect) -> Usually<Re
|
|||
y = y + SceneGridView {
|
||||
buf,
|
||||
area: Rect { x, y, width, height },
|
||||
mode: false,
|
||||
name: &state.name,
|
||||
focused: state.view.is_tracks(),
|
||||
scenes: &state.scenes,
|
||||
tracks: &state.tracks,
|
||||
cursor: &state.cursor
|
||||
}.draw()?.height;
|
||||
}.draw_vertical()?.height;
|
||||
|
||||
if let Some(chain) = state.chain() {
|
||||
y = y + ChainView {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue