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
|
|
@ -19,12 +19,7 @@ pub struct Launcher {
|
|||
show_help: bool,
|
||||
view: LauncherView,
|
||||
}
|
||||
pub enum LauncherView {
|
||||
Tracks,
|
||||
Sequencer,
|
||||
Chains,
|
||||
Modal(Box<dyn Device>),
|
||||
}
|
||||
pub enum LauncherView { Tracks, Sequencer, Chains, Modal(Box<dyn Device>) }
|
||||
impl LauncherView {
|
||||
fn is_tracks (&self) -> bool {
|
||||
match self { Self::Tracks => true, _ => false }
|
||||
|
|
@ -118,25 +113,25 @@ impl Launcher {
|
|||
}
|
||||
}
|
||||
|
||||
fn track <'a> (&'a self) -> Option<(usize, &'a Track)> {
|
||||
pub fn track <'a> (&'a self) -> Option<(usize, &'a Track)> {
|
||||
match self.col() { 0 => None, _ => {
|
||||
let id = self.col() as usize - 1;
|
||||
self.tracks.get(id).map(|t|(id, t))
|
||||
} }
|
||||
}
|
||||
fn scene <'a> (&'a self) -> Option<(usize, &'a Scene)> {
|
||||
pub fn scene <'a> (&'a self) -> Option<(usize, &'a Scene)> {
|
||||
match self.row() { 0 => None, _ => {
|
||||
let id = self.row() as usize - 1;
|
||||
self.scenes.get(id).map(|t|(id, t))
|
||||
} }
|
||||
}
|
||||
fn sequencer <'a> (&'a self) -> Option<MutexGuard<Sequencer>> {
|
||||
pub fn sequencer <'a> (&'a self) -> Option<MutexGuard<Sequencer>> {
|
||||
Some(self.track()?.1.sequencer.state())
|
||||
}
|
||||
fn chain <'a> (&'a self) -> Option<MutexGuard<Chain>> {
|
||||
pub fn chain <'a> (&'a self) -> Option<MutexGuard<Chain>> {
|
||||
Some(self.track()?.1.chain.state())
|
||||
}
|
||||
fn phrase_id (&self) -> Option<usize> {
|
||||
pub fn phrase_id (&self) -> Option<usize> {
|
||||
let (track_id, _) = self.track()?;
|
||||
let (_, scene) = self.scene()?;
|
||||
*scene.clips.get(track_id)?
|
||||
|
|
|
|||
|
|
@ -174,7 +174,7 @@ pub fn contains_note_on (sequence: &Phrase, k: u7, start: u32, end: u32) -> bool
|
|||
let mut s = sequencer.state.lock().unwrap();
|
||||
s.rate = Hz(48000);
|
||||
s.tempo = Tempo(240_000);
|
||||
println!("F/S = {:.03}", s.frames_per_second());
|
||||
println!("F/S = {:.03}", s.rate());
|
||||
println!("B/S = {:.03}", s.beats_per_secon());
|
||||
println!("F/B = {:.03}", s.frames_per_beat());
|
||||
println!("T/B = {:.03}", s.ticks_per_beat());
|
||||
|
|
|
|||
|
|
@ -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