Added a viewboard, problem right now is lack of project
This commit is contained in:
parent
355402ea08
commit
bb67600308
|
|
@ -19,4 +19,8 @@ path = "src/main.rs"
|
|||
|
||||
[[bin]]
|
||||
name = "webtest"
|
||||
path = "src/webtest.rs"
|
||||
path = "src/webtest.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "viewboard"
|
||||
path = "src/viewboard.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);
|
||||
|
|
|
|||
|
|
@ -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 {}
|
||||
}
|
||||
Reference in New Issue