Merge pull request #55 from awonak/develop

Add External Clock BPM Constrain Method
develop
midilab 2 weeks ago committed by GitHub
commit d554229f92
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 15
      src/uClock.cpp
  2. 1
      src/uClock.h

@ -254,7 +254,7 @@ float uClockClass::getTempo()
acc += ext_interval_buffer[i]; acc += ext_interval_buffer[i];
} }
if (acc != 0) { if (acc != 0) {
return freqToBpm(acc / ext_interval_buffer_size); return constrainBpm(freqToBpm(acc / ext_interval_buffer_size));
} }
} }
return tempo; return tempo;
@ -275,6 +275,11 @@ float inline uClockClass::freqToBpm(uint32_t freq)
return (float)((float)(usecs/(float)input_ppqn) * 60.0); return (float)((float)(usecs/(float)input_ppqn) * 60.0);
} }
float inline uClockClass::constrainBpm(float bpm)
{
return (bpm < MIN_BPM) ? MIN_BPM : ( bpm > MAX_BPM ? MAX_BPM : bpm );
}
void uClockClass::setClockMode(ClockMode tempo_mode) void uClockClass::setClockMode(ClockMode tempo_mode)
{ {
clock_mode = tempo_mode; clock_mode = tempo_mode;
@ -492,12 +497,10 @@ void uClockClass::handleTimerInt()
} }
// update internal clock timer frequency // update internal clock timer frequency
float bpm = freqToBpm(counter); float bpm = constrainBpm(freqToBpm(counter));
if (bpm != tempo) { if (bpm != tempo) {
if (bpm >= MIN_BPM && bpm <= MAX_BPM) { tempo = bpm;
tempo = bpm; setTimerTempo(bpm);
setTimerTempo(bpm);
}
} }
} }

@ -184,6 +184,7 @@ class uClockClass {
private: private:
float inline freqToBpm(uint32_t freq); float inline freqToBpm(uint32_t freq);
float inline constrainBpm(float bpm);
void calculateReferencedata(); void calculateReferencedata();
// shuffle // shuffle

Loading…
Cancel
Save