4. VM State
typedef struct trig_state trig_state;
The idea here is to have a component that allows multiple readers to read from one pool. This sort of functionality would make it easier for a single Trig instance to play multiple sequences.
It is initialized with trig_state_init
.
void trig_state_init(trig_state *ts);
void trig_state_init(trig_state *ts)
{
<<trig_state_init>>
}
Two big things that an independent VM state would need: counter + cell position.
For convenience purposes, an optional pointer holding
trig_vm
is also part of the state. This makes it easier
to wrap a graforge node around a reader.
struct trig_state {
int counter;
int pos;
int ipos;
void *ud;
};
ts->counter = -1;
ts->pos = 0;
ts->ipos = 0;
ts->ud = NULL;
The data in the trig_state
struct can be set/get with
trig_state_ud_set
and trig_state_ud_get
.
void trig_state_ud_set(trig_state *state, void *ud);
void * trig_state_ud_get(trig_state *state);
void trig_state_ud_set(trig_state *state, void *ud)
{
state->ud = ud;
}
void * trig_state_ud_get(trig_state *state)
{
return state->ud;
}
If vm is not empty, trig_state_step
can run
trig_vm_state_step
internally.
An initial position, ipos
, dictates where to start.
Internally, this is represented as an 0-indexed array
offset. Externally, the values are 1-indexed in order
for it to make it align more with the visuals.
void trig_state_ipos(trig_state *state, int ipos);
void trig_state_ipos(trig_state *state, int ipos)
{
if (ipos < 1 || ipos > 32) return;
state->ipos = ipos - 1;
}
A state can be reset with trig_state_reset
. This sets
the pos to be ipos
.
void trig_state_reset(trig_state *state);
void trig_state_reset(trig_state *state)
{
state->pos = state->ipos;
state->counter = -1;
}
prev | home | next