new key binding macro

This commit is contained in:
🪞👃🪞 2025-01-02 21:03:20 +01:00
parent 5bc19a45d2
commit 6c266fcfca
16 changed files with 254 additions and 251 deletions

View file

@ -14,6 +14,8 @@ pub struct SequencerTui {
pub transport: bool,
pub selectors: bool,
pub compact: bool,
pub clock: Clock,
pub size: Measure<Tui>,
pub status: bool,
@ -34,6 +36,7 @@ from_jack!(|jack|SequencerTui {
editor: MidiEditor::from(&phrase),
player: MidiPlayer::from((&clock, &phrase)),
compact: true,
transport: true,
selectors: true,
size: Measure::new(),
@ -45,33 +48,36 @@ from_jack!(|jack|SequencerTui {
}
});
render!(Tui: (self: SequencerTui) => {
let w = self.size.w();
let phrase_w = if w > 60 { 20 } else if w > 40 { 15 } else { 10 };
let pool_w = if self.pool.visible { phrase_w } else { 0 };
let pool = Pull::y(1, Fill::y(Align::e(PoolView(self.pool.visible, &self.pool))));
let with_pool = move|x|Bsp::w(Fixed::x(pool_w, pool), x);
let status = SequencerStatus::from(self);
let with_status = |x|Bsp::n(Fixed::x(if self.status { 2 } else { 0 }, status), x);
let with_editbar = |x|Bsp::n(Fixed::x(1, MidiEditStatus(&self.editor)), x);
let with_size = |x|lay!(self.size.clone(), x);
let editor = with_editbar(with_pool(Fill::xy(&self.editor)));
let w =
self.size.w();
let phrase_w =
if w > 60 { 20 } else if w > 40 { 15 } else { 10 };
let color = self.player.play_phrase().as_ref().map(|(_,p)|
p.as_ref().map(|p|p.read().unwrap().color)
).flatten().clone();
let toolbar = Tui::when(self.transport, TransportView::new(true, &self.clock));
let play_queue = Tui::when(self.selectors, row!(
ClipSelected::play_phrase(&self.player),
ClipSelected::next_phrase(&self.player),
));
Min::y(15, with_size(with_status(col!(
let toolbar = Tui::when(self.transport,
TransportView::new(true, &self.clock));
let selectors = Tui::when(self.selectors,
Bsp::e(ClipSelected::play_phrase(&self.player), ClipSelected::next_phrase(&self.player)));
let pool_w =
if self.pool.visible { phrase_w } else { 0 };
let pool =
Pull::y(1, Fill::y(Align::e(PoolView(self.pool.visible, &self.pool))));
let edit_clip =
MidiEditClip(&self.editor);
self.size.of(Bsp::s(
toolbar,
play_queue,
editor,
))))
Bsp::s(
lay!(Align::w(edit_clip), Align::e(selectors)),
Bsp::n(
Align::x(Fixed::y(1, MidiEditStatus(&self.editor))),
Bsp::w(
Fixed::x(pool_w, Align::e(Fill::y(PoolView(self.compact, &self.pool)))),
Fill::xy(&self.editor),
),
)
)
))
});
audio!(|self:SequencerTui, client, scope|{
// Start profiling cycle
@ -94,15 +100,16 @@ has_size!(<Tui>|self:SequencerTui|&self.size);
has_clock!(|self:SequencerTui|&self.clock);
has_phrases!(|self:SequencerTui|self.pool.phrases);
has_editor!(|self:SequencerTui|self.editor);
handle!(<Tui>|self:SequencerTui,input|SequencerCommand::execute_with_state(self, input));
handle!(<Tui>|self:SequencerTui,input|SequencerCommand::execute_with_state(self, input.event()));
#[derive(Clone, Debug)] pub enum SequencerCommand {
Compact(bool),
History(isize),
Clock(ClockCommand),
Pool(PoolCommand),
Editor(MidiEditCommand),
Enqueue(Option<Arc<RwLock<MidiClip>>>),
}
input_to_command!(SequencerCommand: <Tui>|state: SequencerTui, input|match input.event() {
input_to_command!(SequencerCommand: |state: SequencerTui, input: Event|match input {
// TODO: k: toggle on-screen keyboard
key_pat!(Ctrl-Char('k')) => { todo!("keyboard") },
// Transport: Play/pause
@ -117,8 +124,8 @@ input_to_command!(SequencerCommand: <Tui>|state: SequencerTui, input|match input
key_pat!(Char('u')) => Cmd::History(-1),
// Shift-U: redo
key_pat!(Char('U')) => Cmd::History( 1),
// Tab: Toggle visibility of phrase pool column
key_pat!(Tab) => Cmd::Pool(PoolCommand::Show(!state.pool.visible)),
// Tab: Toggle compact mode
key_pat!(Tab) => Cmd::Compact(!state.compact),
// q: Enqueue currently edited phrase
key_pat!(Char('q')) => Cmd::Enqueue(Some(state.pool.phrase().clone())),
// 0: Enqueue phrase 0 (stop all)
@ -146,38 +153,34 @@ input_to_command!(SequencerCommand: <Tui>|state: SequencerTui, input|match input
}
});
command!(|self: SequencerCommand, state: SequencerTui|match self {
Self::Pool(cmd) => {
let mut default = |cmd: PoolCommand|cmd
.execute(&mut state.pool)
.map(|x|x.map(Cmd::Pool));
match cmd {
// autoselect: automatically load selected phrase in editor
PoolCommand::Select(_) => {
let undo = default(cmd)?;
state.editor.set_phrase(Some(state.pool.phrase()));
undo
},
// update color in all places simultaneously
PoolCommand::Phrase(SetColor(index, _)) => {
let undo = default(cmd)?;
state.editor.set_phrase(Some(state.pool.phrase()));
undo
},
_ => default(cmd)?
}
},
Self::Editor(cmd) => {
let default = ||cmd.execute(&mut state.editor).map(|x|x.map(Cmd::Editor));
match cmd {
_ => default()?
}
},
Self::Clock(cmd) => cmd.execute(state)?.map(Cmd::Clock),
Self::Enqueue(phrase) => {
state.player.enqueue_next(phrase.as_ref());
None
},
Self::Pool(cmd) => match cmd {
// autoselect: automatically load selected phrase in editor
PoolCommand::Select(_) => {
let undo = cmd.delegate(&mut state.pool, Self::Pool)?;
state.editor.set_phrase(Some(state.pool.phrase()));
undo
},
// update color in all places simultaneously
PoolCommand::Phrase(SetColor(index, _)) => {
let undo = cmd.delegate(&mut state.pool, Self::Pool)?;
state.editor.set_phrase(Some(state.pool.phrase()));
undo
},
_ => cmd.delegate(&mut state.pool, Self::Pool)?
},
Self::Editor(cmd) => cmd.delegate(&mut state.editor, Self::Editor)?,
Self::Clock(cmd) => cmd.delegate(state, Self::Clock)?,
Self::History(delta) => {
todo!("undo/redo")
},
Self::Compact(compact) => if state.compact != compact {
state.compact = compact;
Some(Self::Compact(!compact))
} else {
None
},
});