Trying to build an "always recording" style looper. Need some help/feedback

Hi I am trying to build a looper that’s always on (no recording).

The basic concept is that incoming audio will go through some kind of buffer, then when a button is pressed the last few seconds of audio will repeat endlessly until the button is released. The size of the buffer will be dictated by a bpm number that’s controlled by a knob. So the buffer will always be 2 bars long (at 120bpm 2 bars is 4000 milliseconds.). As the bpm changes so does that buffer size. There will be 3 buttons attributed to loop size that can be selected 1/8, 1/4, and 1/16 that have momentary functionality as well. So when the user holds down the 1/8 button while at 120bpm the looper will repeat the last 250milliseconds of the buffer etc.

Any information into how to make this would be extremely helpful as im still pretty new to plugdata. Im looking into using tabwrite or delwrite and so far haven’t had much luck

We made a looper video that may help you get started: https://www.youtube.com/watch?v=J2WLxiZH7VE

You should be able to apply what we cover here for your project. So rather than pressing the button to start recording like in this video, you can have the recording/overwriting constantly happen in the background and with the looper amplitude at zero. And when you press a button, the recording stops and the amplitude of the loop turns on.