// 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 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_input: Option, midi_output: Option, } 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(); match args { Args { midi_input: None, midi_output: None, } => { midi::print_midi_interfaces(&"No interface selected, please select one:".into()); return; } Args { midi_input: Some(_), midi_output: Some(_), } => {} Args { midi_input: _, midi_output: None, } => { midi::print_midi_interfaces(&"No interface selected, please select one:".into()); return; } _ => {} } println!("[INFO] Connecting with args: {:?}", args); let proj = Arc::new(Mutex::new(projector::Projector::new( "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_output, "Rusty MIDI Commander Output"); cleanup(&mut output_interface.lock().unwrap()); connect_loop_with_callback( args.midi_input.unwrap(), "Rusty MIDI Commander Input", &mut output_interface, list_actions!(3, proj1, shutter_on, 4, proj2, shutter_off), ); }