mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-08 20:56:43 +01:00
wip: big flat
This commit is contained in:
parent
8cbe621b07
commit
4a3de618d0
20 changed files with 305 additions and 336 deletions
|
|
@ -2,7 +2,7 @@ use crate::*;
|
|||
use super::*;
|
||||
use KeyCode::{Char, Delete, Tab, Up, Down, Left, Right};
|
||||
use ClockCommand::{Play, Pause};
|
||||
use GrooveboxCommand::*;
|
||||
use GrooveboxCommand as Cmd;
|
||||
use PhraseCommand::*;
|
||||
use PhrasePoolCommand::*;
|
||||
|
||||
|
|
@ -11,7 +11,7 @@ pub struct Groovebox {
|
|||
|
||||
pub player: MidiPlayer,
|
||||
pub pool: PoolModel,
|
||||
pub editor: MidiEditorModel,
|
||||
pub editor: MidiEditor,
|
||||
pub sampler: Sampler,
|
||||
|
||||
pub size: Measure<Tui>,
|
||||
|
|
@ -49,7 +49,7 @@ impl Groovebox {
|
|||
)));
|
||||
player.play_phrase = Some((Moment::zero(&player.clock.timebase), Some(phrase.clone())));
|
||||
let pool = crate::pool::PoolModel::from(&phrase);
|
||||
let editor = crate::midi::MidiEditorModel::from(&phrase);
|
||||
let editor = crate::midi::MidiEditor::from(&phrase);
|
||||
Ok(Self {
|
||||
_jack: jack.clone(),
|
||||
player,
|
||||
|
|
@ -142,25 +142,29 @@ render!(<Tui>|self:Groovebox|{
|
|||
});
|
||||
|
||||
struct EditStatus<'a, T: Render<Tui>>(&'a Sampler, &'a MidiEditor, usize, T);
|
||||
render!(<Tui>|self: EditStatus<'a, T: Render<Tui>>|Split::n(false, 9, col!(![
|
||||
row!(|add|{
|
||||
if let Some(sample) = &self.0.mapped[self.2] {
|
||||
add(&format!("Sample {}", sample.read().unwrap().end))?;
|
||||
}
|
||||
add(&MidiEditStatus(&self.1))?;
|
||||
Ok(())
|
||||
}),
|
||||
lay!([
|
||||
Outer(Style::default().fg(TuiTheme::g(128))),
|
||||
Fill::w(Fixed::h(8, if let Some((_, sample)) = &self.0.recording {
|
||||
SampleViewer(Some(sample.clone()))
|
||||
} else if let Some(sample) = &self.0.mapped[self.2] {
|
||||
SampleViewer(Some(sample.clone()))
|
||||
} else {
|
||||
SampleViewer(None)
|
||||
})),
|
||||
]),
|
||||
]), self.3));
|
||||
impl<'a, T: Render<Tui>> Render<Tui> for EditStatus<'a, T> {
|
||||
fn content (&self) -> impl Render<Tui> {
|
||||
Split::n(false, 9, col!([
|
||||
row!(|add|{
|
||||
if let Some(sample) = &self.0.mapped[self.2] {
|
||||
add(&format!("Sample {}", sample.read().unwrap().end))?;
|
||||
}
|
||||
add(&MidiEditStatus(&self.1))?;
|
||||
Ok(())
|
||||
}),
|
||||
lay!([
|
||||
Outer(Style::default().fg(TuiTheme::g(128))),
|
||||
Fill::w(Fixed::h(8, if let Some((_, sample)) = &self.0.recording {
|
||||
SampleViewer(Some(sample.clone()))
|
||||
} else if let Some(sample) = &self.0.mapped[self.2] {
|
||||
SampleViewer(Some(sample.clone()))
|
||||
} else {
|
||||
SampleViewer(None)
|
||||
})),
|
||||
]),
|
||||
]), &self.3)
|
||||
}
|
||||
}
|
||||
|
||||
struct GrooveboxSamples<'a>(&'a Groovebox);
|
||||
render!(<Tui>|self: GrooveboxSamples<'a>|{
|
||||
|
|
@ -204,19 +208,19 @@ input_to_command!(GrooveboxCommand: <Tui>|state: Groovebox, input|match input.ev
|
|||
},
|
||||
|
||||
// Transport: Play from start or rewind to start
|
||||
key_pat!(Char(' ')) => Clock(
|
||||
key_pat!(Char(' ')) => Cmd::Clock(
|
||||
if state.clock().is_stopped() { Play(Some(0)) } else { Pause(Some(0)) }
|
||||
),
|
||||
|
||||
// Tab: Toggle visibility of phrase pool column
|
||||
key_pat!(Tab) => Pool(PoolCommand::Show(!state.pool.visible)),
|
||||
key_pat!(Tab) => Cmd::Pool(PoolCommand::Show(!state.pool.visible)),
|
||||
|
||||
// q: Enqueue currently edited phrase
|
||||
key_pat!(Char('q')) => Enqueue(Some(state.pool.phrase().clone())),
|
||||
key_pat!(Char('q')) => Cmd::Enqueue(Some(state.pool.phrase().clone())),
|
||||
// 0: Enqueue phrase 0 (stop all)
|
||||
key_pat!(Char('0')) => Enqueue(Some(state.pool.phrases()[0].clone())),
|
||||
key_pat!(Char('0')) => Cmd::Enqueue(Some(state.pool.phrases()[0].clone())),
|
||||
|
||||
key_pat!(Shift-Char('R')) => Sampler(if state.sampler.recording.is_some() {
|
||||
key_pat!(Shift-Char('R')) => Cmd::Sampler(if state.sampler.recording.is_some() {
|
||||
SamplerCommand::RecordFinish
|
||||
} else {
|
||||
SamplerCommand::RecordBegin(u7::from(state.editor.note_point() as u8))
|
||||
|
|
@ -226,7 +230,7 @@ input_to_command!(GrooveboxCommand: <Tui>|state: Groovebox, input|match input.ev
|
|||
key_pat!(Char('e')) => if let Some((_, Some(playing))) = state.player.play_phrase() {
|
||||
let editing = state.editor.phrase().as_ref().map(|p|p.read().unwrap().clone());
|
||||
let selected = state.pool.phrase().clone();
|
||||
Editor(Show(Some(if Some(selected.read().unwrap().clone()) != editing {
|
||||
Cmd::Editor(Show(Some(if Some(selected.read().unwrap().clone()) != editing {
|
||||
selected
|
||||
} else {
|
||||
playing.clone()
|
||||
|
|
@ -238,9 +242,9 @@ input_to_command!(GrooveboxCommand: <Tui>|state: Groovebox, input|match input.ev
|
|||
// For the rest, use the default keybindings of the components.
|
||||
// The ones defined above supersede them.
|
||||
_ => if let Some(command) = PhraseCommand::input_to_command(&state.editor, input) {
|
||||
Editor(command)
|
||||
Cmd::Editor(command)
|
||||
} else if let Some(command) = PoolCommand::input_to_command(&state.pool, input) {
|
||||
Pool(command)
|
||||
Cmd::Pool(command)
|
||||
} else {
|
||||
return None
|
||||
}
|
||||
|
|
@ -250,7 +254,7 @@ command!(|self: GrooveboxCommand, state: Groovebox|match self {
|
|||
Self::Pool(cmd) => {
|
||||
let mut default = |cmd: PoolCommand|cmd
|
||||
.execute(&mut state.pool)
|
||||
.map(|x|x.map(Pool));
|
||||
.map(|x|x.map(Self::Pool));
|
||||
match cmd {
|
||||
// autoselect: automatically load selected phrase in editor
|
||||
PoolCommand::Select(_) => {
|
||||
|
|
@ -268,13 +272,13 @@ command!(|self: GrooveboxCommand, state: Groovebox|match self {
|
|||
}
|
||||
},
|
||||
Self::Editor(cmd) => {
|
||||
let default = ||cmd.execute(&mut state.editor).map(|x|x.map(Editor));
|
||||
let default = ||cmd.execute(&mut state.editor).map(|x|x.map(Self::Editor));
|
||||
match cmd {
|
||||
_ => default()?
|
||||
}
|
||||
},
|
||||
Self::Clock(cmd) => cmd.execute(state)?.map(Clock),
|
||||
Self::Sampler(cmd) => cmd.execute(&mut state.sampler)?.map(Sampler),
|
||||
Self::Clock(cmd) => cmd.execute(state)?.map(Self::Clock),
|
||||
Self::Sampler(cmd) => cmd.execute(&mut state.sampler)?.map(Self::Sampler),
|
||||
Self::Enqueue(phrase) => {
|
||||
state.player.enqueue_next(phrase.as_ref());
|
||||
None
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue