MidiSlider { classvar ccArray, ccAllocator; var cc, function, slider, responder; *initClass { ccArray = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]; // this are the control numbers for your slider box, use these or enter your own ccAllocator = LRUNumberAllocator(0, 16); } *new { arg function; var lrnuAlloc, cc; lrnuAlloc = ccAllocator.alloc; if (lrnuAlloc == nil, { "No more free sliders".postln; ^nil; }, { cc = ccArray.at(lrnuAlloc); ^super.newCopyArgs(cc, function ?? {}).alloc; }); } *slider { arg aSlider; var lrnuAlloc, cc; lrnuAlloc = ccAllocator.alloc; if (lrnuAlloc == nil, { "No more free sliders".postln; ^nil; }, { cc = ccArray.at(lrnuAlloc); ^super.newCopyArgs(cc, {}, aSlider).slider; }); } alloc { responder = CCResponder(cc, function); } slider { responder = CCResponder(cc, { arg val; {slider.value_(val / 127).changed; nil}.defer }); } free { responder.remove; ccAllocator.free(ccArray.atIdentityHash(cc)); } } *************/* authors so far: casey basichis */ |