Ugly progression
This commit is contained in:
parent
62793d4f43
commit
e91358e61f
|
|
@ -14,3 +14,8 @@ Cargo.lock
|
|||
# MSVC Windows builds of rustc generate these, which store debugging information
|
||||
*.pdb
|
||||
|
||||
|
||||
|
||||
# Added by cargo
|
||||
|
||||
/target
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
[package]
|
||||
name = "rusty_midicommander"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
midir = "0.9.1"
|
||||
clap = { version = "4.2.1", features = ["derive","color"] }
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
// The commands module should define the commands that the program can send.
|
||||
// This module should provide functions to send each command asynchronously.
|
||||
// The functions should return immediately, without waiting for the command to complete.
|
||||
|
||||
struct MidiData {
|
||||
// Define your MIDI data struct here
|
||||
}
|
||||
|
||||
trait Command {
|
||||
fn execute(&self, midi_data: &MidiData);
|
||||
}
|
||||
|
||||
struct CommandA;
|
||||
|
||||
impl Command for CommandA {
|
||||
fn execute(&self, midi_data: &MidiData) {
|
||||
println!("Executing CommandA with MIDI data {:?}", midi_data);
|
||||
}
|
||||
}
|
||||
|
||||
struct CommandB {
|
||||
message: String,
|
||||
}
|
||||
|
||||
impl Command for CommandB {
|
||||
fn execute(&self, midi_data: &MidiData) {
|
||||
println!(
|
||||
"Executing CommandB with message '{}' and MIDI data {:?}",
|
||||
self.message, midi_data
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
// 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 clap::Parser;
|
||||
use midir::MidiInput;
|
||||
use midir::MidiInputPort;
|
||||
use midir::MidiOutput;
|
||||
use midir::MidiOutputPort;
|
||||
// use midir::MidiOutput;
|
||||
pub mod midi;
|
||||
|
||||
/// 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>,
|
||||
|
||||
/// The port to use (default 0)
|
||||
#[arg(short, long)]
|
||||
port: Option<usize>,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// Parse Arguments
|
||||
let mut args = Args::parse();
|
||||
match args {
|
||||
Args {
|
||||
midi_interface: None,
|
||||
port: _,
|
||||
} => {
|
||||
midi::print_midi_interfaces();
|
||||
return;
|
||||
}
|
||||
Args {
|
||||
midi_interface: Some(_),
|
||||
port: None,
|
||||
} => args.port = Some(0),
|
||||
Args {
|
||||
midi_interface: Some(_),
|
||||
port: Some(_),
|
||||
} => {}
|
||||
}
|
||||
// println!("{:?}", args);
|
||||
connect_with_callback(1, "Rusty MIDI Commander Input");
|
||||
loop {}
|
||||
}
|
||||
|
||||
pub fn connect_with_callback(port: usize, name: &str)
|
||||
// where
|
||||
// F: FnMut(u64, &[u8], &mut T) + Send + 'static,
|
||||
{
|
||||
// Create MIDI input instance
|
||||
let input_interface = MidiInput::new(name).unwrap();
|
||||
|
||||
// Get available MIDI input ports
|
||||
let input_ports = input_interface.ports();
|
||||
|
||||
// Connect to port
|
||||
let input_port = &input_ports[port];
|
||||
let _connection = input_interface
|
||||
.connect(
|
||||
input_port,
|
||||
name,
|
||||
move |_timestamp, message, _| {
|
||||
// Handle MIDI messages here
|
||||
println!("Received MIDI message: {:?}", message);
|
||||
|
||||
// let conn = &midi_co
|
||||
// .output_interface
|
||||
// .connect(&midi_co.output_port.clone(), "Rusty MIDI Commander Input");
|
||||
},
|
||||
(),
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
// The midi module should provide a high-level interface for receiving and sending MIDI messages.
|
||||
// It should handle the low-level details of communicating with the MIDI devices.
|
||||
|
||||
use crate::MidiInput;
|
||||
|
||||
pub fn print_midi_interfaces() {
|
||||
// Create MIDI input and output instances
|
||||
let midi_in = MidiInput::new("Rusty MIDI Commander Input").unwrap();
|
||||
|
||||
// Get available MIDI input and output ports
|
||||
let input_ports = midi_in.ports();
|
||||
// let output_ports = midi_out.ports();
|
||||
|
||||
// Print available input ports
|
||||
println!("No interface selected, please select one:");
|
||||
for (i, port) in input_ports.iter().enumerate() {
|
||||
println!(" {}: {}", i, midi_in.port_name(port).unwrap());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
// 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.
|
||||
Reference in New Issue