fix: callbacks trigger on tick 0 not skiped anymore

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

@ -15,25 +15,29 @@ 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) 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 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 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 5. **onClockStartCallback()** on uClock Start event
6. **onClockStopCallback()** there are some 48ppqn based sync devices out there 6. **onClockStopCallback()** on uClock Stop event
```c++ ```c++
// avaliable resolutions #include <uClock.h>
// [ 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
uClock.setPPQN(uClock.PPQN_96);
// you need to use at least one! void setup() {
uClock.setOnPPQN(onPPQNCallback); // avaliable resolutions
uClock.setOnStep(onStepCallback); // [ uClock.PPQN_24, uClock.PPQN_48, uClock.PPQN_96, uClock.PPQN_384, uClock.PPQN_480, uClock.PPQN_960 ]
uClock.setOnSync24(onSync24Callback); // not mandatory to call, the default is 96PPQN if not set
uClock.setOnSync48(onSync48Callback); uClock.setPPQN(uClock.PPQN_96);
// you need to use at least one!
uClock.setOnPPQN(onPPQNCallback);
uClock.setOnStep(onStepCallback);
uClock.setOnSync24(onSync24Callback);
uClock.setOnSync48(onSync48Callback);
uClock.setOnClockStart(onClockStartCallback); uClock.setOnClockStart(onClockStartCallback);
uClock.setOnClockStop(onClockStopCallback); uClock.setOnClockStop(onClockStopCallback);
uClock.init(); uClock.init();
}
``` ```
Resolutions: set youw own resolution for your clock needs 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); //#define ATOMIC(X) portENTER_CRITICAL_ISR(&_uclockTimerMux); X; portEXIT_CRITICAL_ISR(&_uclockTimerMux);
// FreeRTOS main clock task size in bytes // 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; TaskHandle_t taskHandle;
// mutex to protect the shared resource // mutex to protect the shared resource
SemaphoreHandle_t _mutex; SemaphoreHandle_t _mutex;

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

Loading…
Cancel
Save