fix quantized recording for good

This commit is contained in:
🪞👃🪞 2024-07-07 00:01:32 +03:00
parent f9fa24de0d
commit e98c110dbe
4 changed files with 18 additions and 16 deletions

View file

@ -45,23 +45,23 @@ const KEYMAP: &'static [KeyBinding<App>] = keymap!(App {
}
Ok(true)
}],
[Char('l'), NONE, "loop_toggle", "toggle looping", |app: &mut App| {
[Char('l'), NONE, "loop_toggle", "toggle looping", |_app: &mut App| {
// TODO: This toggles the loop flag for the clip under the cursor.
Ok(true)
}],
[Char('['), NONE, "loop_start_dec", "move loop start back", |app: &mut App| {
[Char('['), NONE, "loop_start_dec", "move loop start back", |_app: &mut App| {
// TODO: This moves the loop start to the previous quant.
Ok(true)
}],
[Char(']'), NONE, "loop_start_inc", "move loop start forward", |app: &mut App| {
[Char(']'), NONE, "loop_start_inc", "move loop start forward", |_app: &mut App| {
// TODO: This moves the loop start to the next quant.
Ok(true)
}],
[Char('{'), NONE, "loop_end_dec", "move loop end back", |app: &mut App| {
[Char('{'), NONE, "loop_end_dec", "move loop end back", |_app: &mut App| {
// TODOO: This moves the loop end to the previous quant.
Ok(true)
}],
[Char('}'), NONE, "loop_end_inc", "move loop end forward", |app: &mut App| {
[Char('}'), NONE, "loop_end_inc", "move loop end forward", |_app: &mut App| {
// TODO: This moves the loop end to the next quant.
Ok(true)
}],

View file

@ -53,7 +53,7 @@ impl Timebase {
#[inline] pub fn pulse_per_frame (&self) -> f64 {
self.usec_per_pulse() / self.usec_per_frame() as f64
}
#[inline] fn usec_per_pulse (&self) -> f64 {
#[inline] pub fn usec_per_pulse (&self) -> f64 {
self.usec_per_beat() / self.ppq() as f64
}
#[inline] pub fn pulse_to_frame (&self, pulses: f64) -> f64 {

View file

@ -159,19 +159,21 @@ impl Track {
if self.recording || self.monitoring {
// For highlighting keys
let notes_on = &mut self.notes_on;
for (time, event, bytes) in parse_midi_input(input) {
for (frame, event, bytes) in parse_midi_input(input) {
match event {
LiveEvent::Midi { message, .. } => {
if monitoring {
self.midi_out_buf[time].push(bytes.to_vec())
self.midi_out_buf[frame].push(bytes.to_vec())
}
if recording {
phrase.as_mut().map(|p|p.record_event({
let pulse = timebase.frame_to_pulse((frame0 + time) as f64) as usize;
let pulse = (pulse / quant) * quant;
let pulse = pulse % p.length;
pulse
}, message));
if let Some((start_frame, _)) = started {
phrase.as_mut().map(|p|p.record_event({
let pulse = timebase.frame_to_pulse((frame0 + frame - start_frame) as f64);
let quantized = (pulse / quant as f64).round() as usize * quant;
let looped = quantized % p.length;
looped
}, message));
}
}
match message {
MidiMessage::NoteOn { key, .. } => {

View file

@ -30,7 +30,7 @@ impl<'a> SceneGridViewVertical<'a> {
lozenge_right(self.buf, x + width - 1, y, height, style);
}
let bg_color = if self.focused && self.entered {
Color::Rgb(30, 75, 25)
Color::Rgb(30, 90, 25)
} else if self.focused {
Color::Rgb(25, 60, 15)
} else {
@ -60,7 +60,6 @@ impl<'a> SceneGridViewVertical<'a> {
if x2 >= x + width {
break
}
let style = Some(highlight(self.focused, focus_column).bold());
let w = (title.len() as u16).max(10);
fill_bg(
&mut self.buf,
@ -76,6 +75,7 @@ impl<'a> SceneGridViewVertical<'a> {
} else if i < columns.len() {
self.clips(x2+1, y2+2, i - 1);
};
let style = Some(highlight(self.focused, focus_column).bold());
title.blit(self.buf, x2+1, y2, style);
x2 = x2 + w + 3;
}