{
   "labels" : [
      "scope",
      "plot",
      "3d"
   ],
   "code" : "/////////////////////////////////////////////////////////////////\r\n// 3D Freq Scope\r\n// You will need PV_MagBuffer (sc3-PlugIns: JoshUGens) and GUI.qt\r\n// heavily inspired by redFrik's \"bufferdisplay\" (http://sccode.org/1-1HR)\r\n\r\n(\r\nb = Buffer.alloc(s, 1024, 1); // FFT\r\nc = Buffer.alloc(s, 1024/2, 1); // Mags\r\nSynthDef(\\magbuf, { |fftbuf, magbuf, freqbuf|\r\n\tvar in, chain;\r\n\tin = SoundIn.ar(0); // <---------- change your input here\r\n//\tin = PMOsc.ar(800, MouseX.kr(10, 800), MouseY.kr(0,40));\r\n\tchain = FFT(fftbuf, in);\r\n\tPV_MagBuffer(chain, magbuf);\r\n//\tOut.ar(0, in)\r\n}).add;\r\n)\r\n\r\n////////////////////////////////////////////////////////////////\r\n// 3D Spectrum vs. Time plotting\r\n(\r\nt = true;\r\n~case = 0;\r\n~amp = 100;\r\nx = Synth(\\magbuf, [\\fftbuf, b, \\magbuf, c]); \r\nw = Window(\"3D SCOPE\", Rect(600, 400, 800, 600)).front;\r\nw.view.keyDownAction_{ |view, char, xxx, code| if(code==32){ w.refresh; t = t.not; u.animate = t; } };\r\nu = UserView(w, w.view.bounds);\r\nu.background = Color.black;\r\nu.animate = t;\r\nu.frameRate = 30;\r\nu.clearOnRefresh = false;\r\nu.drawFunc = { |view|\r\n\tvar i = view.frame;\r\n\tvar ypos = i % 500;\r\n\tvar xpos = 200 - (ypos/3);\r\n\tvar numFreqs = 512;\r\n\tvar lineColor = Color.hsv(ypos/500, 0.5, 0.5, 0.3);\r\n\t// var lineColor = Color.green.alpha_(0.5); // for retro style\r\n\t\r\n\tif( ypos == 0 ) { Pen.fillColor = Color.black; Pen.fillRect(view.bounds) }; // clear on new begin\r\n\r\n\tc.getn(0, numFreqs-1, { |v| d = v }); // get mag buffer data\r\n\t\r\n\tPen.strokeColor = lineColor;\r\n\tPen.moveTo(0, 0); // init\r\n\tPen.translate(xpos, ypos + 100); // scan down\r\n\t\r\n\tswitch(~case,\r\n\t\t// lines\r\n\t\t0, {\r\n\t\t\td.do{ |y, x|\r\n\t\t\t\tif(y.isNil.not){ Pen.lineTo(Point(x*(600/numFreqs), (y/64).tanh.neg * ~amp)) };\r\n\t\t\t};\r\n\t\t\tPen.stroke;\r\n\t\t},\r\n\t\t// dots\r\n\t\t1, {\r\n\t\t\td.do{ |y, x|\r\n\t\t\t\tPen.fillColor = lineColor;\r\n\t\t\t\tif(y.isNil.not){ Pen.addOval(Rect.aboutPoint(Point(x*(600/numFreqs), (y/64).tanh.neg * ~amp), 1, 1)) };\r\n\t\t\t\tPen.fill;\r\n\t\t\t};\r\n\t\t},\r\n\t\t{ nil }\r\n\t);\r\n\t\r\n};\r\nw.onClose_{ x.free };\r\n);\r\n\r\n~case = 0; // draw continuous lines\r\n~case = 1; // draw points\r\n~amp = 200; // change the amp scaling",
   "is_private" : null,
   "id" : "1-4RN",
   "author" : "rukano",
   "name" : "3D Scope",
   "ancestor_list" : [],
   "description" : "This was inspired by http://sccode.org/1-1HR and a student wanted to do a 3D freq/spectrum plot over time.\r\nThe colors are just for extra funkyness.... feel free to change it to standerd retro green and scale the freqs and magnitudes at will ;)"
}
