I am horrified to ask this.
I am trying to create an expanding interval series and use that to count my way around a certain pitch range either up or down using a counter.
So if we were going down we would define a top note to start on and a bottom note as a lower bound that we would go modulo around as if the keyboard was circular. We are counting keys like we are Tom Johnson or something.
So imagine our top note is A5 just above the treble staff and we want to wrap around at G3. We want to count down from that note a 1/2 step and we arrive at Ab. Now from Ab we count down a whole step to Gb. Now from Gb down a minor third (3steps) to Eb then 4 steps to B4, 5steps down to C and then 6 down to F etc. when we reach the last key we wrap around and keep counting from the top as if the last key and the first key were attached.
This isn't exactly what i want but a vastly simplified version of the problem and i feel like if i can get this to work in both directions with a simple expanding series without a stack overflow or an "off by one" error, then I could add all the other fancy layers on to that. I have coded something like this up in C in like 10 minutes, for some reason the max part of my brain can't see what is wrong. Must be some easier, more bulletproof way to do this than what i am doing. I have reduced it to it simplest form and it is still hosed.
I was "off by one" but now it seems to work only counting up. It gives a stack overflow in the other direction. Added to this is my feeble attempt to visualize the pattern in a histogram and also capture it as MIDI data. Surprisingly this part seems to work.