Skip to content

Commit

Permalink
Windows compatibility: without virtual MIDI port
Browse files Browse the repository at this point in the history
  • Loading branch information
JorenSix committed Jan 30, 2023
1 parent 2725af4 commit d84b8e9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
Binary file added misc/executables/mot.exe
Binary file not shown.
38 changes: 36 additions & 2 deletions src/midi_io.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use midir::{MidiOutput,MidiInput, Ignore,MidiOutputConnection};

#[cfg(target_family = "unix")]
use midir::os::unix::{VirtualInput,VirtualOutput};

use std::io::stdin;
Expand All @@ -22,9 +23,11 @@ impl MidiIn {
}
}

#[cfg(target_family = "unix")]
pub fn listen<F,T: 'static + Send>(self, callback: F,data: T,) where F: FnMut(u64, &[u8], &mut T) + Send + 'static {

let _con = match self.midi_in_index {

6666 => {
println!("#Receiving MIDI from virtual mot port");
self.midi_in.create_virtual("mot virtual port", callback,data)
Expand All @@ -43,6 +46,19 @@ impl MidiIn {
println!("Closing MIDI port");
}

#[cfg(not(target_family = "unix"))]
pub fn listen<F,T: 'static + Send>(self, callback: F,data: T,) where F: FnMut(u64, &[u8], &mut T) + Send + 'static {
let in_ports = self.midi_in.ports();
let in_port = &in_ports[self.midi_in_index];
println!("#Receiving MIDI from {:?} ",self.midi_in.port_name(&in_port).unwrap());
let _con = self.midi_in.connect(&in_port, "midir-read-input", callback,data);

let mut input = String::new();
input.clear();
stdin().read_line(&mut input).unwrap(); // wait for next enter key press
println!("Closing MIDI port");
}


pub fn list_midi_input_ports(){
let mut midi_in = MidiInput::new("midir reading input").unwrap();
Expand All @@ -53,7 +69,10 @@ impl MidiIn {
for (i, p) in in_ports.iter().enumerate() {
println!("{}: {}", i, midi_in.port_name(p).unwrap());
}
println!("6666: Virtual mot input port");
if cfg!(target_family = "unix"){
println!("6666: Virtual mot input port");
}

println!("");

}
Expand All @@ -77,6 +96,7 @@ pub struct MidiOut {

impl MidiOut {

#[cfg(target_family = "unix")]
pub fn new(midi_out_index: usize) -> MidiOut {

let midi_out = MidiOutput::new("midir reading output").unwrap();
Expand All @@ -97,6 +117,18 @@ impl MidiOut {
}
}

#[cfg(not(target_family = "unix"))]
pub fn new(midi_out_index: usize) -> MidiOut {
let midi_out = MidiOutput::new("midir reading output").unwrap();
let out_ports = midi_out.ports();
let out_port = &out_ports[midi_out_index];
let out_connection = midi_out.connect(out_port, "mot-out").expect("Could not connect to port");

MidiOut{
conn_out: out_connection
}
}

//pub fn send(&mut self, midi_cmd: u8, data1:u8 , data2: u8){
// self.conn_out.send(&[midi_cmd, data1, data2]).unwrap();
//}
Expand All @@ -114,7 +146,9 @@ impl MidiOut {
for (i, p) in out_ports.iter().enumerate() {
println!("{}: {}", i, midi_out.port_name(p).unwrap());
}
println!("6666: Virtual mot ouput port");
if cfg!(target_family = "unix") {
println!("6666: Virtual mot ouput port");
}
println!("");
}

Expand Down

0 comments on commit d84b8e9

Please sign in to comment.