This commit is contained in:
@@ -4,7 +4,7 @@ use std::sync::atomic::Ordering;
|
||||
use super::{InputContext, InputResult};
|
||||
use crate::commands::AppCommand;
|
||||
use crate::engine::{AudioCommand, SeqCommand};
|
||||
use crate::state::{ConfirmAction, DeviceKind, EngineSection, Modal, SettingKind};
|
||||
use crate::state::{ConfirmAction, DeviceKind, EngineSection, LinkSetting, Modal, SettingKind};
|
||||
|
||||
pub(crate) fn cycle_engine_setting(ctx: &mut InputContext, right: bool) {
|
||||
let sign = if right { 1 } else { -1 };
|
||||
@@ -31,6 +31,112 @@ pub(crate) fn cycle_engine_setting(ctx: &mut InputContext, right: bool) {
|
||||
ctx.app.save_settings(ctx.link);
|
||||
}
|
||||
|
||||
pub(crate) fn cycle_link_setting(ctx: &mut InputContext, right: bool) {
|
||||
match ctx.app.audio.link_setting {
|
||||
LinkSetting::Enabled => ctx.link.set_enabled(!ctx.link.is_enabled()),
|
||||
LinkSetting::StartStopSync => ctx
|
||||
.link
|
||||
.set_start_stop_sync_enabled(!ctx.link.is_start_stop_sync_enabled()),
|
||||
LinkSetting::Quantum => {
|
||||
let delta = if right { 1.0 } else { -1.0 };
|
||||
ctx.link.set_quantum(ctx.link.quantum() + delta);
|
||||
}
|
||||
}
|
||||
ctx.app.save_settings(ctx.link);
|
||||
}
|
||||
|
||||
pub(crate) fn cycle_midi_output(ctx: &mut InputContext, right: bool) {
|
||||
let slot = ctx.app.audio.midi_output_slot;
|
||||
let all_devices = crate::midi::list_midi_outputs();
|
||||
let available: Vec<(usize, &crate::midi::MidiDeviceInfo)> = all_devices
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter(|(idx, _)| {
|
||||
ctx.app.midi.selected_outputs[slot] == Some(*idx)
|
||||
|| !ctx
|
||||
.app
|
||||
.midi
|
||||
.selected_outputs
|
||||
.iter()
|
||||
.enumerate()
|
||||
.any(|(s, sel)| s != slot && *sel == Some(*idx))
|
||||
})
|
||||
.collect();
|
||||
let total_options = available.len() + 1;
|
||||
let current_pos = ctx.app.midi.selected_outputs[slot]
|
||||
.and_then(|idx| available.iter().position(|(i, _)| *i == idx))
|
||||
.map(|p| p + 1)
|
||||
.unwrap_or(0);
|
||||
let new_pos = if right {
|
||||
(current_pos + 1) % total_options
|
||||
} else if current_pos == 0 {
|
||||
total_options - 1
|
||||
} else {
|
||||
current_pos - 1
|
||||
};
|
||||
if new_pos == 0 {
|
||||
ctx.app.midi.disconnect_output(slot);
|
||||
ctx.dispatch(AppCommand::SetStatus(format!(
|
||||
"MIDI output {slot}: disconnected"
|
||||
)));
|
||||
} else {
|
||||
let (device_idx, device) = available[new_pos - 1];
|
||||
if ctx.app.midi.connect_output(slot, device_idx).is_ok() {
|
||||
ctx.dispatch(AppCommand::SetStatus(format!(
|
||||
"MIDI output {}: {}",
|
||||
slot, device.name
|
||||
)));
|
||||
}
|
||||
}
|
||||
ctx.app.save_settings(ctx.link);
|
||||
}
|
||||
|
||||
pub(crate) fn cycle_midi_input(ctx: &mut InputContext, right: bool) {
|
||||
let slot = ctx.app.audio.midi_input_slot;
|
||||
let all_devices = crate::midi::list_midi_inputs();
|
||||
let available: Vec<(usize, &crate::midi::MidiDeviceInfo)> = all_devices
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter(|(idx, _)| {
|
||||
ctx.app.midi.selected_inputs[slot] == Some(*idx)
|
||||
|| !ctx
|
||||
.app
|
||||
.midi
|
||||
.selected_inputs
|
||||
.iter()
|
||||
.enumerate()
|
||||
.any(|(s, sel)| s != slot && *sel == Some(*idx))
|
||||
})
|
||||
.collect();
|
||||
let total_options = available.len() + 1;
|
||||
let current_pos = ctx.app.midi.selected_inputs[slot]
|
||||
.and_then(|idx| available.iter().position(|(i, _)| *i == idx))
|
||||
.map(|p| p + 1)
|
||||
.unwrap_or(0);
|
||||
let new_pos = if right {
|
||||
(current_pos + 1) % total_options
|
||||
} else if current_pos == 0 {
|
||||
total_options - 1
|
||||
} else {
|
||||
current_pos - 1
|
||||
};
|
||||
if new_pos == 0 {
|
||||
ctx.app.midi.disconnect_input(slot);
|
||||
ctx.dispatch(AppCommand::SetStatus(format!(
|
||||
"MIDI input {slot}: disconnected"
|
||||
)));
|
||||
} else {
|
||||
let (device_idx, device) = available[new_pos - 1];
|
||||
if ctx.app.midi.connect_input(slot, device_idx).is_ok() {
|
||||
ctx.dispatch(AppCommand::SetStatus(format!(
|
||||
"MIDI input {}: {}",
|
||||
slot, device.name
|
||||
)));
|
||||
}
|
||||
}
|
||||
ctx.app.save_settings(ctx.link);
|
||||
}
|
||||
|
||||
pub(super) fn handle_engine_page(ctx: &mut InputContext, key: KeyEvent) -> InputResult {
|
||||
match key.code {
|
||||
KeyCode::Char('q') if !ctx.app.plugin_mode => {
|
||||
@@ -49,6 +155,15 @@ pub(super) fn handle_engine_page(ctx: &mut InputContext, key: KeyEvent) -> Input
|
||||
EngineSection::Settings => {
|
||||
ctx.dispatch(AppCommand::AudioSettingPrev);
|
||||
}
|
||||
EngineSection::Link => {
|
||||
ctx.app.audio.prev_link_setting();
|
||||
}
|
||||
EngineSection::MidiOutput => {
|
||||
ctx.app.audio.prev_midi_output_slot();
|
||||
}
|
||||
EngineSection::MidiInput => {
|
||||
ctx.app.audio.prev_midi_input_slot();
|
||||
}
|
||||
EngineSection::Samples => {
|
||||
ctx.app.audio.sample_list.move_up();
|
||||
}
|
||||
@@ -68,6 +183,15 @@ pub(super) fn handle_engine_page(ctx: &mut InputContext, key: KeyEvent) -> Input
|
||||
EngineSection::Settings => {
|
||||
ctx.dispatch(AppCommand::AudioSettingNext);
|
||||
}
|
||||
EngineSection::Link => {
|
||||
ctx.app.audio.next_link_setting();
|
||||
}
|
||||
EngineSection::MidiOutput => {
|
||||
ctx.app.audio.next_midi_output_slot();
|
||||
}
|
||||
EngineSection::MidiInput => {
|
||||
ctx.app.audio.next_midi_input_slot();
|
||||
}
|
||||
EngineSection::Samples => {
|
||||
let count = ctx.app.audio.config.sample_paths.len();
|
||||
ctx.app.audio.sample_list.move_down(count);
|
||||
@@ -123,6 +247,9 @@ pub(super) fn handle_engine_page(ctx: &mut InputContext, key: KeyEvent) -> Input
|
||||
ctx.dispatch(AppCommand::SetDeviceKind(DeviceKind::Output));
|
||||
}
|
||||
EngineSection::Settings => cycle_engine_setting(ctx, false),
|
||||
EngineSection::Link => cycle_link_setting(ctx, false),
|
||||
EngineSection::MidiOutput => cycle_midi_output(ctx, false),
|
||||
EngineSection::MidiInput => cycle_midi_input(ctx, false),
|
||||
_ => {}
|
||||
},
|
||||
KeyCode::Right => match ctx.app.audio.section {
|
||||
@@ -130,6 +257,9 @@ pub(super) fn handle_engine_page(ctx: &mut InputContext, key: KeyEvent) -> Input
|
||||
ctx.dispatch(AppCommand::SetDeviceKind(DeviceKind::Input));
|
||||
}
|
||||
EngineSection::Settings => cycle_engine_setting(ctx, true),
|
||||
EngineSection::Link => cycle_link_setting(ctx, true),
|
||||
EngineSection::MidiOutput => cycle_midi_output(ctx, true),
|
||||
EngineSection::MidiInput => cycle_midi_input(ctx, true),
|
||||
_ => {}
|
||||
},
|
||||
KeyCode::Char('R') if !ctx.app.plugin_mode => {
|
||||
@@ -158,7 +288,6 @@ pub(super) fn handle_engine_page(ctx: &mut InputContext, key: KeyEvent) -> Input
|
||||
if !ctx.app.plugin_mode {
|
||||
let _ = ctx.audio_tx.load().send(AudioCommand::Hush);
|
||||
}
|
||||
let _ = ctx.seq_cmd_tx.send(SeqCommand::StopAll);
|
||||
}
|
||||
KeyCode::Char('p') => {
|
||||
if !ctx.app.plugin_mode {
|
||||
|
||||
Reference in New Issue
Block a user