Merge remote-tracking branch 'origin/develop' into dev

This commit is contained in:
Dandaedre 2024-12-07 11:38:04 -06:00
commit 940486c3fa
4 changed files with 111 additions and 24 deletions

View File

@ -30,3 +30,6 @@ path = "src/lib.rs"
name = "webtest"
path = "src/webtest.rs"
[[bin]]
name = "viewboard"
path = "src/viewboard.rs"

View File

@ -55,14 +55,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((|| {})());
}),
),
],

View File

@ -59,26 +59,25 @@ 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);
if let (144, 3..=4) = (command, note) {
for (id, f) in calls.iter() {
if note == *id {
println!("match");
f();
}
let mut list = vec![];
if note == 3 {
// Meh
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() {
// Meh
conn_clone.lock().unwrap().send(n).unwrap();
conn_clone.lock().unwrap().send(n).unwrap();
//println!("Received MIDI message: {:?}", message);
match (command, note) {
(144, 3..=4) => {
for (id, f) in calls.iter() {
if note == *id {
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();
}
}
}
}

77
src/viewboard.rs Normal file
View File

@ -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<Mutex<MidiOutputConnection>>,
/// The list of available notes
pub list_notes: Vec<u8>,
/// The list of current notes values (if no other source has sent changes)
pub current_values: Vec<u8>,
/// The list of notes about to be sent
pub future_values: Vec<u8>,
/// The state of the board, wether it is visible or not
pub live: bool,
}
impl RecvCommander<'_> {
fn new(output_interface: &mut Arc<Mutex<MidiOutputConnection>>) -> 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 {}
}