88 lines
2.7 KiB
Rust
88 lines
2.7 KiB
Rust
// In this organization, src/main.rs is the entry point for the program.
|
|
// This file should set up the MIDI input and output devices, and then
|
|
// start a loop to receive and process MIDI messages.
|
|
// It should also use the commands module to send commands asynchronously.
|
|
// use crate::midi::print_midi_interfaces;
|
|
use crate::midi::cleanup;
|
|
use crate::midi::connect_loop_with_callback;
|
|
use crate::midi::create_output_interface;
|
|
use crate::midi::prepare;
|
|
use clap::Parser;
|
|
use std::sync::Arc;
|
|
use std::sync::Mutex;
|
|
|
|
use midir::MidiInput;
|
|
|
|
use midir::MidiOutput;
|
|
use midir::MidiOutputConnection;
|
|
|
|
// use midir::MidiOutput;
|
|
pub mod midi;
|
|
mod projector;
|
|
/// Simple program to greet a person
|
|
#[derive(Parser, Debug)]
|
|
#[command(author, version, about, long_about = None)]
|
|
struct Args {
|
|
/// The midi interface to select
|
|
midi_interface: Option<usize>,
|
|
}
|
|
|
|
fn main() {
|
|
// Parse Arguments
|
|
let args = Args::parse();
|
|
match args {
|
|
Args {
|
|
midi_interface: None,
|
|
} => {
|
|
midi::print_midi_interfaces();
|
|
return;
|
|
}
|
|
Args {
|
|
midi_interface: Some(_),
|
|
} => {}
|
|
}
|
|
println!("{:?}", args);
|
|
let proj = Arc::new(Mutex::new(projector::Projector::new(
|
|
"192.168.0.8", //"127.0.0.1:8080",
|
|
"admin1",
|
|
"panasonic",
|
|
)));
|
|
let proj1 = Arc::clone(&proj);
|
|
let proj2 = Arc::clone(&proj);
|
|
|
|
// proj.lock().unwrap().shutter_on().unwrap();
|
|
// proj.lock().unwrap().shutter_off().unwrap();
|
|
// proj.lock().unwrap().get_osd().unwrap();
|
|
|
|
let mut output_interface =
|
|
create_output_interface(args.midi_interface.unwrap(), "Rusty MIDI Commander Output");
|
|
cleanup(&mut output_interface.lock().unwrap());
|
|
connect_loop_with_callback(
|
|
args.midi_interface.unwrap(),
|
|
"Rusty MIDI Commander Input",
|
|
&mut output_interface,
|
|
vec![
|
|
(
|
|
3,
|
|
Box::new(move || match proj1.lock().unwrap().shutter_off() {
|
|
Ok(_) => println!("Receiving SHUTTER OFF message"),
|
|
Err(_e) => {
|
|
println!("Error receiving SHUTTER OFF message");
|
|
"Error".to_string();
|
|
}
|
|
}),
|
|
),
|
|
(
|
|
4,
|
|
Box::new(move || match proj2.lock().unwrap().shutter_on() {
|
|
Ok(_) => println!("Receiving SHUTTER ON message"),
|
|
Err(_e) => {
|
|
println!("Error receiving SHUTTER ON message");
|
|
"Error".to_string();
|
|
} // proj2.lock().unwrap().unwrap_or((|| {})());
|
|
}),
|
|
),
|
|
],
|
|
);
|
|
}
|