| 1 |
/* |
| 2 |
CheeseCutter v2 (C) Abaddon. Licensed under GNU GPL. |
| 3 |
*/ |
| 4 |
|
| 5 |
module audio.timer; |
| 6 |
|
| 7 |
import audio.audio; |
| 8 |
import com.session; |
| 9 |
import ct.base; |
| 10 |
|
| 11 |
__gshared int sec, min; |
| 12 |
__gshared private int clockCounter; |
| 13 |
__gshared private int fplayTickCounter, fplayRowCounter; // how many rows done since last fplay update? |
| 14 |
__gshared private int tickCounter; |
| 15 |
|
| 16 |
int readRowTick() { |
| 17 |
int t = fplayRowCounter; |
| 18 |
fplayRowCounter = 0; |
| 19 |
return t; |
| 20 |
} |
| 21 |
|
| 22 |
int readTick() { |
| 23 |
int t = tickCounter; |
| 24 |
tickCounter = 0; |
| 25 |
return t; |
| 26 |
} |
| 27 |
|
| 28 |
void stop() { |
| 29 |
|
| 30 |
} |
| 31 |
|
| 32 |
/+ from player.start +/ |
| 33 |
void start() { |
| 34 |
sec = min = clockCounter = 0; |
| 35 |
fplayTickCounter = fplayRowCounter = 0; |
| 36 |
} |
| 37 |
/+ should be called each on update from callback +/ |
| 38 |
void tick() nothrow { |
| 39 |
if(++clockCounter >= audio.audio.framerate) { |
| 40 |
clockCounter = 0; |
| 41 |
static import audio.callback; |
| 42 |
audio.callback.maxCycles = 0; |
| 43 |
if(++sec > 59) { |
| 44 |
sec = 0; min++; |
| 45 |
min %= 100; |
| 46 |
} |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
/+ should be called once per frame cycle, updated fplay counters +/ |
| 51 |
void tickFullFrame() nothrow { |
| 52 |
tickCounter++; |
| 53 |
if(++fplayTickCounter > song.playSpeed) { |
| 54 |
fplayRowCounter++; |
| 55 |
fplayTickCounter = 0; |
| 56 |
} |
| 57 |
} |