Cleans up macro usage
This commit is contained in:
parent
dce5b8d883
commit
4cdb40ae4f
34
src/main.rs
34
src/main.rs
|
|
@ -2,7 +2,7 @@
|
|||
// 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;
|
||||
|
|
@ -16,9 +16,12 @@ use midir::MidiInput;
|
|||
use midir::MidiOutput;
|
||||
use midir::MidiOutputConnection;
|
||||
|
||||
// use midir::MidiOutput;
|
||||
pub mod midi;
|
||||
mod projector;
|
||||
|
||||
#[macro_use]
|
||||
mod utils;
|
||||
|
||||
/// Simple program to greet a person
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(author, version, about, long_about = None)]
|
||||
|
|
@ -28,33 +31,6 @@ struct Args {
|
|||
midi_output: Option<usize>,
|
||||
}
|
||||
|
||||
macro_rules! list_actions {
|
||||
($proj:ident, $($id:literal, $action:ident),+ ) => {
|
||||
{
|
||||
let mut temp_vec:Vec<(u8, Box<(dyn Fn() + Send + 'static)>)> = Vec::new();
|
||||
$(
|
||||
let proj = Arc::clone(&$proj);
|
||||
temp_vec.push((
|
||||
$id,
|
||||
Box::new(move || {
|
||||
match proj.lock().unwrap().$action() {
|
||||
Ok(_) => {}
|
||||
Err(e) => {
|
||||
println!(
|
||||
"[ERROR] An error occurend while sending a ({}) message",
|
||||
stringify!($action)
|
||||
);
|
||||
println!(" {}", e)
|
||||
}
|
||||
};
|
||||
}),
|
||||
));
|
||||
)+
|
||||
temp_vec
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// Parse Arguments
|
||||
let args = Args::parse();
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ use std::error::Error;
|
|||
|
||||
use std::time::Duration;
|
||||
|
||||
static WAIT_TIME: f64 = 0.7;
|
||||
static WAIT_TIME: f64 = 0.5;
|
||||
|
||||
pub struct Projector {
|
||||
ip: String,
|
||||
|
|
|
|||
27
src/utils.rs
27
src/utils.rs
|
|
@ -1,2 +1,29 @@
|
|||
// The utils module should provide utility functions that are used throughout the program.
|
||||
// These functions could include functions to convert MIDI messages to and from human-readable formats, or to handle errors.
|
||||
|
||||
macro_rules! list_actions {
|
||||
($proj:ident, $($id:literal, $action:ident),+ ) => {
|
||||
{
|
||||
let mut temp_vec:Vec<(u8, Box<(dyn Fn() + Send + 'static)>)> = Vec::new();
|
||||
$(
|
||||
let proj = Arc::clone(&$proj);
|
||||
temp_vec.push((
|
||||
$id,
|
||||
Box::new(move || {
|
||||
match proj.lock().unwrap().$action() {
|
||||
Ok(_) => {}
|
||||
Err(e) => {
|
||||
println!(
|
||||
"[ERROR] An error occurend while sending a ({}) message",
|
||||
stringify!($action)
|
||||
);
|
||||
println!(" {}", e)
|
||||
}
|
||||
};
|
||||
}),
|
||||
));
|
||||
)+
|
||||
temp_vec
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Reference in New Issue