feat: simple virtual port impl
This commit is contained in:
parent
10f5a05b35
commit
13a619866d
2 changed files with 51 additions and 0 deletions
11
Cargo.toml
11
Cargo.toml
|
@ -5,3 +5,14 @@ edition = "2021"
|
|||
|
||||
[lib]
|
||||
|
||||
[[bin]]
|
||||
name = "mmp-port"
|
||||
path = "src/port/main.rs"
|
||||
required-features = ["port"]
|
||||
|
||||
[dependencies]
|
||||
midi-msg = { version = "0.7", optional = true }
|
||||
midir = { version = "0.10", optional = true }
|
||||
[features]
|
||||
default = []
|
||||
port = ["dep:midi-msg", "dep:midir"]
|
||||
|
|
40
src/port/main.rs
Normal file
40
src/port/main.rs
Normal file
|
@ -0,0 +1,40 @@
|
|||
use std::error::Error;
|
||||
use std::io::Read;
|
||||
|
||||
use midi_msg::ControlChange;
|
||||
use midir::os::unix::VirtualOutput;
|
||||
use midir::MidiOutput;
|
||||
|
||||
fn main() {
|
||||
match run() {
|
||||
Ok(_) => (),
|
||||
Err(err) => println!("Error: {}", err),
|
||||
}
|
||||
}
|
||||
|
||||
fn run() -> Result<(), Box<dyn Error>> {
|
||||
let Some(addr) = std::env::args().nth(1) else {
|
||||
eprintln!("no address provided!");
|
||||
eprintln!("usage: mpp-port 192.168.1.1:8080");
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
let midi_out = MidiOutput::new("mmp")?;
|
||||
|
||||
let mut conn = midi_out.create_virtual("control")?;
|
||||
|
||||
let msg = |control, value| midi_msg::MidiMsg::ChannelVoice {
|
||||
channel: midi_msg::Channel::Ch1,
|
||||
msg: midi_msg::ChannelVoiceMsg::ControlChange {
|
||||
control: ControlChange::CC { control, value, }
|
||||
}
|
||||
};
|
||||
|
||||
let mut stream = std::net::TcpStream::connect(addr)?;
|
||||
let mut buf = [0u8, 0u8];
|
||||
|
||||
loop {
|
||||
stream.read_exact(&mut buf)?;
|
||||
conn.send(&msg(buf[0], buf[1]).to_midi())?;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue