Quote:
Originally Posted by IXix
Code:
current_pos = beat_position % sequence_length;
|
This, but keep in mind % returns an integer. If you want a fractional position you need to use fmod
Code:
function fmod (n, k) (
n - k * floor(n/k);
);
current_pos = fmod(beat_position, sequence_length);
If you want the sequencer to go along but not be tied to the arrangement specific position you can use something along the lines of
Code:
@block
beat_per_spl = tempo / (srate * 60);
beat_per_block = beat_per_spl * samplesblock;
//This replaces beat_position
bp += beat_per_block;
//Fractional position
current_pos = fmod(bp, sequence_length);
//Integer position
current_beat = floor(current_pos);
This will play even if transport is stopped, so if it's not desirable you've got to check play_state.
Then you can
Code:
@block
beat_per_spl = tempo / (srate * 60);
beat_per_block = beat_per_spl * samplesblock;
bp += beat_per_block;
current_pos = fmod(bp, sequence_length);
next_block_pos = fmod(bp + beat_per_block, sequence_length);
//Next block is going to start during next beat
floor(current_pos) != floor(next_block_pos) ? (
//How far is next beat
beat_offset = ceil(cur_position) - cur_position;
spl_offset = beat_offset / beat_per_block * samplesblock;
midisend(spl_offset, [...]);
);
The advantage being that you can do stuff like
Code:
beat_per_block = beat_per_spl * samplesblock;
beat_per_block *= speed;
And if you need it to be sync with transport you can do
Code:
@init
is_init = 0;
@block
//beat_position is not available in @init so you need to set it here
!is_init ? (
is_init = 1;
bp = beat_position;
);