{
   "labels" : [
      "gui",
      "synthesis techniques",
      "amplitude modulation"
   ],
   "id" : "1-4Uy",
   "is_private" : null,
   "code" : "// ************************************\r\n// Amplitude Modulation (GUI)\r\n// Patch 1 - Basic Demo\r\n// Bruno Ruviaro, 2013-08-02\r\n// ************************************\r\n\r\n/*\r\n\r\nVery simple interface to play with basic amplitude modulation.\r\nAmplitude Modulation (AM): one oscillator controls the amplitude of another.\r\nImagine a note the amplitude of which goes up and down at a given speed.\r\n\r\nSelect all (ctrl + A), then evaluate (ctrl + period).\r\nWatch the spectrum on the Frequency Analyzer window.\r\n\r\n*/\r\n\r\ns.waitForBoot({\r\n\r\n\tvar win, carrFreqKnob, carrFreqNumber, carrFreqLabel, modFreqKnob, modFreqNumber, modFreqLabel, volumeSlider, defaultFont, carrSpec, modSpec, synth;\r\n\r\n\tdefaultFont = Font(\"Verdana\", 16, bold: true);\r\n\r\n\t// Main window\r\n\tWindow.closeAll;\r\n\tFreqScope.new;\r\n\twin = Window.new(\"Amplitude Modulation\", Rect(20, 400, 610, 280));\r\n\twin.onClose = {s.freeAll; Window.closeAll; \"Amplitude Modulation window closed.\".postln; \"\".postln};\r\n\twin.front;\r\n\twin.background = Color.grey;\r\n\twin.alpha = 0.95;\r\n\r\n\t// Carrier Frequency Knob\r\n\tcarrSpec = ControlSpec(20, 20000, 'exp', 0, 440, \" Hz\");\r\n\tcarrFreqKnob = Knob.new(win, Rect(20, 20, 200, 200))\r\n\t.action = {arg v;\r\n\t\tvar freq = carrSpec.map(v.value);\r\n\t\tcarrFreqNumber.string = freq.round;\r\n\t\tsynth.set(\\carrFreq, freq)};\r\n\tcarrFreqKnob.value = carrSpec.unmap(carrSpec.default);\r\n\r\n\t// Carrier Frequency Number\r\n\tcarrFreqNumber = StaticText.new(win, Rect(80, 210, 80, 25));\r\n\tcarrFreqNumber.background = Color.grey;\r\n\tcarrFreqNumber.alpha = 0.95;\r\n\tcarrFreqNumber.align = \\center;\r\n\tcarrFreqNumber.string = 440;\r\n\tcarrFreqNumber.font = defaultFont;\r\n\r\n\t// Carrier Frequency Label\r\n\tcarrFreqLabel = StaticText.new(win, Rect(20, 240, 200, 25));\r\n\tcarrFreqLabel.string = \"Carrier Frequency\";\r\n\tcarrFreqLabel.align = \\center;\r\n\tcarrFreqLabel.font = defaultFont;\r\n\r\n\t// Modulator Frequency Knob\r\n\tmodSpec = ControlSpec(0.5, 5000, 'exp', 0, 2, \" Hz\");\r\n\tmodFreqKnob = Knob.new(win, Rect(260, 20, 200, 200))\r\n\t.action = {arg v;\r\n\t\tvar freq = modSpec.map(v.value);\r\n\t\tmodFreqNumber.string = freq.round(0.1);\r\n\t\tsynth.set(\\modFreq, freq)};\r\n\tmodFreqKnob.value = modSpec.unmap(modSpec.default);\r\n\r\n\t// Modulator Frequency Number\r\n\tmodFreqNumber = StaticText.new(win, Rect(320, 210, 80, 25));\r\n\tmodFreqNumber.background = Color.grey;\r\n\tmodFreqNumber.alpha = 0.95;\r\n\tmodFreqNumber.align = \\center;\r\n\tmodFreqNumber.string = 2;\r\n\tmodFreqNumber.font = defaultFont;\r\n\r\n\t// Modulator Frequency Label\r\n\tmodFreqLabel = StaticText.new(win, Rect(260, 240, 200, 25));\r\n\tmodFreqLabel.string = \"Modulator Frequency\";\r\n\tmodFreqLabel.align = \\center;\r\n\tmodFreqLabel.font = defaultFont;\r\n\r\n\t// Volume Slider\r\n\tvolumeSlider = EZSlider(\r\n\t\tparent: win,\r\n\t\tbounds: Rect(510, 20, 70, 230),\r\n\t\tlabel: \"VOLUME\",\r\n\t\tcontrolSpec: ControlSpec(-40, 0, \\lin, 0.1, -24, \"dB\"),\r\n\t\taction: {|ez| synth.set(\\amp, ez.value.dbamp)},\r\n\t\tlabelWidth: 80,\r\n\t\tunitWidth: 30,\r\n\t\tlayout: 'vert')\r\n\t.setColors(\r\n\t\tstringColor: Color.black,\r\n\t\tsliderBackground: Color.grey(0.9),\r\n\t\tnumNormalColor: Color.black)\r\n\t.font = Font(\"Verdana\", 14, bold: true);\r\n\r\n\tvolumeSlider.numberView.align = \\center;\r\n\tvolumeSlider.unitView.align = \\center;\r\n\r\n\t{\r\n\t\tSynthDef(\"amp-mod\", {arg carrFreq = 440, modFreq = 2, amp = 0.06;\r\n\t\t\tvar carrier, modulator;\r\n\t\t\tcarrier = SinOsc.ar(carrFreq);\r\n\t\t\tmodulator = SinOsc.ar(modFreq).range(0, 0.8);\r\n\t\t\tOut.ar(0, carrier * modulator * amp);\r\n\t\t}).add;\r\n\r\n\t\ts.sync;\r\n\r\n\t\tsynth = Synth(\"amp-mod\");\r\n\r\n\t}.fork;\r\n\r\n\tCmdPeriod.doOnce({win.close});\r\n\r\n}); // end of waitForBoot",
   "name" : "Amplitude Modulation GUI Demo",
   "author" : "Bruno Ruviaro",
   "ancestor_list" : [],
   "description" : "Simple but nice interface to play with basic amplitude modulation."
}
