int32 BPM

bool32 reset

int32.positive bar

int32.positive part

int32.positive Gcount

int32.positive Scount

bool32 gate

bool32 Bsync

bool32 Psync

int32 M

int32 D

int32 bars

int32 barlength

frac32.s.map start

frac32.s.map timeOffset

frac32.u.map stepsize

frac32.u.map pulselength

frac32.u.map probability

bool32.tgl 1

Declaration

```
uint32_t count;
uint32_t Count;
uint32_t part;
int ntrig;
int trig;
int length;
int C1;
int C2;
int C3;
int G;
int gate;
int32_t stepsize;
int32_t pulsewidth;
int nextbar;
int Brestart;
int rndgate;
int rtrig;
```

Control Rate

```
if ((inlet_reset > 0) && !rtrig == 1) {
rtrig = 1;
count = 0;
C1 = 0;
C2 = 0;
} else if (inlet_reset == 0) {
rtrig = 0;
}
int32_t rate;
rate = (1 << 29) / (48000 >> 7) * inlet_BPM / 60 * param_M / param_D;
count += rate;
Count = count + (param_timeOffset << 5);
length = param_barlength;
stepsize = ___SMMUL(param_barlength << 3, param_stepsize << 2);
pulsewidth =
___SMMUL((stepsize - param_1) << 3, param_pulselength << 2) + param_1;
trig = Count < (1 << 31) ? 1 : 0;
nextbar = 0;
if ((trig > 0) && !ntrig) {
ntrig = 1;
C1 += 1;
nextbar = C1 >= length ? 1 : 0;
C1 = C1 >= length ? 0 : C1;
rndgate = ((int32_t)(GenerateRandomNumber()) >> 4) <
((param_probability << 1) - (1 << 27))
? 1
: 0;
} else if (trig == 0) {
ntrig = 0;
}
Brestart = 0;
if (nextbar > 0) {
C2 += 1;
Brestart = C2 >= param_bars ? 1 : 0;
C2 = C2 >= param_bars ? 0 : C2;
}
G = C1 - ___SMMUL(param_start << 3, length << 2);
G = G - (G / length) * length;
G = G < 0 ? G + length : G;
gate = G - (G / stepsize) * stepsize;
outlet_Gcount = gate;
outlet_Scount = G / stepsize;
gate = gate < 0 ? gate + stepsize : gate;
gate = gate < pulsewidth ? 1 : 0;
outlet_gate = gate + rndgate;
outlet_Bsync = Brestart;
outlet_Psync = nextbar;
outlet_bar = C2;
outlet_part = C1;
```