{
   "author" : "blueprint",
   "name" : "Quneo Additive synth with modulation and filters.",
   "description" : "This is an additive synth using a sinOscFb with an lfo and an RLPF ... \r\nit's desiqned for the quneo controller.\r\nThe pads control note and velocity as you would expect and the x/y controll modulation frequency and depth. Pad presssure controls the add factor of the modulation AND the resonace of the filter.\r\n\r\nBased on the code from http://sccode.org/1-4UO Bruno Ruviaro, 2013-07-22 .\r\nThis version does clean midi note handling and uses the lovely controls.",
   "ancestor_list" : [],
   "labels" : [
      "synth",
      "quneo"
   ],
   "code" : "// ************************************\r\n// Additive Synthesis Demo with QuNEO\r\n// based on patch by http://sccode.org/1-4UO Bruno Ruviaro, 2013-07-22\r\n// this version, blueprint@poetaster.de\r\n// tested in SC 3.6 and 3.9 (including on the pi prynth platform)\r\n// ************************************\r\n\r\n/*\r\nUse QuNEO default preset #1\r\n\r\nPads play 16 first partials of the harmonic series:\r\n\r\n13 14 15 16\r\n09 10 11 12\r\n05 06 07 08\r\n01 02 03 04\r\n\r\nLong Slider controls fundamental frequency\r\nVertical Sliders control ADSR envelope\r\nTop two horizontal sliders control the frequency and the resonance of a filter.\r\n\r\nThe pad note and velocity control the usual factors, freq. and amplitude.\r\nThe pad x / y control values control the frequency and depth of modulation.\r\nThe pad pressure controls the add amount of the lfo from x/y \r\nand also the resonance of the filter.\r\n*/\r\n\r\ns.waitForBoot({\r\n\r\n\t// Some variables\r\n\r\n\tvar notes = Array.newClear(64);\r\n\tvar ints = Array.series(16, 36, 1);\r\n\r\n\t~att = 0.01;\r\n\t~dec = 0.3;\r\n\t~sus = 0.5;\r\n\t~rel = 1.0;\r\n\t~lpfFreq = 0.5;\r\n\t~lpfRes = 0.5;\r\n\t~fundamental = 110;\r\n\t~quNeoChannel = 0;\r\n\r\n\tMIDIIn.connectAll;\r\n\r\n\t//MIDIdef.freeAll;\r\n\r\n\tMIDIdef.noteOn(\r\n\t\tkey: \\noteOn,\r\n\t\tfunc: { arg vel, note;\r\n\t\t\tvar node, partial;\r\n\t        node = notes.at(note);\r\n\t\t\tif ( node.notNil, { node.set(\\gate,0); notes.put(note, nil) } );\r\n\t\t\tpartial = note - 35; // start from 1\r\n\t\t\tnotes[note] = Synth(\"addsynth\", [\r\n\t\t\t\t\\freq, ~fundamental * partial,\r\n\t\t\t\t\\amp, vel.linlin(0, 127, 0.1,0.8),\r\n\t\t\t\t\\att, ~att,\r\n\t\t\t\t\\dec, ~dec,\r\n\t\t\t\t\\sus, ~sus,\r\n\t\t\t\t\\rel, ~rel,\r\n\t\t\t\t\\lpfFreq, ~lpfFreq,\r\n\t\t\t\t\\lpfRes, ~lpfRes])},\r\n\t\tnoteNum: (29..127), // Ignore notes lower than 24 (= 46Hz)\r\n\t\tchan: ~quNeoChannel);\r\n\r\n\tMIDIdef.noteOff(\r\n\t\tkey: \\noteOff,\r\n\t\tfunc: {arg vel, note;\r\n\t\t\tnotes[note].set(\\gate,0);\r\n\t\t\tnotes.put(note, nil);\r\n\t\t//(\"Note OFF \"++ note).postln;\r\n\t\t},\r\n\t\tchan: ~quNeoChannel);\r\n\r\n\tMIDIdef.cc(\r\n\t\tkey: \\adsr,\r\n\t\tfunc: {arg val, ccnum;\r\n\t\t\tcase\r\n\t\t\t{ccnum==6} {~att = val.linlin(0, 127, 0.01, 2)}\r\n\t\t\t{ccnum==7} {~dec = val.linlin(0, 127, 0.05, 1)}\r\n\t\t\t{ccnum==8} {~sus = val.linlin(0, 127, 0.25, 1)}\r\n\t\t\t{ccnum==9} {~rel = val.linlin(0, 127, 0.5, 2)}\r\n\t\t\t{ccnum==0} {~lpfFreq = val.linlin(0, 127, 0.1, 1.0)}\r\n\t\t\t{ccnum==1} {~lpfRes = val.linlin(0, 127, 0.0, 2.0)};\r\n\t\t\t[~att, ~dec, ~sus, ~rel, ~lpfFreq, ~lpfRes].round(0.01).postln},\r\n\t\tccNum: [6,7,8,9,0,1]); // Vertical Sliders\r\n\r\n\t//pad controllers for various factors\r\n\r\n   // vibrato add value + amplitude\r\n\tMIDIdef.cc(\r\n\t\tkey: \\synAmp,\r\n\t\tfunc: {arg val, ccnum, n;\r\n\t\t\tn = (ccnum - 23).linlin(1,48,1,16).round ; // map the pressure controller to it's note.\r\n\t\t\tn = n + 35 ; // offset to 36\r\n\t\t\t//(\"cc is \"++ ccnum).postln;\r\n\t\t\tnotes[n].set(\\vibAdd,  val.linlin(0, 127, 0.1, 0.6));\r\n\t\t\tnotes[n].set(\\lpfRes,  val.linlin(0, 127, 0.1, 0.9));\r\n\t\t},\r\n\t\tccNum: Array.series(50,23,3));\r\n\r\n\t\t//[23,26,29,32,35,38,41,44,47,50,53,56,59,62,65,68]);\r\n\t// vibrato frequency\r\n\tMIDIdef.cc(\r\n\t\tkey: \\vibF,\r\n\t\tfunc: {arg val, ccnum, n;\r\n\t\t\tn = (ccnum - 23).linlin(1,48,1,16).round ; // map the x controller to vibrato freq\r\n\t\t\tn = n + 35 ; // offset to 36\r\n\t\t\t//(\"Note is \"++ n).postln;\r\n\t\t\tnotes[n].set(\\vibFreq,  val.linlin(0, 127, 0.05, 0.99));\r\n\t\t},\r\n\t\tccNum: Array.series(50,24,3));\r\n\r\n       // vibrato amplitude\r\n\t\tMIDIdef.cc(\r\n\t\tkey: \\vibA,\r\n\t\tfunc: {arg val, ccnum, n;\r\n\t\t\tn = (ccnum - 23).linlin(1,48,1,16).round ; // map the y controller to the vibrato depth\r\n\t\t\tn = n + 35 ; // offset to 36\r\n\t\t\t//a(\"note is \" ++ n).postln;\r\n\t\t\tnotes[n].set(\\vibAmp, val.linlin(0, 127, 0.1, 0.5));\r\n\t\t},\r\n\t\tccNum: Array.series(50,25,3));\r\n\r\n\r\n\tMIDIdef.cc(\r\n\t\tkey: \\fundamental,\r\n\t\tfunc: {arg val, ccnum;\r\n\t\t\t~fundamental = val.linexp(0, 127, 55, 220);\r\n\t\t\t(\"Fundamental is \"++~fundamental.round(0.1)++\" Hz\").postln},\r\n\t\tccNum: 10);  // Long Slider\r\n\r\n\t// A synth\r\n\r\n\tSynthDef(\"addsynth\", { arg freq = 440, amp = 0.1, gate = 1, att = 0.01, dec = 0.3, sus = 0.5, rel = 1,vibFreq=7, vibAmp=0,vibAdd=0.5,lpfFreq = 0.5, lpfRes = 0.5;\r\n\t\tvar snd, env;\r\n\t\tlpfFreq = lpfFreq * (freq * 3) + ~fundamental;\r\n\t\tlpfRes = 1 - lpfRes * 0.9 + 0.1;\r\n\t\tenv = EnvGen.ar(Env.adsr(att, dec, sus, rel, amp), gate, doneAction: 2);\r\n\t\tsnd = SinOscFB.ar(freq, vibAmp, amp);\r\n\t\tsnd = snd * SinOsc.kr(vibFreq*15, mul:vibAmp, add:vibAdd);\r\n\t\tsnd = snd * env;\r\n\t\t//snd = snd * doneActionEnv * 0.5;\r\n\t\tOut.ar([0,1], RLPF.ar(snd, lpfFreq,lpfRes));\r\n\t}).add;\r\n\r\n});",
   "is_private" : null,
   "id" : "1-5ah"
}
