working
This commit is contained in:
parent
133a1d2e8f
commit
e75ac7b3c0
6 changed files with 84 additions and 12 deletions
|
|
@ -2,10 +2,13 @@ use std::collections::HashMap;
|
|||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use midir::MidiOutput;
|
||||
|
||||
use tokio::sync::{ mpsc, Mutex };
|
||||
use tokio::time::Instant;
|
||||
use serde::Deserialize;
|
||||
use std::thread::sleep;
|
||||
|
||||
use crate::loggerbridge::Logger;
|
||||
pub struct MidiMessage {
|
||||
pub message: Vec<u8>,
|
||||
pub instant: Instant,
|
||||
|
|
@ -18,6 +21,7 @@ pub struct AsyncInputTransmit {
|
|||
}
|
||||
|
||||
pub fn init(
|
||||
logger: Logger,
|
||||
async_input_receiver: mpsc::Receiver<Vec<MidiMessage>>,
|
||||
mut async_output_receiver: mpsc::Receiver<Vec<MidiMessage>>,
|
||||
async_output_transmitter: mpsc::Sender<Vec<MidiMessage>>
|
||||
|
|
@ -50,10 +54,13 @@ pub fn init(
|
|||
let mut port_names = Vec::new();
|
||||
//TODO: Send these print messages to the UI logger instead of the rust console so the user can see them
|
||||
if out_ports.len() == 0 {
|
||||
println!(" No MIDI devices found. Connect a device or enable IAC Driver.");
|
||||
logger.log(" No MIDI devices found. Connect a device or enable IAC Driver.".to_string(), "".to_string());
|
||||
// logger(window, " No MIDI devices found. Connect a device or enable IAC Driver.".to_string(), None);
|
||||
return;
|
||||
}
|
||||
println!("Found {} midi devices!", out_ports.len());
|
||||
// give the frontend couple seconds to load on start, or the log messages will get lost
|
||||
sleep(Duration::from_secs(3));
|
||||
logger.log(format!("Found {} midi devices!", out_ports.len()), "".to_string());
|
||||
|
||||
// the user could reference any port at anytime during runtime,
|
||||
// so let's go ahead and open them all (same behavior as web app)
|
||||
|
|
@ -63,7 +70,7 @@ pub fn init(
|
|||
let ports = midiout.ports();
|
||||
let port = ports.get(i).unwrap();
|
||||
let port_name = midiout.port_name(port).unwrap();
|
||||
println!("{}", port_name);
|
||||
logger.log(port_name.clone(), "".to_string());
|
||||
let out_con = midiout.connect(port, &port_name).unwrap();
|
||||
port_names.insert(i, port_name.clone());
|
||||
output_connections.insert(port_name, out_con);
|
||||
|
|
@ -96,10 +103,10 @@ pub fn init(
|
|||
if out_con.is_some() {
|
||||
// process the message
|
||||
if let Err(err) = (&mut out_con.unwrap()).send(&message.message) {
|
||||
println!("Midi message send error: {}", err);
|
||||
logger.log(format!("Midi message send error: {}", err), "warning".to_string());
|
||||
}
|
||||
} else {
|
||||
println!("failed to find midi device: {}", message.requestedport);
|
||||
logger.log(format!("failed to find midi device: {}", message.requestedport), "warning".to_string());
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue