{
   "code" : "(\r\n/* Harmo module, licensed under GNU GPL v3 (<https://www.gnu.org/licenses/>),\r\n\r\nAdapted by Simon Deplat (aka Dindoleon), but mostly written by Bruno Ruviaro in his 'Additive Synthesis GUI DEMO 2' patch (see http://sccode.org/1-4Uv ).\r\n\r\nThis is a standalone module which allows you to shape a continuous tone by modifying the amplitude of its harmonic. The major change with Ruviaro's version is the plot display, rather than bar charts display (see lines 65 - 66), and the over simplification of the interface.\r\n\r\nThis is a good visual tool to introduce the notions of harmonics and timbre, due to its simplicity.\r\n\r\nReplace the mulstiSlider's 'win' argument by a View to integrate it inside another GUI.\r\n*/\r\n\r\nvar win, window_size, synth, spectrum, numharm, ampBus, sndBus, multiSlider, margin, frame_color, fill_color, line_color;\r\n\r\nwindow_size = [ 500, 300 ];\r\nmargin = 3;\r\n\r\nframe_color = Color.blue;\r\nline_color = Color.new( 0.2, 0.6, 1 );\r\nfill_color = Color.white;\r\n\r\nnumharm = 32;\r\n\r\nampBus = Bus.control(s);\r\nampBus.value = 0.1;\r\nsndBus = Bus. audio(s, 2);\r\n\r\n// Routine to add SynthDefs, wait for Server reply, then start Synths\r\n{\r\n\t// The SynthDef has been modified to store the harmonic number inside it, allowing to change the root frequency for every harmonic at once.\r\n\tSynthDef(\"additive-multislider\", {\r\n\t\targ outbus, freq = 110, amp = 0.01, freq_mul = 1;\r\n\t\tvar snd = SinOsc.ar(freq * freq_mul, 0, Lag.kr(amp, 3));\r\n\t\tOut.ar(outbus, snd!2);\r\n\t}).add;\r\n\r\n\tSynthDef(\"continuousOut\", {\r\n\t\targ inbus, amp = 0.1, gate = 1, att = 0.1, sus = 1, rel = 1;\r\n\t\tvar env = EnvGen.kr(Env.asr(att, sus, rel), gate);\r\n\t\tOut.ar(0, In.ar(inbus, 2) * amp * env * 0.05);\r\n\t}).add;\r\n\r\n\t// Wait for SynthDefs to be added...\r\n\ts.sync;\r\n\r\n\t// Now call the Synths:\r\n\tspectrum = Array.fill(numharm, {arg i; Synth(\"additive-multislider\", [\\freq, 440, \\freq_mul, (i+1), \\amp, 0.0, \\outbus, sndBus])});\r\n\r\n\tsynth = Synth(\"continuousOut\", [\\inbus, sndBus, \\amp, ampBus.asMap], addAction: \\addToTail);\r\n\r\n}.fork;\r\n\r\nwin = Window(\"Harmo\", Rect(0, 0, window_size[0], window_size[1]), false);\r\nwin.background_( frame_color );\r\n\r\n// Multislider\r\nmultiSlider = MultiSliderView(win, Rect( margin, margin, window_size[0] - ( margin * 2 ), window_size[1] - ( margin * 2 ) ));\r\nmultiSlider.value = Array.fill(numharm, {0.0});\r\nmultiSlider.isFilled = true;\r\nmultiSlider.elasticMode_(true);\r\nmultiSlider.fillColor = fill_color;\r\nmultiSlider.strokeColor = line_color;\r\nmultiSlider.gap = 0;\r\nmultiSlider.drawRects = false; // Display as bar charts\r\nmultiSlider.drawLines = true; // Display as plot\r\n\r\nmultiSlider.action = {arg multi;\r\n\tvar index = multi.index;\r\n\tvar value = multi.currentvalue;\r\n\tspectrum[index].set(\\amp, value-0.01*2); };\r\n\r\nwin.front;\r\n)",
   "id" : "1-5b0",
   "is_private" : null,
   "labels" : [
      "gui",
      "harmonic",
      "fork",
      "module",
      "multislider"
   ],
   "description" : "MultiSlider plot display allowing to shape a harmonic series. This is a simplification of Bruno Ruviaro's Additive Synthesis GUI Demo 2.",
   "ancestor_list" : [],
   "name" : "Harmo : Harmonic Series modulated by a MultiSlider interface.",
   "author" : "Dindoléon"
}
