mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
draw in sequencer
This commit is contained in:
parent
31f8ec5362
commit
b6c093b355
3 changed files with 62 additions and 38 deletions
|
|
@ -17,7 +17,13 @@ pub struct Sequencer {
|
||||||
exited: bool,
|
exited: bool,
|
||||||
jack: Jack<Notifications>,
|
jack: Jack<Notifications>,
|
||||||
cursor: (u16, u16, u16),
|
cursor: (u16, u16, u16),
|
||||||
sequence: Vec<()>,
|
sequence: Vec<Vec<Option<Event>>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub enum Event {
|
||||||
|
NoteOn(u8, u8),
|
||||||
|
NoteOff(u8)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Sequencer {
|
impl Sequencer {
|
||||||
|
|
@ -38,7 +44,7 @@ impl Sequencer {
|
||||||
exited: false,
|
exited: false,
|
||||||
cursor: (0, 0, 0),
|
cursor: (0, 0, 0),
|
||||||
jack,
|
jack,
|
||||||
sequence: vec![],
|
sequence: vec![vec![None;64];4],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,34 @@ pub fn handle (state: &mut Sequencer,event: &Event) -> Result<(), Box<dyn Error>
|
||||||
state.exit();
|
state.exit();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
KeyCode::Down => {
|
||||||
|
state.cursor.0 = if state.cursor.0 >= 3 {
|
||||||
|
0
|
||||||
|
} else {
|
||||||
|
state.cursor.0 + 1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
KeyCode::Up => {
|
||||||
|
state.cursor.0 = if state.cursor.0 == 0 {
|
||||||
|
3
|
||||||
|
} else {
|
||||||
|
state.cursor.0 - 1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
KeyCode::Left => {
|
||||||
|
state.cursor.1 = if state.cursor.1 == 0 {
|
||||||
|
63
|
||||||
|
} else {
|
||||||
|
state.cursor.1 - 1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
KeyCode::Right => {
|
||||||
|
state.cursor.1 = if state.cursor.1 == 63 {
|
||||||
|
0
|
||||||
|
} else {
|
||||||
|
state.cursor.1 + 1
|
||||||
|
}
|
||||||
|
},
|
||||||
KeyCode::Char('[') => {
|
KeyCode::Char('[') => {
|
||||||
if state.cursor.2 > 0 {
|
if state.cursor.2 > 0 {
|
||||||
state.cursor.2 = state.cursor.2 - 1
|
state.cursor.2 = state.cursor.2 - 1
|
||||||
|
|
@ -19,36 +47,15 @@ pub fn handle (state: &mut Sequencer,event: &Event) -> Result<(), Box<dyn Error>
|
||||||
KeyCode::Char(']') => {
|
KeyCode::Char(']') => {
|
||||||
state.cursor.2 = state.cursor.2 + 1
|
state.cursor.2 = state.cursor.2 + 1
|
||||||
},
|
},
|
||||||
KeyCode::Down => {
|
KeyCode::Char('a') => {
|
||||||
state.cursor.1 = if state.cursor.1 >= 3 {
|
let row = state.cursor.0 as usize;
|
||||||
0
|
let step = state.cursor.1 as usize;
|
||||||
} else {
|
let duration = state.cursor.2 as usize;
|
||||||
state.cursor.1 + 1
|
state.sequence[row][step] = Some(super::Event::NoteOn(35, 128));
|
||||||
|
if state.cursor.2 > 0 {
|
||||||
|
state.sequence[row][step + duration] = Some(super::Event::NoteOff(35));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
KeyCode::Up => {
|
|
||||||
state.cursor.1 = if state.cursor.1 == 0 {
|
|
||||||
3
|
|
||||||
} else {
|
|
||||||
state.cursor.1 - 1
|
|
||||||
}
|
|
||||||
},
|
|
||||||
KeyCode::Left => {
|
|
||||||
state.cursor.0 = if state.cursor.0 == 0 {
|
|
||||||
63
|
|
||||||
} else {
|
|
||||||
state.cursor.0 - 1
|
|
||||||
}
|
|
||||||
},
|
|
||||||
KeyCode::Right => {
|
|
||||||
state.cursor.0 = if state.cursor.0 == 63 {
|
|
||||||
0
|
|
||||||
} else {
|
|
||||||
state.cursor.0 + 1
|
|
||||||
}
|
|
||||||
},
|
|
||||||
KeyCode::Char('A') => {
|
|
||||||
},
|
|
||||||
_ => {
|
_ => {
|
||||||
println!("{event:?}");
|
println!("{event:?}");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ fn render_grid (
|
||||||
let move_to = |col, row| crossterm::cursor::MoveTo(offset.0 + col, offset.1 + row);
|
let move_to = |col, row| crossterm::cursor::MoveTo(offset.0 + col, offset.1 + row);
|
||||||
let bg = "┊···············┊···············┊···············┊···············";
|
let bg = "┊···············┊···············┊···············┊···············";
|
||||||
let cursor: String = if state.cursor.2 == 0 {
|
let cursor: String = if state.cursor.2 == 0 {
|
||||||
"X".into()
|
"❱".into()
|
||||||
} else {
|
} else {
|
||||||
std::iter::repeat("·")
|
std::iter::repeat("·")
|
||||||
.take(state.cursor.2 as usize)
|
.take(state.cursor.2 as usize)
|
||||||
|
|
@ -30,12 +30,23 @@ fn render_grid (
|
||||||
.queue(move_to(1, 3))?.queue(Print("1.1"))?
|
.queue(move_to(1, 3))?.queue(Print("1.1"))?
|
||||||
.queue(move_to(17, 3))?.queue(Print("1.2"))?
|
.queue(move_to(17, 3))?.queue(Print("1.2"))?
|
||||||
.queue(move_to(33, 3))?.queue(Print("1.3"))?
|
.queue(move_to(33, 3))?.queue(Print("1.3"))?
|
||||||
.queue(move_to(49, 3))?.queue(Print("1.4"))?
|
.queue(move_to(49, 3))?.queue(Print("1.4"))?;
|
||||||
.queue(move_to(1, 4))?.queue(PrintStyledContent(bg.grey()))?
|
for (index, row) in state.sequence.iter().enumerate() {
|
||||||
.queue(move_to(1, 5))?.queue(PrintStyledContent(bg.grey()))?
|
let y = index as u16 + 4;
|
||||||
.queue(move_to(1, 6))?.queue(PrintStyledContent(bg.grey()))?
|
stdout.queue(move_to(1, y))?.queue(
|
||||||
.queue(move_to(1, 7))?.queue(PrintStyledContent(bg.grey()))?
|
PrintStyledContent(bg.grey())
|
||||||
.queue(move_to(1 + state.cursor.0, 4 + state.cursor.1))?
|
)?;
|
||||||
|
for (index, step) in row.iter().enumerate() {
|
||||||
|
if step.is_some() {
|
||||||
|
let x = index as u16 + 1;
|
||||||
|
stdout.queue(move_to(x, y))?.queue(
|
||||||
|
PrintStyledContent("X".white().bold())
|
||||||
|
)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stdout
|
||||||
|
.queue(move_to(1 + state.cursor.1, 4 + state.cursor.0))?
|
||||||
.queue(PrintStyledContent(cursor.reverse()))?;
|
.queue(PrintStyledContent(cursor.reverse()))?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue