Working Placeholder, now let's refactor EVERYTHING
This commit is contained in:
parent
f0b63d0572
commit
4290e0da9c
36
src/midi.rs
36
src/midi.rs
|
|
@ -31,7 +31,7 @@ pub fn connect_loop_with_callback(
|
|||
port: usize,
|
||||
name: &str,
|
||||
out_port: &mut Arc<Mutex<MidiOutputConnection>>,
|
||||
calls: Vec<(u8, Box<dyn Fn() -> ()>)>,
|
||||
calls: Vec<(u8, Box<dyn Fn() + Send + 'static>)>,
|
||||
) {
|
||||
// Create MIDI input instance
|
||||
let input_interface = MidiInput::new(name).unwrap();
|
||||
|
|
@ -42,22 +42,38 @@ pub fn connect_loop_with_callback(
|
|||
// Connect to port
|
||||
let input_port = &input_ports[port];
|
||||
let conn_clone = Arc::clone(&out_port);
|
||||
// let fn_clone = Arc::clone(&calls);
|
||||
let _connection = input_interface
|
||||
.connect(
|
||||
input_port,
|
||||
name,
|
||||
move |_timestamp, message, _| {
|
||||
// Handle MIDI messages here
|
||||
let (a, note, value) = (message[0], message[1], message[2]);
|
||||
let (command, note, _value) = (message[0], message[1], message[2]);
|
||||
println!("Received MIDI message: {:?}", message);
|
||||
// for (id, _) in calls.iter() {
|
||||
// println!("{:?}", id);
|
||||
// }
|
||||
conn_clone
|
||||
.lock()
|
||||
.unwrap()
|
||||
.send(&[a, note, (value + 1) % 7])
|
||||
.unwrap();
|
||||
match (command, note) {
|
||||
(144, 3..=4) => {
|
||||
for (id, f) in calls.iter() {
|
||||
if note == *id {
|
||||
println!("match");
|
||||
f();
|
||||
}
|
||||
let mut list = vec![];
|
||||
if note == 3 {
|
||||
list.push([command, 3, 2]);
|
||||
list.push([command, 4, 3]);
|
||||
} else {
|
||||
list.push([command, 3, 1]);
|
||||
list.push([command, 4, 4]);
|
||||
}
|
||||
for n in list.iter() {
|
||||
conn_clone.lock().unwrap().send(n).unwrap();
|
||||
conn_clone.lock().unwrap().send(n).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
(_, _) => (),
|
||||
}
|
||||
},
|
||||
(),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -13,19 +13,30 @@ async fn get_osd(_req: HttpRequest) -> impl Responder {
|
|||
HttpResponse::Ok().body(response)
|
||||
}
|
||||
|
||||
async fn debug_handler(req: HttpRequest/*,config: web::Data<Config>*/) -> HttpResponse {
|
||||
async fn debug_handler(req: HttpRequest /*,config: web::Data<Config>*/) -> HttpResponse {
|
||||
if let Some(header_value) = req.headers().get("Authorization") {
|
||||
if let Ok(header_value) = header_value.to_str() {
|
||||
if let Some(credentials) = header_value.strip_prefix("Basic ") {
|
||||
// Authentication succeeded
|
||||
println!("Debug message! {:?}", general_purpose::STANDARD_NO_PAD.decode(credentials).unwrap_or("".into()));
|
||||
return HttpResponse::Ok().body(general_purpose::STANDARD_NO_PAD.decode(credentials).unwrap_or("".into()));
|
||||
}
|
||||
// Authentication succeeded
|
||||
println!(
|
||||
"Debug message! {:?}",
|
||||
general_purpose::STANDARD_NO_PAD
|
||||
.decode(credentials)
|
||||
.unwrap_or("".into())
|
||||
);
|
||||
return HttpResponse::Ok().body(
|
||||
general_purpose::STANDARD_NO_PAD
|
||||
.decode(credentials)
|
||||
.unwrap_or("".into()),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Authentication failed
|
||||
HttpResponse::Unauthorized().append_header(("WWW-Authenticate","Basic realm=\"Restricted area\"")).finish()
|
||||
HttpResponse::Unauthorized()
|
||||
.append_header(("WWW-Authenticate", "Basic realm=\"Restricted area\""))
|
||||
.finish()
|
||||
}
|
||||
|
||||
// in your `App` configuration
|
||||
|
|
@ -33,12 +44,12 @@ async fn debug_handler(req: HttpRequest/*,config: web::Data<Config>*/) -> HttpRe
|
|||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
HttpServer::new(|| {
|
||||
App::new().route("/debug", web::get().to(debug_handler))
|
||||
App::new()
|
||||
.route("/debug", web::get().to(debug_handler))
|
||||
.route("/cgi-bin/proj_ctl.cgi", web::get().to(proj_ctl))
|
||||
.route("/cgi-bin/get_osd.cgi", web::get().to(get_osd))
|
||||
|
||||
})
|
||||
.bind("127.0.0.1:8080")?
|
||||
.run()
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Reference in New Issue