/*************************************************************************************/ /*تتتتتتتتتتتتتتتتتتتتتتتتتتتت Matthew Wrobel, Assignment 3 */ /*************************************************************************************/ /* My patch is called "Envelopes and Different Types of Waves and Speeds", */ //and it allows the user to control the behavior of a lot of randomly pitched Sawtooth, //Pulse, and Sin Waves. The user can control the attack, sustain, and release times of the //lenin envelope of the sounds, as wellas the sustain amplitude. One can also control the speed //at which they are spawned, and the duration that they are held out. When dealing with the //Pulse type waves, the width of can also be fooled around with. It starts as square. /* There are three windows of sliders, used to control the envelope and other attributes of */ //each of three types of waves, Sin, Pulse, and Saw. There is also one window in which you turn //of the three waves on and off with checkboxes. The wave is scoped. The idea is that you can make //many cool sounds by adjusting the durations, and envelopes of these three wave types. //The variables are mostly used to deal with the GUI unfortunately, because I couldn't figure out //how to use Arrays in this language. the variables 'sin' 'pulse' and 'saw' are used to piece together //the sounds from all the different parameters that are controled through the GUI.*/ // PS, I have a big monitor, and I have no idea if it will work the same on a smaller one. ( var w, xinc = 60, yinc = 28, ylen = 180, offset = 700, getnext, q, pbox, nbox, sbox, pslide0, pslide1, pslide2, pslide3, pslide4, pslide5, pslide6, pslide7, pv1, pv2, pv3, pv4, pv5, pv6, pv7, pv0, color1 = rgb(255, 255, 255), color2 = rgb(0, 0, 0), z, sslide1, sslide2, sslide3, sslide4, sslide5, sslide6, sslide7, sv1, sv2, sv3, sv4, sv5, sv6, sv7, y, nslide1, nslide2, nslide3, nslide4, nslide5, nslide6, nslide7, nv1, nv2, nv3, nv4, nv5, nv6, nv7, pulse, saw, sin; ////////////////////////////////////////////////////////////////////////// //First we make the checkboxes that control which waves are being played// ////////////////////////////////////////////////////////////////////////// q = GUIWindow.new("Control Boxes", Rect.new(offset - 100, 68, offset, 105)); pbox = CheckBoxView.new(q, Rect.new(18, 15, 146, 35), "Pulses", 0, 0, 1, 0, 'linear'); sbox = CheckBoxView.new(q, Rect.new(18, 39, 146, 59), "Sawtooths", 0, 0, 1, 0, 'linear'); nbox = CheckBoxView.new(q, Rect.new(18, 63, 146, 83), "SinWaves", 0, 0, 1, 0, 'linear'); ///////////////////////////////////////////////////////////////////////// // Now we take a long time and do the Pulse controls! // ///////////////////////////////////////////////////////////////////////// w = GUIWindow.new("Pulse Controls", Rect.new(100 + offset, 68, 330 + offset, 300)); StringView.new(w, Rect.new(1, 8, xinc, 24), "Width") .labelColor_(rgb(0,0,0)); StringView.new(w, Rect.new(1, yinc + 8, xinc + 8, yinc + 24), "AttackT") .labelColor_(rgb(0,0,0)); StringView.new(w, Rect.new(1, yinc * 2 + 8, xinc, yinc * 2 + 24), "SustainT") .labelColor_(rgb(0,0,0)); StringView.new(w, Rect.new(1, yinc * 3 + 8, xinc, yinc * 3 + 24), "ReleaseT") .labelColor_(rgb(0,0,0)); StringView.new(w, Rect.new(1, yinc * 4 + 8, xinc, yinc * 4 + 24), "SustainAmp") .labelColor_(rgb(0,0,0)); StringView.new(w, Rect.new(1, yinc * 5 + 8, xinc, yinc * 5 + 24), "MaxAmp") .labelColor_(rgb(0,0,0)); StringView.new(w, Rect.new(1, yinc * 6 + 8, xinc, yinc * 6 + 24), "Speed") .labelColor_(rgb(0,0,0)); StringView.new(w, Rect.new(1, yinc * 7 + 8, xinc, yinc * 7 + 24), "Duration") .labelColor_(rgb(0,0,0)); pslide0 = SliderView.new(w, Rect.new(xinc, 8, ylen, 24), nil, 0.5, 0, 1); pslide1 = SliderView.new(w, Rect.new(xinc, yinc + 8, ylen, yinc + 24), nil, 0.5, 0, 1); pslide2 = SliderView.new(w, Rect.new(xinc, yinc * 2 + 8, ylen, yinc * 2 + 24), nil, 0.5, 0, 1); pslide3 = SliderView.new(w, Rect.new(xinc, yinc * 3 + 8, ylen, yinc * 3 + 24), nil, 0.5, 0, 1); pslide4 = SliderView.new(w, Rect.new(xinc, yinc * 4 + 8, ylen, yinc * 4 + 24), nil, 0.5, 0, 1); pslide5 = SliderView.new(w, Rect.new(xinc, yinc * 5 + 8, ylen, yinc * 5 + 24), nil, 0.3, 0, 1); pslide6 = SliderView.new(w, Rect.new(xinc, yinc * 6 + 8, ylen, yinc * 6 + 24), nil, 100, 10, 200); pslide7 = SliderView.new(w, Rect.new(xinc, yinc * 7 + 8, ylen, yinc * 7 + 24), nil, 0.5, 0.1, 2.5); pv0 = NumericalView.new(w, Rect.new(ylen + 5, 7, ylen + 35, 24), nil, pslide0.value, 0, 1, 0.01) .backColor_(color1).labelColor_(color2); pv1 = NumericalView.new(w, Rect.new(ylen + 5, yinc + 7, ylen + 35, yinc + 24), nil, pslide1.value, 0, 1, 0.01) .backColor_(color1).labelColor_(color2); pv2 = NumericalView.new(w, Rect.new(ylen + 5, yinc * 2 + 8, ylen + 35, yinc * 2 + 24), nil, pslide2.value, 0, 1, 0.01) .backColor_(color1).labelColor_(color2); pv3 = NumericalView.new(w, Rect.new(ylen + 5, yinc * 3 + 8, ylen + 35, yinc * 3 + 24), nil, pslide3.value, 0, 1, 0.01) .backColor_(color1).labelColor_(color2); pv4 = NumericalView.new(w, Rect.new(ylen + 5, yinc * 4 + 8, ylen + 35, yinc * 4 + 24), nil, pslide4.value, 0, 1, 0.01) .backColor_(color1).labelColor_(color2); pv5 = NumericalView.new(w, Rect.new(ylen + 5, yinc * 5 + 8, ylen + 35, yinc * 5 + 24), nil, pslide5.value, 0, 1, 0.01) .backColor_(color1).labelColor_(color2); pv6 = NumericalView.new(w, Rect.new(ylen + 5, yinc * 6 + 8, ylen + 35, yinc * 6 + 24), nil, pslide6.value, 10, 200, 1) .backColor_(color1).labelColor_(color2); pv7 = NumericalView.new(w, Rect.new(ylen + 5, yinc * 7 + 8, ylen + 35, yinc * 7 + 24), nil, pslide7.value, 0.1, 2.5, 0.05) .backColor_(color1).labelColor_(color2); // This set all the sliders and viewboxes to update automatically pv0.action = {pslide0.value = pv0.value}; pv1.action = {pslide1.value = pv1.value}; pv2.action = {pslide2.value = pv2.value}; pv3.action = {pslide3.value = pv3.value}; pv4.action = {pslide4.value = pv4.value}; pv5.action = {pslide5.value = pv5.value}; pv6.action = {pslide6.value = pv6.value}; pv7.action = {pslide7.value = pv7.value}; pslide0.action = {pv0.value = pslide0.value}; pslide1.action = {pv1.value = pslide1.value}; pslide2.action = {pv2.value = pslide2.value}; pslide3.action = {pv3.value = pslide3.value}; pslide4.action = {pv4.value = pslide4.value}; pslide5.action = {pv5.value = pslide5.value}; pslide6.action = {pv6.value = pslide6.value}; pslide7.action = {pv7.value = pslide7.value}; ///////////////////////////////////////////////////////////////////////// // Whoa! that took a while...now we do the sawtooth controls, woohoo! // ///////////////////////////////////////////////////////////////////////// z = GUIWindow.new("SawTooth Controls", Rect.new(100 + offset, 330, 330 + offset, 530)); StringView.new(z, Rect.new(1, 8, xinc, 24), "AttackT") .labelColor_(rgb(0,0,0)); StringView.new(z, Rect.new(1, yinc + 8, xinc, yinc + 24), "SustainT") .labelColor_(rgb(0,0,0)); StringView.new(z, Rect.new(1, yinc * 2 + 8, xinc, yinc * 2 + 24), "ReleaseT") .labelColor_(rgb(0,0,0)); StringView.new(z, Rect.new(1, yinc * 3 + 8, xinc, yinc * 3 + 24), "SustainAmp") .labelColor_(rgb(0,0,0)); StringView.new(z, Rect.new(1, yinc * 4 + 8, xinc, yinc * 4 + 24), "MaxAmp") .labelColor_(rgb(0,0,0)); StringView.new(z, Rect.new(1, yinc * 5 + 8, xinc, yinc * 5 + 24), "Speed") .labelColor_(rgb(0,0,0)); StringView.new(z, Rect.new(1, yinc * 6 + 8, xinc, yinc * 6 + 24), "Duration") .labelColor_(rgb(0,0,0)); sslide1 = SliderView.new(z, Rect.new(xinc, 8, ylen, 24), nil, 0.5, 0, 1); sslide2 = SliderView.new(z, Rect.new(xinc, yinc + 8, ylen, yinc + 24), nil, 0.5, 0, 1); sslide3 = SliderView.new(z, Rect.new(xinc, yinc * 2 + 8, ylen, yinc * 2 + 24), nil, 0.5, 0, 1); sslide4 = SliderView.new(z, Rect.new(xinc, yinc * 3 + 8, ylen, yinc * 3 + 24), nil, 0.5, 0, 1); sslide5 = SliderView.new(z, Rect.new(xinc, yinc * 4 + 8, ylen, yinc * 4 + 24), nil, 0.3, 0, 1); sslide6 = SliderView.new(z, Rect.new(xinc, yinc * 5 + 8, ylen, yinc * 5 + 24), nil, 100, 10, 200); sslide7 = SliderView.new(z, Rect.new(xinc, yinc * 6 + 8, ylen, yinc * 6 + 24), nil, 0.5, 0.1, 2.5); sv1 = NumericalView.new(z, Rect.new(ylen + 5, 7, ylen + 35, 24), nil, sslide1.value, 0, 1, 0.01) .backColor_(color1).labelColor_(color2); sv2 = NumericalView.new(z, Rect.new(ylen + 5, yinc + 8, ylen + 35, yinc + 24), nil, sslide2.value, 0, 1, 0.01) .backColor_(color1).labelColor_(color2); sv3 = NumericalView.new(z, Rect.new(ylen + 5, yinc * 2 + 8, ylen + 35, yinc * 2 + 24), nil, sslide3.value, 0, 1, 0.01) .backColor_(color1).labelColor_(color2); sv4 = NumericalView.new(z, Rect.new(ylen + 5, yinc * 3 + 8, ylen + 35, yinc * 3 + 24), nil, sslide4.value, 0, 1, 0.01) .backColor_(color1).labelColor_(color2); sv5 = NumericalView.new(z, Rect.new(ylen + 5, yinc * 4 + 8, ylen + 35, yinc * 4 + 24), nil, sslide5.value, 0, 1, 0.01) .backColor_(color1).labelColor_(color2); sv6 = NumericalView.new(z, Rect.new(ylen + 5, yinc * 5 + 8, ylen + 35, yinc * 5 + 24), nil, sslide6.value, 10, 200, 1) .backColor_(color1).labelColor_(color2); sv7 = NumericalView.new(z, Rect.new(ylen + 5, yinc * 6 + 8, ylen + 35, yinc * 6 + 24), nil, sslide7.value, 0.1, 2.5, 0.05) .backColor_(color1).labelColor_(color2); // This set all the sliders and viewboxes to update automatically sv1.action = {sslide1.value = sv1.value}; sv2.action = {sslide2.value = sv2.value}; sv3.action = {sslide3.value = sv3.value}; sv4.action = {sslide4.value = sv4.value}; sv5.action = {sslide5.value = sv5.value}; sv6.action = {sslide6.value = sv6.value}; sv7.action = {sslide7.value = sv7.value}; sslide1.action = {sv1.value = sslide1.value}; sslide2.action = {sv2.value = sslide2.value}; sslide3.action = {sv3.value = sslide3.value}; sslide4.action = {sv4.value = sslide4.value}; sslide5.action = {sv5.value = sslide5.value}; sslide6.action = {sv6.value = sslide6.value}; sslide7.action = {sv7.value = sslide7.value}; ///////////////////////////////////////////////////////////////////////// // We're almost to the interesting stuff, here are the SinOsc controls // ///////////////////////////////////////////////////////////////////////// y = GUIWindow.new("SinOsc Controls", Rect.new(100 + offset, 560, 330 + offset, 760)); StringView.new(y, Rect.new(1, 8, xinc, 24), "AttackT") .labelColor_(rgb(0,0,0)); StringView.new(y, Rect.new(1, yinc + 8, xinc, yinc + 24), "SustainT") .labelColor_(rgb(0,0,0)); StringView.new(y, Rect.new(1, yinc * 2 + 8, xinc, yinc * 2 + 24), "ReleaseT") .labelColor_(rgb(0,0,0)); StringView.new(y, Rect.new(1, yinc * 3 + 8, xinc, yinc * 3 + 24), "SustainAmp") .labelColor_(rgb(0,0,0)); StringView.new(y, Rect.new(1, yinc * 4 + 8, xinc, yinc * 4 + 24), "MaxAmp") .labelColor_(rgb(0,0,0)); StringView.new(y, Rect.new(1, yinc * 5 + 8, xinc, yinc * 5 + 24), "Speed") .labelColor_(rgb(0,0,0)); StringView.new(y, Rect.new(1, yinc * 6 + 8, xinc, yinc * 6 + 24), "Duration") .labelColor_(rgb(0,0,0)); nslide1 = SliderView.new(y, Rect.new(xinc, 8, ylen, 24), nil, 0.5, 0, 1); nslide2 = SliderView.new(y, Rect.new(xinc, yinc + 8, ylen, yinc + 24), nil, 0.5, 0, 1); nslide3 = SliderView.new(y, Rect.new(xinc, yinc * 2 + 8, ylen, yinc * 2 + 24), nil, 0.5, 0, 1); nslide4 = SliderView.new(y, Rect.new(xinc, yinc * 3 + 8, ylen, yinc * 3 + 24), nil, 0.5, 0, 1); nslide5 = SliderView.new(y, Rect.new(xinc, yinc * 4 + 8, ylen, yinc * 4 + 24), nil, 0.3, 0, 1); nslide6 = SliderView.new(y, Rect.new(xinc, yinc * 5 + 8, ylen, yinc * 5 + 24), nil, 100, 10, 200); nslide7 = SliderView.new(y, Rect.new(xinc, yinc * 6 + 8, ylen, yinc * 6 + 24), nil, 0.5, 0.1, 2.5); nv1 = NumericalView.new(y, Rect.new(ylen + 5, 7, ylen + 35, 24), nil, nslide1.value, 0, 1, 0.01) .backColor_(color1).labelColor_(color2); nv2 = NumericalView.new(y, Rect.new(ylen + 5, yinc + 8, ylen + 35, yinc + 24), nil, nslide2.value, 0, 1, 0.01) .backColor_(color1).labelColor_(color2); nv3 = NumericalView.new(y, Rect.new(ylen + 5, yinc * 2 + 8, ylen + 35, yinc * 2 + 24), nil, nslide3.value, 0, 1, 0.01) .backColor_(color1).labelColor_(color2); nv4 = NumericalView.new(y, Rect.new(ylen + 5, yinc * 3 + 8, ylen + 35, yinc * 3 + 24), nil, nslide4.value, 0, 1, 0.01) .backColor_(color1).labelColor_(color2); nv5 = NumericalView.new(y, Rect.new(ylen + 5, yinc * 4 + 8, ylen + 35, yinc * 4 + 24), nil, nslide5.value, 0, 1, 0.01) .backColor_(color1).labelColor_(color2); nv6 = NumericalView.new(y, Rect.new(ylen + 5, yinc * 5 + 8, ylen + 35, yinc * 5 + 24), nil, nslide6.value, 10, 200, 1) .backColor_(color1).labelColor_(color2); nv7 = NumericalView.new(y, Rect.new(ylen + 5, yinc * 6 + 8, ylen + 35, yinc * 6 + 24), nil, nslide7.value, 0.1, 2.5, 0.05) .backColor_(color1).labelColor_(color2); // This set all the sliders and viewboxes to update automatically nv1.action = {nslide1.value = nv1.value}; nv2.action = {nslide2.value = nv2.value}; nv3.action = {nslide3.value = nv3.value}; nv4.action = {nslide4.value = nv4.value}; nv5.action = {nslide5.value = nv5.value}; nv6.action = {nslide6.value = nv6.value}; nv7.action = {nslide7.value = nv7.value}; nslide1.action = {nv1.value = nslide1.value}; nslide2.action = {nv2.value = nslide2.value}; nslide3.action = {nv3.value = nslide3.value}; nslide4.action = {nv4.value = nslide4.value}; nslide5.action = {nv5.value = nslide5.value}; nslide6.action = {nv6.value = nslide6.value}; nslide7.action = {nv7.value = nslide7.value}; ///////////////////////////////////////////////////////////////////////// // We're finally ready for the fun stuff. We set up all the controls // ///////////////////////////////////////////////////////////////////////// // the actual waves and envolopes are determined randomly using the maximum values pulse = {arg freq = 300, dur = 0.5, amp = 0.3, width = 0.5, att = 0.5, sus = 0.5, rel = 0.5, samp = 0.3; EnvGen.ar(Env.linen(att, sus, rel, samp), Pulse.ar(1000.300.rand, width, 1, 0), 0, amp, 0, dur); }; saw = {arg freq = 300, dur = 0.5, amp = 0.3, att = 0.5, sus = 0.5, rel = 0.5, samp = 0.3; EnvGen.ar(Env.linen(att, sus, rel, samp), Saw.ar(1000.300.rand, 1, 0), 0, amp, 0, dur); }; sin = {arg freq = 300, dur = 0.5, amp = 0.3, att = 0.5, sus = 0.5, rel = 0.5, samp = 0.3; EnvGen.ar(Env.linen(att, sus, rel, samp), SinOsc.ar(1000.300.rand, 1, 1), 0, amp, 0, dur); }; // We define a getnext function that will randomize the playing of sounds getnext = {arg seed = 100; 20 / seed; }; // This sets it up so that the checkboxes control what's played. Sounds are spawned if the box is checked. Synth.scope({ Spawn.ar({ if (pbox.value > 0, { // if check box is ON pulse.value(pslide6.value, pslide7.value, pslide5.value, pslide0.value, pslide1.value, pslide2.value, pslide3.value, pslide4.value); }); }, 1, getnext.value(pslide6.value)) + Spawn.ar({ if (sbox.value > 0, { // if check box is ON saw.value(sslide6.value, sslide7.value, sslide5.value, sslide1.value, sslide2.value, sslide3.value, sslide4.value); }); }, 1, getnext.value(sslide6.value)) + Spawn.ar({ if (nbox.value > 0, { // if check box is ON sin.value(nslide6.value, nslide7.value, nslide5.value, nslide1.value, nslide2.value, nslide3.value, nslide4.value); }); }, 1, getnext.value(nslide6.value)) }); q.close; w.close; z.close; y.close; )