mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 04:06:45 +01:00
fix timing by cleaning it
This commit is contained in:
parent
55a8b67bfb
commit
c4d8692b71
5 changed files with 69 additions and 97 deletions
|
|
@ -15,10 +15,10 @@ impl Phrase {
|
|||
Self { name: name.to_string(), length, notes: notes.unwrap_or(BTreeMap::new()) }
|
||||
}
|
||||
pub fn frames (&self, timebase: &Arc<Timebase>) -> usize {
|
||||
timebase.pulse_to_frame(self.length as usize)
|
||||
timebase.pulses_frames(self.length as usize)
|
||||
}
|
||||
pub fn frame_to_pulse (&self, timebase: &Arc<Timebase>, frame: usize) -> usize {
|
||||
timebase.frame_to_pulse(frame) % self.length as usize
|
||||
timebase.frames_pulses(frame) % self.length as usize
|
||||
}
|
||||
/** Write a chunk of MIDI events to an output port. */
|
||||
pub fn chunk_out (
|
||||
|
|
@ -29,8 +29,7 @@ impl Phrase {
|
|||
frame0: usize,
|
||||
frames: usize,
|
||||
) {
|
||||
let quant = self.frames(timebase);
|
||||
let ticks = timebase.frames_to_ticks(frame0, frame0 + frames, quant);
|
||||
let ticks = timebase.frames_to_ticks(frame0, frame0 + frames, self.frames(timebase));
|
||||
for (time, tick) in ticks.iter() {
|
||||
let events = self.notes.get(&(*tick as u32));
|
||||
if events.is_none() {
|
||||
|
|
@ -56,7 +55,7 @@ impl Phrase {
|
|||
}
|
||||
}
|
||||
}
|
||||
/** React a chunk of MIDI events from an input port. */
|
||||
/** Read a chunk of MIDI events from an input port. */
|
||||
pub fn chunk_in (
|
||||
&mut self,
|
||||
input: ::jack::MidiIter,
|
||||
|
|
@ -68,7 +67,7 @@ impl Phrase {
|
|||
) {
|
||||
for RawMidi { time, bytes } in input {
|
||||
let time = time as usize;
|
||||
let pulse = timebase.frame_to_pulse(frame0 + time) as u32;
|
||||
let pulse = timebase.frames_pulses(frame0 + time) as u32;
|
||||
if let LiveEvent::Midi { message, .. } = LiveEvent::parse(bytes).unwrap() {
|
||||
if let MidiMessage::NoteOn { key, vel: _ } = message {
|
||||
notes_on[key.as_int() as usize] = true;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue