fix: callbacks trigger on tick 0 not skiped anymore

pull/32/head
midilab 11 months ago
parent b35ba50dc1
commit 51b03d55b6
  1. 8
      README.md
  2. 2
      src/platforms/esp32.h
  3. 26
      src/uClock.cpp

@ -15,10 +15,13 @@ The uClock library API operates through attached callback functions mechanism:
2. **onStepCallback(uint32_t step)** good way to code old style step sequencer based on 16th note schema(not dependent on PPQN resolution)
3. **onSync24Callback(uint32_t tick)** good way to code a clock machine, or keep your gears synced with your device
4. **onSync48Callback(uint32_t tick)** there are some 48ppqn based sync devices out there
5. **onClockStartCallback()** there are some 48ppqn based sync devices out there
6. **onClockStopCallback()** there are some 48ppqn based sync devices out there
5. **onClockStartCallback()** on uClock Start event
6. **onClockStopCallback()** on uClock Stop event
```c++
#include <uClock.h>
void setup() {
// avaliable resolutions
// [ uClock.PPQN_24, uClock.PPQN_48, uClock.PPQN_96, uClock.PPQN_384, uClock.PPQN_480, uClock.PPQN_960 ]
// not mandatory to call, the default is 96PPQN if not set
@ -34,6 +37,7 @@ uClock.setOnClockStart(onClockStartCallback);
uClock.setOnClockStop(onClockStopCallback);
uClock.init();
}
```
Resolutions: set youw own resolution for your clock needs

@ -9,7 +9,7 @@ hw_timer_t * _uclockTimer = NULL;
//#define ATOMIC(X) portENTER_CRITICAL_ISR(&_uclockTimerMux); X; portEXIT_CRITICAL_ISR(&_uclockTimerMux);
// FreeRTOS main clock task size in bytes
#define CLOCK_STACK_SIZE 5012 // adjust for your needs, a sequencer with heavy serial handling should be large in size
#define CLOCK_STACK_SIZE 5*1024 // adjust for your needs, a sequencer with heavy serial handling should be large in size
TaskHandle_t taskHandle;
// mutex to protect the shared resource
SemaphoreHandle_t _mutex;

@ -367,7 +367,7 @@ void uClockClass::handleTimerInt()
{
// External sync is handled here... test if clock check on each tick instead when
// mod24_counter kicks in will help or worst slave timing sync quality
if (mod24_counter == mod24_ref) {
if (mod24_counter == 0) {
if (mode == EXTERNAL_CLOCK) {
// sync tick position with external tick clock
if ((int_clock_tick < ext_clock_tick) || (int_clock_tick > (ext_clock_tick + 1))) {
@ -399,18 +399,18 @@ void uClockClass::handleTimerInt()
if (onSync24Callback) {
onSync24Callback(int_clock_tick);
}
// reset counter
mod24_counter = 0;
// reset counter reference
mod24_counter = mod24_ref;
// internal clock tick me! sync24 tick too
++int_clock_tick;
}
// sync signals first please...
if (onSync48Callback) {
if (mod48_counter == mod48_ref) {
if (mod48_counter == 0) {
onSync48Callback(sync48_tick);
// reset counter
mod48_counter = 0;
// reset counter reference
mod48_counter = mod48_ref;
// sync48 tick me!
++sync48_tick;
}
@ -424,10 +424,10 @@ void uClockClass::handleTimerInt()
if (onStepCallback) {
// we can add a time signature here for call setup based on mod_step_ref
// basic will be 16ths, but let the option to handle unusual sequences
if (mod_step_counter == mod_step_ref) {
if (mod_step_counter == 0) {
onStepCallback(step_counter);
// reset counter
mod_step_counter = 0;
// reset counter reference
mod_step_counter = mod_step_ref;
// going forward to the next step call
++step_counter;
}
@ -444,10 +444,10 @@ void uClockClass::handleTimerInt()
// tick me!
++tick;
// increment mod counters
++mod24_counter;
++mod48_counter;
++mod_step_counter;
// decrement mod counters
--mod24_counter;
--mod48_counter;
--mod_step_counter;
}
// elapsed time support

Loading…
Cancel
Save