From 355402ea0807ac608212bb0803072f145a50e6d7 Mon Sep 17 00:00:00 2001 From: beffroi Date: Tue, 4 Apr 2023 16:56:27 +0200 Subject: [PATCH 1/3] Workaround for the Error values --- src/main.rs | 18 +++++++++++++----- src/midi.rs | 3 +-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index 51347e0..33d5915 100644 --- a/src/main.rs +++ b/src/main.rs @@ -43,7 +43,7 @@ fn main() { } println!("{:?}", args); let proj = Arc::new(Mutex::new(projector::Projector::new( - "127.0.0.1:8080", + "192.168.0.8", //"127.0.0.1:8080", "admin1", "panasonic", ))); @@ -64,14 +64,22 @@ fn main() { vec![ ( 3, - Box::new(move || { - proj1.lock().unwrap().shutter_on().unwrap(); + 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 || { - proj2.lock().unwrap().shutter_on().unwrap(); + 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((|| {})()); }), ), ], diff --git a/src/midi.rs b/src/midi.rs index cedec07..f53d474 100644 --- a/src/midi.rs +++ b/src/midi.rs @@ -50,12 +50,11 @@ pub fn connect_loop_with_callback( move |_timestamp, message, _| { // Handle MIDI messages here let (command, note, _value) = (message[0], message[1], message[2]); - println!("Received MIDI message: {:?}", message); + //println!("Received MIDI message: {:?}", message); match (command, note) { (144, 3..=4) => { for (id, f) in calls.iter() { if note == *id { - println!("match"); f(); } let mut list = vec![]; From bb6760030863ea7d9fa3a15049e7fad7c38d2b37 Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Fri, 7 Apr 2023 16:25:14 +0200 Subject: [PATCH 2/3] Added a viewboard, problem right now is lack of project --- Cargo.toml | 6 +++- src/midi.rs | 9 +++--- src/viewboard.rs | 77 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+), 5 deletions(-) create mode 100644 src/viewboard.rs diff --git a/Cargo.toml b/Cargo.toml index 42e6fa8..ee32985 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,4 +19,8 @@ path = "src/main.rs" [[bin]] name = "webtest" -path = "src/webtest.rs" \ No newline at end of file +path = "src/webtest.rs" + +[[bin]] +name = "viewboard" +path = "src/viewboard.rs" \ No newline at end of file diff --git a/src/midi.rs b/src/midi.rs index f53d474..cfc2a30 100644 --- a/src/midi.rs +++ b/src/midi.rs @@ -1,9 +1,10 @@ // 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; -use crate::MidiOutput; -use crate::MidiOutputConnection; +use midir::MidiInput; +use midir::MidiOutput; +use midir::MidiOutputConnection; + use lazy_static::lazy_static; use std::sync::Arc; use std::sync::Mutex; @@ -99,7 +100,7 @@ pub fn cleanup( // co.send(message).unwrap(); // } for n in 0..=71 { - send_note_on(out_port, n, 0); + send_note_on(out_port, n, 2); } for n in 82..=89 { send_note_on(out_port, n, 0); diff --git a/src/viewboard.rs b/src/viewboard.rs new file mode 100644 index 0000000..baf6a27 --- /dev/null +++ b/src/viewboard.rs @@ -0,0 +1,77 @@ +#![allow(dead_code)] + +use crate::midi::create_output_interface; +use crate::midi::print_midi_interfaces; +use crate::midi::send_note_on; +use midir::MidiOutputConnection; +use std::sync::Arc; +use std::sync::Mutex; +use std::thread::sleep; +use std::time::Duration; + +/// A viewboard to represent the commanderpad +mod midi; +struct Placeholder {} + +struct RecvCommander<'a> { + /// The midi channel to communicate with the board + pub midi_address: &'a mut Arc>, + /// The list of available notes + pub list_notes: Vec, + /// The list of current notes values (if no other source has sent changes) + pub current_values: Vec, + /// The list of notes about to be sent + pub future_values: Vec, + /// The state of the board, wether it is visible or not + pub live: bool, +} + +impl RecvCommander<'_> { + fn new(output_interface: &mut Arc>) -> RecvCommander { + // Assert all vectors are of the same size + assert_eq!(70, 70); + RecvCommander { + midi_address: output_interface, + list_notes: (0..89).collect(), + current_values: vec![0; 89], + future_values: vec![0; 89], + live: false, + } + } + fn reset(&self) { + // let mut _addr = self.midi_address.lock().unwrap(); + for (i, note) in self.list_notes.iter().enumerate() { + send_note_on(&mut self.midi_address.lock().unwrap(), *note, 0); + if i % 20 == 0 { + sleep(Duration::from_millis(100)); + } + } + } + fn update(&self) { + for (i, note) in self.list_notes.iter().enumerate() { + let cr_note = self.current_values[i]; + let fu_note = self.future_values[i]; + if i % 20 == 0 { + sleep(Duration::from_millis(100)); + } + if fu_note == cr_note { + continue; + } + + send_note_on(&mut self.midi_address.lock().unwrap(), *note, fu_note); + } + } +} + +fn main() { + print_midi_interfaces(); + let output_interface = create_output_interface(3, "Rusty MIDI Commander Output"); + let mut binding = Arc::clone(&output_interface); + let board = RecvCommander::new(&mut binding); + // cleanup(&mut output_interface.lock().unwrap()); + board.reset(); + send_note_on(&mut output_interface.lock().unwrap(), 2, 1); + // sleep(Duration::from_millis(1000)); + board.update(); + loop {} +} From c82294f1f97d15d18aedbe40f13950d34ac0ec2e Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Mon, 4 Dec 2023 22:47:57 +0100 Subject: [PATCH 3/3] Fix weird color --- src/midi.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/midi.rs b/src/midi.rs index cfc2a30..7bf6b64 100644 --- a/src/midi.rs +++ b/src/midi.rs @@ -100,7 +100,7 @@ pub fn cleanup( // co.send(message).unwrap(); // } for n in 0..=71 { - send_note_on(out_port, n, 2); + send_note_on(out_port, n, 0); } for n in 82..=89 { send_note_on(out_port, n, 0);