davidlang42 / midi-arpeggiator

A CLI tool which reads held notes from MIDI-IN and arpeggiates them to MIDI-OUT
GNU General Public License v3.0
0 stars 0 forks source link

Implement BpmDetector settings getter #6

Open davidlang42 opened 1 year ago

davidlang42 commented 1 year ago

Concept: Determine settings based on the MIDI CLOCK speed (bpm) With this test code in passthrough_midi() I was able to get an accurate read up to 200bpm on laptop (but need to confirm on pi0)

MidiMessage::TimingClock => {
    self.ticks += 1;
    if self.ticks == 24 {
        self.ticks = 0;
        let now = Instant::now();
        let ns = now.duration_since(self.last_tick).as_nanos();
        self.last_tick = now;
        let bpm = (60000000000.0 / ns as f64).round() as usize;
        if bpm != self.last_bpm {
            self.last_bpm = bpm;
            println!("{}ns = {}bpm", ns, bpm);
        }
    }
    Some(message)
}
davidlang42 commented 1 year ago

Partially implemented in https://github.com/davidlang42/midi-arpeggiator/commit/f82bf765d0a470bcb34435962e2b6d25385ddd18