mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-08 04:36:45 +01:00
wip: running interface in separate or combined mode
also disassociating render functions from state structs
This commit is contained in:
parent
f9218e887a
commit
d6bf840a1f
31 changed files with 905 additions and 532 deletions
49
src/sampler/handle.rs
Normal file
49
src/sampler/handle.rs
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
use crate::prelude::*;
|
||||
use super::Sampler;
|
||||
|
||||
pub fn handle (
|
||||
state: &mut Sampler,
|
||||
event: crossterm::event::Event
|
||||
) -> Result<(), Box<dyn Error>> {
|
||||
use crossterm::event::{Event, KeyCode, KeyModifiers};
|
||||
if let Event::Key(event) = event {
|
||||
match event.code {
|
||||
KeyCode::Char('c') => {
|
||||
if event.modifiers == KeyModifiers::CONTROL {
|
||||
state.exit = true;
|
||||
}
|
||||
},
|
||||
KeyCode::Down => {
|
||||
state.selected_sample = (state.selected_sample + 1) % state.samples.len();
|
||||
println!("{}", state.selected_sample);
|
||||
},
|
||||
KeyCode::Up => {
|
||||
if state.selected_sample == 0 {
|
||||
state.selected_sample = state.samples.len() - 1;
|
||||
} else {
|
||||
state.selected_sample = state.selected_sample - 1;
|
||||
}
|
||||
println!("{}", state.selected_sample);
|
||||
},
|
||||
KeyCode::Left => {
|
||||
if state.selected_column == 0 {
|
||||
state.selected_column = 6
|
||||
} else {
|
||||
state.selected_column = state.selected_column - 1;
|
||||
}
|
||||
},
|
||||
KeyCode::Right => {
|
||||
if state.selected_column == 6 {
|
||||
state.selected_column = 0
|
||||
} else {
|
||||
state.selected_column = state.selected_column + 1;
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
println!("{event:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
40
src/sampler/jack.rs
Normal file
40
src/sampler/jack.rs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
use crate::prelude::*;
|
||||
|
||||
pub struct Notifications;
|
||||
|
||||
impl NotificationHandler for Notifications {
|
||||
fn thread_init (&self, _: &Client) {
|
||||
}
|
||||
|
||||
fn shutdown (&mut self, status: ClientStatus, reason: &str) {
|
||||
}
|
||||
|
||||
fn freewheel (&mut self, _: &Client, is_enabled: bool) {
|
||||
}
|
||||
|
||||
fn sample_rate (&mut self, _: &Client, _: Frames) -> Control {
|
||||
Control::Quit
|
||||
}
|
||||
|
||||
fn client_registration (&mut self, _: &Client, name: &str, is_reg: bool) {
|
||||
}
|
||||
|
||||
fn port_registration (&mut self, _: &Client, port_id: PortId, is_reg: bool) {
|
||||
}
|
||||
|
||||
fn port_rename (&mut self, _: &Client, id: PortId, old: &str, new: &str) -> Control {
|
||||
Control::Continue
|
||||
}
|
||||
|
||||
fn ports_connected (&mut self, _: &Client, id_a: PortId, id_b: PortId, are: bool) {
|
||||
}
|
||||
|
||||
fn graph_reorder (&mut self, _: &Client) -> Control {
|
||||
Control::Continue
|
||||
}
|
||||
|
||||
fn xrun (&mut self, _: &Client) -> Control {
|
||||
Control::Continue
|
||||
}
|
||||
}
|
||||
|
||||
80
src/sampler/render.rs
Normal file
80
src/sampler/render.rs
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
use crate::prelude::*;
|
||||
use super::Sampler;
|
||||
|
||||
pub fn render (
|
||||
state: &mut Sampler,
|
||||
stdout: &mut Stdout,
|
||||
offset: (u16, u16),
|
||||
) -> Result<(), Box<dyn Error>> {
|
||||
render_toolbar(state, stdout, offset)?;
|
||||
render_table(state, stdout, offset)?;
|
||||
render_meters(state, stdout, offset)?;
|
||||
stdout.flush()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn render_toolbar (
|
||||
state: &mut Sampler,
|
||||
stdout: &mut Stdout,
|
||||
offset: (u16, u16),
|
||||
) -> Result<(), Box<dyn Error>> {
|
||||
stdout
|
||||
.queue(cursor::MoveTo(1, 0))?
|
||||
.queue(PrintStyledContent("Arrows".yellow().bold()))?
|
||||
.queue(cursor::MoveTo(1, 1))?
|
||||
.queue(PrintStyledContent("Navigate".yellow()))?
|
||||
|
||||
.queue(cursor::MoveTo(11, 0))?
|
||||
.queue(PrintStyledContent("Enter".yellow().bold()))?
|
||||
.queue(cursor::MoveTo(11, 1))?
|
||||
.queue(PrintStyledContent("Play sample".yellow()))?
|
||||
|
||||
.queue(cursor::MoveTo(24, 0))?
|
||||
.queue(PrintStyledContent("Ins/Del".yellow().bold()))?
|
||||
.queue(cursor::MoveTo(24, 1))?
|
||||
.queue(PrintStyledContent("Add/remove sample".yellow()))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn render_table (
|
||||
state: &mut Sampler,
|
||||
stdout: &mut Stdout,
|
||||
offset: (u16, u16),
|
||||
) -> Result<(), Box<dyn Error>> {
|
||||
stdout
|
||||
.queue(cursor::MoveTo(0, 3))?
|
||||
.queue(Print(
|
||||
" Name Rate Trigger Route"))?;
|
||||
for (i, sample) in state.samples.iter().enumerate() {
|
||||
let row = 4 + i as u16;
|
||||
for (j, (column, field)) in [
|
||||
(0, format!(" {:7} ", sample.name)),
|
||||
(9, format!(" {:.1}Hz ", sample.rate)),
|
||||
(18, format!(" MIDI C10 36 ")),
|
||||
(33, format!(" {:.1}dB -> Output ", sample.gain)),
|
||||
].into_iter().enumerate() {
|
||||
stdout.queue(cursor::MoveTo(column, row))?;
|
||||
if state.selected_sample == i && state.selected_column == j {
|
||||
stdout.queue(PrintStyledContent(field.to_string().bold().reverse()))?;
|
||||
} else {
|
||||
stdout.queue(PrintStyledContent(field.to_string().bold()))?;
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn render_meters (
|
||||
state: &mut Sampler,
|
||||
stdout: &mut Stdout,
|
||||
offset: (u16, u16),
|
||||
) -> Result<(), Box<dyn Error>> {
|
||||
for (i, sample) in state.samples.iter().enumerate() {
|
||||
let row = 4 + i as u16;
|
||||
stdout
|
||||
.queue(cursor::MoveTo(32, row))?
|
||||
.queue(PrintStyledContent("▁".green()))?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue