CallbackRepeater.cpp (672B)
1 /* 2 ZynAddSubFX - a software synthesizer 3 4 CallbackRepeater.cpp - Timed Callback Container 5 Copyright (C) 2016 Mark McCurry 6 7 This program is free software; you can redistribute it and/or 8 modify it under the terms of the GNU General Public License 9 as published by the Free Software Foundation; either version 2 10 of the License, or (at your option) any later version. 11 */ 12 #include "CallbackRepeater.h" 13 14 namespace zyn { 15 16 CallbackRepeater::CallbackRepeater(int interval, cb_t cb_) 17 :last(time(0)), dt(interval), cb(cb_) 18 {} 19 20 void CallbackRepeater::tick(void) 21 { 22 auto now = time(0); 23 if(now-last > dt && dt >= 0) { 24 cb(); 25 last = now; 26 } 27 } 28 29 }