Hi,
i have a problem with the timing or I'm simply to stupid.
I want simply send for each step/16th a note on. This works, but not in same interval.
I have this code:
void GstepAudioProcessor::processBlock ( AudioSampleBuffer& buffer,
MidiBuffer& midiMessages ) noexcept
{
static MidiMessage message = MidiMessage::noteOn ( 1, 60, uint8{127} );
AudioPlayHead::CurrentPositionInfo pos;
if ( getPlayHead() != 0 && getPlayHead()->getCurrentPosition ( pos ) )
{
const double samples_per_tick = 2.5 * getSampleRate() / pos.bpm;
const double samples_per_step = samples_per_tick * 6;
// check if the current buffer include the next step
for ( uint_fast32_t i = pos.timeInSamples;
i <= pos.timeInSamples + buffer.getNumSamples();
++i )
{
// if modula == 0 -> we have a step in this buffer
if ( i % uint_fast32_t {samples_per_step} == 0 )
{
uint_fast32_t absolut_step = i / samples_per_step;
uint_fast8_t relative_step = absolut_step % 16;
// delay in samples for the massage from the current position
int samples_delay = i - pos.timeInSamples;
// output for debug
if ( samples_delay <= 144 ) // jumps at 120 bpm if samples_delay 16,
// 32, 48... until 144
{
std::cout << pos.timeInSamples
<< " rs: " << int {relative_step}
<< " delay: " << samples_delay
<< " stick: " << samples_per_tick
<< " numS: " << buffer.getNumSamples()
<< std::endl;
}
midiMessages.addEvent ( message, samples_delay );
}
}
}
I tryed already some solutions from the net, but all do jump too.
What do i wrong?
Tommy
EDIT: i realize now that should be in the audioPlugin forum? Can anybody move this thread? Thx
