ui thrashing

This commit is contained in:
🪞👃🪞 2024-07-07 17:55:05 +03:00
parent acb952736e
commit 20b7267225
18 changed files with 695 additions and 233 deletions

View file

@ -67,9 +67,9 @@ impl Sampler {
fn process_midi_in (&mut self, scope: &ProcessScope) {
for RawMidi { time, bytes } in self.ports.midi_ins.get("midi").unwrap().iter(scope) {
if let LiveEvent::Midi { message, .. } = LiveEvent::parse(bytes).unwrap() {
if let MidiMessage::NoteOn { ref key, .. } = message {
if let MidiMessage::NoteOn { ref key, ref vel } = message {
if let Some(sample) = self.samples.get(key) {
self.voices.push(sample.play(time as usize));
self.voices.push(sample.play(time as usize, vel));
}
}
}
@ -143,11 +143,12 @@ impl Sample {
pub fn new (name: &str, start: usize, end: usize, channels: Vec<Vec<f32>>) -> Arc<Self> {
Arc::new(Self { name: name.to_string(), start, end, channels })
}
pub fn play (self: &Arc<Self>, after: usize) -> Voice {
pub fn play (self: &Arc<Self>, after: usize, velocity: &u7) -> Voice {
Voice {
sample: self.clone(),
after,
position: self.start
position: self.start,
velocity: velocity.as_int() as f32 / 127.0
}
}
}
@ -156,6 +157,7 @@ pub struct Voice {
pub sample: Arc<Sample>,
pub after: usize,
pub position: usize,
pub velocity: f32,
}
const BUFFER: [f32;64] = [0.0f32;64];
@ -171,8 +173,8 @@ impl Iterator for Voice {
let position = self.position;
self.position = self.position + 1;
return Some([
self.sample.channels[0][position],
self.sample.channels[0][position],
self.sample.channels[0][position] * self.velocity,
self.sample.channels[0][position] * self.velocity,
])
}
None