Added a macro
This commit is contained in:
parent
06e74b28c4
commit
de9f497a00
|
|
@ -1,3 +1,8 @@
|
|||
# RustyMIDICommander
|
||||
|
||||
Rusty MIDI Commander is a lightweight and flexible Rust program for sending asynchronous commands in response to MIDI input. Built on top of popular Rust MIDI libraries, it provides a simple and modular framework for defining MIDI commands and executing them asynchronously. Whether you need to control web APIs, hardware devices, or other MIDI-enabled software, Rusty MIDI Commander makes it easy to build powerful and responsive MIDI control systems.
|
||||
Rusty MIDI Commander is a lightweight and flexible Rust program for sending asynchronous commands in response to MIDI input. Built on top of popular Rust MIDI libraries, it provides a simple and modular framework for defining MIDI commands and executing them asynchronously. Whether you need to control web APIs, hardware devices, or other MIDI-enabled software, Rusty MIDI Commander makes it easy to build powerful and responsive MIDI control systems.
|
||||
|
||||
|
||||
# Macro Reading
|
||||
https://veykril.github.io/tlborm/syntax-extensions/expansion.html
|
||||
https://doc.rust-lang.org/book/ch19-06-macros.html
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
[general]
|
||||
midi_name = "Rusty MIDI Commander"
|
||||
|
||||
[projector]
|
||||
address = "127.0.0.1:8080"
|
||||
login = "admin1"
|
||||
password = "panasonic"
|
||||
|
||||
59
src/main.rs
59
src/main.rs
|
|
@ -28,6 +28,31 @@ struct Args {
|
|||
midi_output: Option<usize>,
|
||||
}
|
||||
|
||||
macro_rules! list_actions {
|
||||
($($id1:literal , $proj1:ident, $action1:ident),+ ) => {
|
||||
|
||||
|
||||
vec![
|
||||
$((
|
||||
$id1,
|
||||
|
||||
Box::new(move || {
|
||||
match $proj1.lock().unwrap().$action1() {
|
||||
Ok(_) => {}
|
||||
Err(e) => {
|
||||
println!(
|
||||
"[ERROR] An error occurend while sending a ({}) message",
|
||||
stringify!($action1)
|
||||
);
|
||||
println!(" {}", e)
|
||||
}
|
||||
};
|
||||
}),
|
||||
),)+
|
||||
]
|
||||
};
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// Parse Arguments
|
||||
let args = Args::parse();
|
||||
|
|
@ -36,7 +61,7 @@ fn main() {
|
|||
midi_input: None,
|
||||
midi_output: None,
|
||||
} => {
|
||||
midi::print_midi_interfaces();
|
||||
midi::print_midi_interfaces(&"No interface selected, please select one:".into());
|
||||
return;
|
||||
}
|
||||
Args {
|
||||
|
|
@ -47,12 +72,13 @@ fn main() {
|
|||
midi_input: _,
|
||||
midi_output: None,
|
||||
} => {
|
||||
midi::print_midi_interfaces();
|
||||
midi::print_midi_interfaces(&"No interface selected, please select one:".into());
|
||||
return;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
println!("{:?}", args);
|
||||
|
||||
println!("[INFO] Connecting with args: {:?}", args);
|
||||
let proj = Arc::new(Mutex::new(projector::Projector::new(
|
||||
"127.0.0.1:8080",
|
||||
"admin1",
|
||||
|
|
@ -72,31 +98,6 @@ fn main() {
|
|||
args.midi_input.unwrap(),
|
||||
"Rusty MIDI Commander Input",
|
||||
&mut output_interface,
|
||||
vec![
|
||||
(
|
||||
3,
|
||||
Box::new(move || {
|
||||
match proj1.lock().unwrap().shutter_on() {
|
||||
Ok(_) => {}
|
||||
Err(e) => {
|
||||
println!(
|
||||
"[ERROR] An error occurend while sending a (Shutter on) message"
|
||||
);
|
||||
println!(" {}", e)
|
||||
}
|
||||
};
|
||||
}),
|
||||
),
|
||||
(
|
||||
4,
|
||||
Box::new(move || match proj2.lock().unwrap().shutter_off() {
|
||||
Ok(_) => {}
|
||||
Err(e) => {
|
||||
println!("[ERROR] An error occurend while sending a (Shutter off) message");
|
||||
println!(" {}", e)
|
||||
}
|
||||
}),
|
||||
),
|
||||
],
|
||||
list_actions!(3, proj1, shutter_on, 4, proj2, shutter_off),
|
||||
);
|
||||
}
|
||||
|
|
|
|||
16
src/midi.rs
16
src/midi.rs
|
|
@ -12,7 +12,7 @@ lazy_static! {
|
|||
static ref INIT_NOTES: Vec<(u8, u8)> = vec![(3, 1), (4, 3)];
|
||||
}
|
||||
|
||||
pub fn print_midi_interfaces() {
|
||||
pub fn print_midi_interfaces(error_message: &String) {
|
||||
// Create MIDI input and output instances
|
||||
let midi_in = MidiInput::new("Rusty MIDI Commander Input").unwrap();
|
||||
let midi_out = MidiOutput::new("Rusty MIDI Commander Output").unwrap();
|
||||
|
|
@ -36,7 +36,7 @@ pub fn print_midi_interfaces() {
|
|||
);
|
||||
return;
|
||||
}
|
||||
(_, _) => println!("No interface selected, please select one:"),
|
||||
(_, _) => println!("{}", error_message),
|
||||
}
|
||||
|
||||
println!("[Input]");
|
||||
|
|
@ -65,6 +65,10 @@ pub fn connect_loop_with_callback(
|
|||
let input_ports = input_interface.ports();
|
||||
|
||||
// Connect to port
|
||||
if port >= input_ports.len() {
|
||||
print_midi_interfaces(&"[ERROR] Midi input port is out of range".to_string());
|
||||
std::process::exit(1);
|
||||
}
|
||||
let input_port = &input_ports[port];
|
||||
let conn_clone = Arc::clone(&out_port);
|
||||
// let fn_clone = Arc::clone(&calls);
|
||||
|
|
@ -115,6 +119,12 @@ pub fn create_output_interface(
|
|||
None => MidiOutput::new(name).unwrap(),
|
||||
Some(_) => MidiOutput::new(name).unwrap(),
|
||||
};
|
||||
if port.unwrap() >= output_interface.ports().len() {
|
||||
print_midi_interfaces(
|
||||
&"[ERROR] The midi output interface selected is out of bounds".into(),
|
||||
);
|
||||
std::process::exit(1);
|
||||
}
|
||||
let output_port = &output_interface.ports()[port.unwrap()];
|
||||
Arc::new(Mutex::new(
|
||||
output_interface
|
||||
|
|
@ -126,8 +136,6 @@ pub fn create_output_interface(
|
|||
pub fn cleanup(
|
||||
out_port: &mut MidiOutputConnection, /*, range: &dyn std::iter::Iterator<Item = usize>*/
|
||||
) {
|
||||
// let _messages = vec![[0xB0, 0x7B, 0x00], [0xB0, 0x79, 0x00]];
|
||||
|
||||
// for message in messages.iter() {
|
||||
// co.send(message).unwrap();
|
||||
// }
|
||||
|
|
|
|||
Reference in New Issue