This commit is contained in:
🪞👃🪞 2024-06-30 01:52:14 +03:00
parent 0ba14bf2da
commit 3ba5e253b0
5 changed files with 120 additions and 59 deletions

View file

@ -171,13 +171,24 @@ pub fn render (state: &Plugin, buf: &mut Buffer, area: Rect)
let Rect { x, y, height, .. } = area;
let mut width = 40u16;
match &state.plugin {
Some(PluginKind::LV2 { portList, .. }) => {
Some(PluginKind::LV2 { portList, instance, .. }) => {
let start = state.selected.saturating_sub((height as usize / 2).saturating_sub(1));
let end = start + height as usize - 2;
//draw_box(buf, Rect { x, y, width, height });
for i in 0..height-3 {
if let Some(port) = portList.get(i as usize) {
let label = &format!("C·· M·· {:25} = {:03}", port.name, port.default_value);
for i in start..end {
if let Some(port) = portList.get(i) {
let value = if let Some(value) = instance.control_input(port.index) {
value
} else {
port.default_value
};
let label = &format!("C·· M·· {:25} = {value:.03}", port.name);
width = width.max(label.len() as u16);
label.blit(buf, x + 2, y + 2 + i as u16, None);
label.blit(buf, x + 2, y + 1 + i as u16 - start as u16, if i == state.selected {
Some(Style::default().green())
} else {
None
});
} else {
break
}
@ -200,26 +211,67 @@ fn draw_header (state: &Plugin, buf: &mut Buffer, x: u16, y: u16, w: u16) -> Usu
pub fn handle (s: &mut Plugin, event: &AppEvent) -> Usually<bool> {
handle_keymap(s, event, keymap!(Plugin {
[Up, NONE, "cursor_up", "move cursor up",
|s: &mut Plugin|{
s.selected = s.selected.saturating_sub(1);
if s.selected < s.offset {
s.offset = s.selected;
if s.selected > 0 {
s.selected = s.selected - 1
} else {
s.selected = match &s.plugin {
Some(PluginKind::LV2 { portList, .. }) => portList.len() - 1,
_ => 0
}
}
Ok(true)
}],
[Down, NONE, "cursor_down", "move cursor down",
|s: &mut Plugin|{
s.selected = s.selected + 1;
if s.selected >= s.offset + 19 {
s.offset = s.offset + 1;
match &s.plugin {
Some(PluginKind::LV2 { portList, .. }) => {
if s.selected >= portList.len() {
s.selected = 0;
}
},
_ => {}
}
Ok(true)
}],
[Char(','), NONE, "decrement", "decrement value",
|s: &mut Plugin|{
match s.plugin.as_mut() {
Some(PluginKind::LV2 { portList, ref mut instance, .. }) => {
let index = portList[s.selected].index;
if let Some(value) = instance.control_input(index) {
instance.set_control_input(index, value - 0.01);
}
},
_ => {}
}
Ok(true)
}],
[Char('.'), NONE, "increment", "increment value",
|s: &mut Plugin|{
match s.plugin.as_mut() {
Some(PluginKind::LV2 { portList, ref mut instance, .. }) => {
let index = portList[s.selected].index;
if let Some(value) = instance.control_input(index) {
instance.set_control_input(index, value + 0.01);
}
},
_ => {}
}
Ok(true)
}],
[Char('m'), NONE, "toggle_midi_map", "toggle midi map mode",
|s: &mut Plugin|{
s.mapping = !s.mapping;
Ok(true)
}]
}))
}

View file

@ -115,18 +115,18 @@ fn toggle_help (state: &mut Launcher) -> Usually<bool> {
}
fn focus_next (state: &mut Launcher) -> Usually<bool> {
match state.view {
LauncherView::Tracks => { state.view = LauncherView::Chains; },
LauncherView::Chains => { state.view = LauncherView::Sequencer; },
LauncherView::Sequencer => { state.view = LauncherView::Tracks; },
LauncherView::Tracks => { state.view = LauncherView::Sequencer; },
LauncherView::Sequencer => { state.view = LauncherView::Chains; },
LauncherView::Chains => { state.view = LauncherView::Tracks; },
_ => {},
};
Ok(true)
}
fn focus_prev (state: &mut Launcher) -> Usually<bool> {
match state.view {
LauncherView::Tracks => { state.view = LauncherView::Sequencer; },
LauncherView::Sequencer => { state.view = LauncherView::Chains; },
LauncherView::Chains => { state.view = LauncherView::Tracks; },
LauncherView::Tracks => { state.view = LauncherView::Chains; },
LauncherView::Chains => { state.view = LauncherView::Sequencer; },
LauncherView::Sequencer => { state.view = LauncherView::Tracks; },
_ => {},
};
Ok(true)

View file

@ -60,7 +60,7 @@ impl Launcher {
monitoring: true,
recording: false,
overdub: true,
cursor: (1, 1),
cursor: (2, 2),
position: 0,
scenes: scenes.unwrap_or_else(||vec![Scene::new(&"Scene 1", &[None])]),
tracks: if let Some(tracks) = tracks { tracks } else { vec![
@ -184,7 +184,7 @@ pub fn render (state: &Launcher, buf: &mut Buffer, mut area: Rect) -> Usually<Re
let mut y = y + 1;
y = y + LauncherGridView::new(
state, buf, Rect { x, y, width, height: 8 }, state.view.is_tracks()
).draw()?.height - 1;
).draw()?.height;
y = y + draw_section_sequencer(state, buf, Rect { x, y, width, height: 8 })?.height;
y = y + draw_section_chains(state, buf, Rect { x, y, width, height: 8 })?.height;
area.height = y;

View file

@ -72,7 +72,7 @@ pub fn process (state: &mut Sequencer, _: &Client, scope: &ProcessScope) -> Cont
type MIDIChunk = [Option<Vec<Vec<u8>>>];
/// Add "all notes off" to the start of a buffer.
fn all_notes_off (output: &mut MIDIChunk) {
pub fn all_notes_off (output: &mut MIDIChunk) {
output[0] = Some(vec![]);
if let Some(Some(frame)) = output.get_mut(0) {
let mut buf = vec![];
@ -83,7 +83,7 @@ fn all_notes_off (output: &mut MIDIChunk) {
}
}
fn play_from_sequence (
pub fn play_from_sequence (
output: &mut MIDIChunk,
sequence: &PhraseData,
timebase: &Arc<Timebase>,
@ -113,7 +113,7 @@ fn play_from_sequence (
}
}
fn monitor_and_record (
pub fn monitor_and_record (
scope: &ProcessScope,
output: &mut MIDIChunk,
sequence: &mut PhraseData,