More robust midi implementation
This commit is contained in:
52
src/main.rs
52
src/main.rs
@@ -103,16 +103,20 @@ fn main() -> io::Result<()> {
|
||||
theme::set(settings.display.color_scheme.to_theme());
|
||||
|
||||
// Load MIDI settings
|
||||
if let Some(output_name) = &settings.midi.output_device {
|
||||
let outputs = midi::list_midi_outputs();
|
||||
if let Some(idx) = outputs.iter().position(|d| &d.name == output_name) {
|
||||
let _ = app.midi.connect_output(idx);
|
||||
let outputs = midi::list_midi_outputs();
|
||||
let inputs = midi::list_midi_inputs();
|
||||
for (slot, name) in settings.midi.output_devices.iter().enumerate() {
|
||||
if !name.is_empty() {
|
||||
if let Some(idx) = outputs.iter().position(|d| &d.name == name) {
|
||||
let _ = app.midi.connect_output(slot, idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(input_name) = &settings.midi.input_device {
|
||||
let inputs = midi::list_midi_inputs();
|
||||
if let Some(idx) = inputs.iter().position(|d| &d.name == input_name) {
|
||||
let _ = app.midi.connect_input(idx);
|
||||
for (slot, name) in settings.midi.input_devices.iter().enumerate() {
|
||||
if !name.is_empty() {
|
||||
if let Some(idx) = inputs.iter().position(|d| &d.name == name) {
|
||||
let _ = app.midi.connect_input(slot, idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -240,28 +244,28 @@ fn main() -> io::Result<()> {
|
||||
// Process pending MIDI commands
|
||||
while let Ok(midi_cmd) = midi_rx.try_recv() {
|
||||
match midi_cmd {
|
||||
engine::MidiCommand::NoteOn { channel, note, velocity } => {
|
||||
app.midi.send_note_on(channel, note, velocity);
|
||||
engine::MidiCommand::NoteOn { device, channel, note, velocity } => {
|
||||
app.midi.send_note_on(device, channel, note, velocity);
|
||||
}
|
||||
engine::MidiCommand::NoteOff { channel, note } => {
|
||||
app.midi.send_note_off(channel, note);
|
||||
engine::MidiCommand::NoteOff { device, channel, note } => {
|
||||
app.midi.send_note_off(device, channel, note);
|
||||
}
|
||||
engine::MidiCommand::CC { channel, cc, value } => {
|
||||
app.midi.send_cc(channel, cc, value);
|
||||
engine::MidiCommand::CC { device, channel, cc, value } => {
|
||||
app.midi.send_cc(device, channel, cc, value);
|
||||
}
|
||||
engine::MidiCommand::PitchBend { channel, value } => {
|
||||
app.midi.send_pitch_bend(channel, value);
|
||||
engine::MidiCommand::PitchBend { device, channel, value } => {
|
||||
app.midi.send_pitch_bend(device, channel, value);
|
||||
}
|
||||
engine::MidiCommand::Pressure { channel, value } => {
|
||||
app.midi.send_pressure(channel, value);
|
||||
engine::MidiCommand::Pressure { device, channel, value } => {
|
||||
app.midi.send_pressure(device, channel, value);
|
||||
}
|
||||
engine::MidiCommand::ProgramChange { channel, program } => {
|
||||
app.midi.send_program_change(channel, program);
|
||||
engine::MidiCommand::ProgramChange { device, channel, program } => {
|
||||
app.midi.send_program_change(device, channel, program);
|
||||
}
|
||||
engine::MidiCommand::Clock => app.midi.send_realtime(0xF8),
|
||||
engine::MidiCommand::Start => app.midi.send_realtime(0xFA),
|
||||
engine::MidiCommand::Stop => app.midi.send_realtime(0xFC),
|
||||
engine::MidiCommand::Continue => app.midi.send_realtime(0xFB),
|
||||
engine::MidiCommand::Clock { device } => app.midi.send_realtime(device, 0xF8),
|
||||
engine::MidiCommand::Start { device } => app.midi.send_realtime(device, 0xFA),
|
||||
engine::MidiCommand::Stop { device } => app.midi.send_realtime(device, 0xFC),
|
||||
engine::MidiCommand::Continue { device } => app.midi.send_realtime(device, 0xFB),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user