Wow! This is incredibly cool. I was trying to use C preprocessor for this kind of semi-object-oriented stuff but 16 chars limit prevented me from using token pasting effectively. Just when I was considering to write my own preprocessor I saw this thread. And it all happened
today!
Here's a small but useful js function, just to show that this new addition opens up some very cool possibilities that may not be immediately recognizable:
Code:
@init
function malloc(size)
local(result)
(
result = heapTop;
heapTop += ceil(size);
result;
);
// Allocate 200 ms delay buffers for each channel
delayBufferL = malloc(srate * 0.200);
delayBufferR = malloc(srate * 0.200);
// Report memory usage
freembuf(heapTop);
Automatic memory management for JS
One can also declare heapTop as an instance variable to avoid polluting the global namespace. I love it!
Now this addition begs for an
include file functionality (in case it doesn't exist already), with a dedicated Effects\Include folder so we can immediately start rolling reusable DSP libraries for interpolated delay buffers, biquad filters etc.