realearn icon indicating copy to clipboard operation
realearn copied to clipboard

Throttle feedback messages

Open TheSoundOfOneHandClapping opened this issue 3 years ago • 3 comments

Incorporate an option to throttle feedback messages. Some controllers (Arturia BeatStep in my case) are too slow to handle the feedback messages at the speed they are currently sent out. I wrote a jsfx plugin to slows down the messages to around 1 message per millisecond which works fine. But it would be preferable to have it natively supported in the plugin. thanks

@TheSoundOfOneHandClapping Could you paste the JSFX code? Want to check if we have the same idea of "throttling".

helgoboss avatar Apr 21 '22 12:04 helgoboss

Here's the code for the ReaLearn Throttler (it's based on the reaper's "MIDI Delay") For the Arturia BeatStep I set the slider to 1ms. Hope this helps

desc:ReaLearn Throttler

slider1:0<0,50,0.1>Throttle (ms)

in_pin:none
out_pin:none

@init
ext_midi_bus=ext_nodenorm=1;
buf_l = buf_r = 0;
buf_hdr = 3; // position, length (incl header), bus
max_ram = __memtop();
newOffs = 0;
lastOffs = 0;

@block
delay_samples = floor((slider1*0.001)*srate + 0.5);
delay_sc = (delay_samples + samplesblock);
delay_isc = 1 / delay_sc;

// process incoming events
while( (l = midirecv_buf(offs, buf_r+buf_hdr, max_ram-buf_r-buf_hdr) ) > 0 )
(
  newOffs = ((offs-lastOffs) < delay_samples) ? lastOffs + delay_samples : offs;
  lastOffs = newOffs;
  buf_r[0] = newOffs;
  buf_r[1] = buf_hdr + l;
  buf_r[2] = midi_bus;
  buf_r += buf_hdr + l;
);

lastOffs-= samplesblock;
lastOffs<0 ? lastOffs = 0; 

// process outgoing events
rd = buf_l;
while (rd<buf_r)
(
  rd==buf_l && (offs=rd[0]) < samplesblock ? (
    midi_bus=rd[2];
    l = rd[1];
    midisend_buf(max(offs,0),rd+buf_hdr,l-buf_hdr);
    buf_l = (rd += l);
  ) : (
    rd[0] -= samplesblock;
    rd += rd[1];
  );
);

// compact buf if needed
buf_l >= buf_r ? (
  buf_l=buf_r=0;
) : (
  buf_l > max(1024,buf_r*.5) ? (
    (buf_r-=buf_l) > 0 ? memcpy(0,buf_l,buf_r) : buf_r=0;
    buf_l=0; 
  );
);

Thanks!

helgoboss avatar Apr 21 '22 14:04 helgoboss