{
   "labels" : [
      "gui",
      "synthesis",
      "utility",
      "plotter"
   ],
   "id" : "1-5fA",
   "is_private" : null,
   "code" : "s.boot;\r\n\r\n(\r\nvar bufferSize = s.sampleRate * 1; // Buffer size is fixed. s.sampleRate * seconds makes sense.\r\n\r\nif( ~plotterIn == nil, { ~plotterIn = Bus.audio( s, 2 ) } ); // Declare a global channel for the plotter input, stereo\r\n\r\nif( ~plotterBuffer != nil, { ~plotterBuffer.free } ); // Reset the buffer if existant\r\n~plotterBuffer = Buffer.alloc( s, bufferSize, 2 ); // Create our buffer, stereo\r\n\r\nSynthDef( \\toBuffer, { // A simple routing synth\r\n\t| bufNum |\r\n\tvar in = In.ar( ~plotterIn, 2 ); // Takes an input\r\n\tRecordBuf.ar( in, bufNum, loop: 0, doneAction: 2 ); // And outputs it in our buffer\r\n} ).add;\r\n)\r\n\r\n( // Demo Synth\r\nSynthDef( \\demoSynth, {\r\n\t| out = 0, freq = 220 |\r\n\r\n\tvar snd = SinOsc.ar( freq!2 );\r\n\tsnd = snd * EnvGen.kr( Env.perc( 0.1, 0.9 ), doneAction: 2 );\r\n\r\n\tOut.ar( out, snd );\r\n} ).add\r\n)\r\n\r\n(\r\nSynth( \\toBuffer, [ \\bufNum, ~plotterBuffer ] ); // Trigger the buffer synth\r\nSynth( \\demoSynth, [ \\out, ~plotterIn, \\freq, 110 ] ); // Then our favorite synth\r\n)\r\n\r\n// You will need to wait the bufferSize length before plotting it !\r\n~plotterBuffer.plot // Finally print the result\r\n\r\nif( ~plotterBuffer != nil, { ~plotterBuffer.free } ); // Free the buffer if existant",
   "name" : "Buffer Plotter",
   "author" : "Dindoléon",
   "ancestor_list" : [],
   "description" : "This is a setup that allows you to plot a Synth() output, using a buffer. See https://scsynth.org/t/what-is-the-best-way-to-plot-a-synth/5160 ."
}
