From 3158a724f8096825084201f090caa305eb99c3de Mon Sep 17 00:00:00 2001 From: midilab Date: Mon, 5 Nov 2018 07:05:47 -0200 Subject: [PATCH] force static inline on clock_diff and phase_mult(just to make sure the gcc will do it for us) --- src/uClock.cpp | 44 ++++++++++++++++++++++---------------------- src/uClock.h | 40 ++++++++++++++++++++++++---------------- 2 files changed, 46 insertions(+), 38 deletions(-) diff --git a/src/uClock.cpp b/src/uClock.cpp index 8411dbe..52be478 100755 --- a/src/uClock.cpp +++ b/src/uClock.cpp @@ -31,10 +31,25 @@ namespace umodular { namespace clock { +static inline uint32_t phase_mult(uint32_t val) +{ + return (val * PHASE_FACTOR) >> 8; +} + +static inline uint16_t clock_diff(uint16_t old_clock, uint16_t new_clock) +{ + if (new_clock >= old_clock) { + return new_clock - old_clock; + } else { + return new_clock + (65535 - old_clock); + } +} + uClockClass::uClockClass() { init(); mode = INTERNAL_CLOCK; + state = PAUSED; setTempo(120); onClock96PPQNCallback = NULL; @@ -71,21 +86,6 @@ void uClockClass::init() SREG = tmpSREG; } -uint16_t clock_diff(uint16_t old_clock, uint16_t new_clock) -{ - if (new_clock >= old_clock) { - return new_clock - old_clock; - } else { - return new_clock + (65535 - old_clock); - } -} - -#define PHASE_FACTOR 16 -static uint32_t phase_mult(uint32_t val) -{ - return (val * PHASE_FACTOR) >> 8; -} - void uClockClass::start() { start_timer = millis(); @@ -93,7 +93,7 @@ void uClockClass::start() if (onClockStartCallback) { onClockStartCallback(); } - + if (mode == INTERNAL_CLOCK) { state = STARTED; mod6_counter = 0; @@ -148,11 +148,11 @@ void uClockClass::setTempo(uint16_t _tempo) return; } - if ( tempo == _tempo ) { + if (tempo == _tempo) { return; } - if ( _tempo > 300 || _tempo == 0 ) { + if (_tempo > 300 || _tempo == 0) { return; } @@ -180,8 +180,8 @@ void uClockClass::setMode(uint8_t tempo_mode) void uClockClass::clockMe() { - if (uClock.mode == uClock.EXTERNAL_CLOCK) { - uClock.handleClock(); + if (mode == EXTERNAL_CLOCK) { + handleClock(); } } @@ -337,7 +337,7 @@ uint32_t uClockClass::getNowTimer() uint32_t uClockClass::getPlayTime() { return start_timer; -} +} } } // end namespace umodular::clock @@ -354,7 +354,7 @@ ISR(TIMER1_OVF_vect) // global timer counter _timer = millis(); - if (uClock.state == uClock.STARTED) { + if (uClock.state == umodular::clock::STARTED) { _clock++; uClock.handleTimerInt(); } diff --git a/src/uClock.h b/src/uClock.h index 8526a15..bdb5bbf 100755 --- a/src/uClock.h +++ b/src/uClock.h @@ -33,16 +33,29 @@ #include #include +#define PHASE_FACTOR 16 + #define SECS_PER_MIN (60UL) #define SECS_PER_HOUR (3600UL) #define SECS_PER_DAY (SECS_PER_HOUR * 24L) namespace umodular { namespace clock { -class uClockClass { +enum { + PAUSED = 0, + STARTING, + STARTED +} state; - public: +enum { + INTERNAL_CLOCK = 0, + EXTERNAL_CLOCK +} mode; + +class uClockClass { + private: + void (*onClock96PPQNCallback)(uint32_t * tick); void (*onClock32PPQNCallback)(uint32_t * tick); void (*onClock16PPQNCallback)(uint32_t * tick); @@ -62,18 +75,12 @@ class uClockClass { uint16_t pll_x; uint16_t tempo; uint32_t start_timer; + uint8_t mode; + + public: - enum { - PAUSED = 0, - STARTING, - STARTED - } state; - - enum { - INTERNAL_CLOCK = 0, - EXTERNAL_CLOCK - } mode; - + uint8_t state; + uClockClass(); void setClock96PPQNOutput(void (*callback)(uint32_t * tick)) { @@ -107,11 +114,12 @@ class uClockClass { void setTempo(uint16_t tempo); uint16_t getTempo(); - // External timming control + // external timming control void setMode(uint8_t tempo_mode); uint8_t getMode(); void clockMe(); + // todo! void shuffle(); void tap(); @@ -130,8 +138,8 @@ class uClockClass { extern umodular::clock::uClockClass uClock; extern "C" { -extern volatile uint16_t _clock; -extern volatile uint32_t _timer; + extern volatile uint16_t _clock; + extern volatile uint32_t _timer; } #endif /* __U_CLOCK_H__ */