«UPIC waveform editor» by snappizz
on 12 Feb'14 00:21 inA fun little GUI toy emulating a freehand waveform editor as seen in Iannis Xenakis' UPIC software. Draw on the graph to edit an oscillator's waveform in realtime.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
s.waitForBoot({ var size = 1024; var canvas, reset, test; var wave, waveBuf, testSynth; var draw, lastPos, lastVal, update; w = Window("Waveform editor", Rect(100, 100, 800, 330)); wave = Signal.sineFill(size, [1]); waveBuf = Buffer.alloc(s, size * 2); ~waveBuf = waveBuf; testSynth = nil; update = { waveBuf.loadCollection(wave.asWavetable); }; lastPos = nil; lastVal = nil; draw = { |me, x, y, mod, btn| var pos = (size * (x / me.bounds.width)).floor, val = (2 * (y / me.bounds.height)) - 1; val = min(max(val, -1), 1); wave.clipPut(pos, val); if(lastPos != nil, { for(lastPos + 1, pos - 1, { |i| wave.clipPut(i, lastVal + (((i - lastPos) / (pos - lastPos)) * (val - lastVal))); }); for(pos + 1, lastPos - 1, { |i| wave.clipPut(i, lastVal + (((i - lastPos) / (pos - lastPos)) * (val - lastVal))); }); }); lastPos = pos; lastVal = val; update.value; }; canvas = UserView(w, Rect(0, 30, 800, 300)) .background_(Color.white) .animate_(true) .mouseDownAction_(draw) .mouseMoveAction_(draw) .mouseUpAction_({ lastPos = nil; lastVal = nil; }) .drawFunc_({ |me| Pen.moveTo(0@(me.bounds.height * (wave[0] + 1) / 2)); for(1, size - 1, { |i, a| Pen.lineTo((me.bounds.width * i / size)@(me.bounds.height * (wave[i] + 1) / 2)) }); Pen.stroke; }); reset = Button(w, Rect(0, 0, 60, 30)) .states_([["Reset"]]) .action_({ wave.sineFill([1]); update.value; }); test = Button(w, Rect(60, 0, 60, 30)) .states_([["Test"], ["Stop"]]) .action_({ |me| if(me.value == 1, { update.value; testSynth = { var sig; sig = Osc.ar(waveBuf, MouseY.kr(30, 1000)) * 0.1; sig = LeakDC.ar(sig); sig = sig!2; }.play; }, { testSynth.free; }); }); w.onClose_({ testSynth.free; wave.free; }); w.front; });
reception
Is it possible to save the waveform?
The latest version sets "~waveBuf" to point to the buffer, so you can access it even after the editor is closed. (It's in wavetable format, so use Osc to play it and not, say, PlayBuf.)