////////////////////////////////////////// // Code by Ben Miller and Joe Levine /// // Assignment 3 /// // CC12 - May 4th, 2000 /// ////////////////////////////////////////// // The purpose of this code is to create a GUI window with sliders and checkboxes to control // eight different sine waves. Amplitude and frequency of each since wave is controlled by // a slider. The sine waves can be turned on and off with checkboxes. The output is the // sum of the sine waves and is displayed in the scope window. // The starting frequencies are random numbers between 201 and 220. // Starting amplitude is set rather low so that all of the waves can be used at once without // producing a wave that doesn't fit in the scope window. ( //window variable var w; //Variables for slider frequencies var freq1, freq2, freq3, freq4, freq5, freq6, freq7, freq8; //Variables for Number frequencies var nfreq1, nfreq2, nfreq3, nfreq4, nfreq5, nfreq6, nfreq7, nfreq8; //Amplitude for slider variables var amp1, amp2, amp3, amp4, amp5, amp6, amp7, amp8; //Amplitude for Number variables var namp1, namp2, namp3, namp4, namp5, namp6, namp7, namp8; //Checkbox variables var box1, box2, box3, box4, box5, box6, box7, box8; // real starting frequencies (varied from startfreq by a random number) var startfreq1, startfreq2, startfreq3, startfreq4, startfreq5, startfreq6, startfreq7, startfreq8; //initial slider values var minfreq, maxfreq, startfreq, freqinc, minamp, maxamp, startamp, ampinc; minfreq = 20; maxfreq = 20000; startfreq = 200; freqinc = 1; minamp = 0.0001; maxamp = 1; startamp = 0.15; ampinc = 0.001; // set values of actual start frequencies startfreq1 = startfreq + 20.1.rand; startfreq2 = startfreq + 20.1.rand; startfreq3 = startfreq + 20.1.rand; startfreq4 = startfreq + 20.1.rand; startfreq5 = startfreq + 20.1.rand; startfreq6 = startfreq + 20.1.rand; startfreq7 = startfreq + 20.1.rand; startfreq8 = startfreq + 20.1.rand; //create gui window w = GUIWindow.new("panel", Rect.newBy(196, 56, 596, 461)); //Create all the sliders freq1 = SliderView.new( w, Rect.newBy(134, 30, 128, 20), "SliderView", startfreq1, minfreq, maxfreq, freqinc, 'exponential') .backColor_(rgb(136,136,136)).labelColor_(rgb(24,117,52)).knobColor_(rgb(24,117,52)); amp1 = SliderView.new( w, Rect.newBy(374, 30, 128, 20), "SliderView", startamp, minamp, maxamp, ampinc, 'linear') .backColor_(rgb(136,136,136)).labelColor_(rgb(239,31,29)).knobColor_(rgb(239,31,29)); freq2 = SliderView.new( w, Rect.newBy(134, 63, 128, 20), "SliderView", startfreq2, minfreq, maxfreq, freqinc, 'exponential') .backColor_(rgb(136,136,136)).labelColor_(rgb(24,117,52)).knobColor_(rgb(24,117,52)); amp2 = SliderView.new( w, Rect.newBy(374, 63, 128, 20), "SliderView", startamp, minamp, maxamp, ampinc, 'linear') .backColor_(rgb(136,136,136)).labelColor_(rgb(239,31,29)).knobColor_(rgb(239,31,29)); freq3 = SliderView.new( w, Rect.newBy(134, 106, 128, 20), "SliderView", startfreq3, minfreq, maxfreq, freqinc, 'exponential') .backColor_(rgb(136,136,136)).labelColor_(rgb(24,117,52)).knobColor_(rgb(24,117,52)); amp3 = SliderView.new( w, Rect.newBy(374, 106, 128, 20), "SliderView", startamp, minamp, maxamp, ampinc, 'linear') .backColor_(rgb(136,136,136)).labelColor_(rgb(239,31,29)).knobColor_(rgb(239,31,29)); freq4 = SliderView.new( w, Rect.newBy(134, 150, 128, 20), "SliderView", startfreq4, minfreq, maxfreq, freqinc, 'exponential') .backColor_(rgb(136,136,136)).labelColor_(rgb(24,117,52)).knobColor_(rgb(24,117,52)); amp4 = SliderView.new( w, Rect.newBy(374, 150, 128, 20), "SliderView", startamp, minamp, maxamp, ampinc, 'linear') .backColor_(rgb(136,136,136)).labelColor_(rgb(239,31,29)).knobColor_(rgb(239,31,29)); freq5 = SliderView.new( w, Rect.newBy(134, 203, 128, 20), "SliderView", startfreq5, minfreq, maxfreq, freqinc, 'exponential') .backColor_(rgb(136,136,136)).labelColor_(rgb(24,117,52)).knobColor_(rgb(24,117,52)); amp5 = SliderView.new( w, Rect.newBy(374, 203, 128, 20), "SliderView", startamp, minamp, maxamp, ampinc, 'linear') .backColor_(rgb(136,136,136)).labelColor_(rgb(239,31,29)).knobColor_(rgb(239,31,29)); freq6 = SliderView.new( w, Rect.newBy(134, 248, 128, 20), "SliderView", startfreq6, minfreq, maxfreq, freqinc, 'exponential') .backColor_(rgb(136,136,136)).labelColor_(rgb(24,117,52)).knobColor_(rgb(24,117,52)); amp6 = SliderView.new( w, Rect.newBy(374, 248, 128, 20), "SliderView", startamp, minamp, maxamp, ampinc, 'linear') .backColor_(rgb(136,136,136)).labelColor_(rgb(239,31,29)).knobColor_(rgb(239,31,29)); freq7 = SliderView.new( w, Rect.newBy(134, 307, 128, 20), "SliderView", startfreq7, minfreq, maxfreq, freqinc, 'exponential') .backColor_(rgb(136,136,136)).labelColor_(rgb(24,117,52)).knobColor_(rgb(24,117,52)); amp7 = SliderView.new( w, Rect.newBy(374, 307, 128, 20), "SliderView", startamp, minamp, maxamp, ampinc, 'linear') .backColor_(rgb(136,136,136)).labelColor_(rgb(239,31,29)).knobColor_(rgb(239,31,29)); freq8 = SliderView.new( w, Rect.newBy(134, 353, 128, 20), "SliderView", startfreq8, minfreq, maxfreq, freqinc, 'exponential') .backColor_(rgb(136,136,136)).labelColor_(rgb(24,117,52)).knobColor_(rgb(24,117,52)); amp8 = SliderView.new( w, Rect.newBy(374, 353, 128, 20), "SliderView", startamp, minamp, maxamp, ampinc, 'linear') .backColor_(rgb(136,136,136)).labelColor_(rgb(239,31,29)).knobColor_(rgb(239,31,29)); //Create all the on/off boxes box1 = CheckBoxView.new( w, Rect.newBy(6, 30, 128, 10), "On/Off", 1, 0, 1, 0, 'linear'); box2 = CheckBoxView.new( w, Rect.newBy(6, 63, 128, 10), "On/Off", 1, 0, 1, 0, 'linear'); box3 = CheckBoxView.new( w, Rect.newBy(6, 106, 128, 10), "On/Off", 1, 0, 1, 0, 'linear'); box4 = CheckBoxView.new( w, Rect.newBy(6, 150, 128, 10), "On/Off", 1, 0, 1, 0, 'linear'); box5 = CheckBoxView.new( w, Rect.newBy(6, 203, 128, 10), "On/Off", 1, 0, 1, 0, 'linear'); box6 = CheckBoxView.new( w, Rect.newBy(6, 248, 128, 10), "On/Off", 1, 0, 1, 0, 'linear'); box7 = CheckBoxView.new( w, Rect.newBy(6, 307, 128, 10), "On/Off", 1, 0, 1, 0, 'linear'); box8 = CheckBoxView.new( w, Rect.newBy(6, 353, 128, 10), "On/Off", 1, 0, 1, 0, 'linear'); //create all the input boxes nfreq1 = NumericalView.new( w, Rect.newBy(267, 30, 64, 20), "NumericalView", startfreq1, minfreq, maxfreq, freqinc, 'exponential'); namp1 = NumericalView.new( w, Rect.newBy(521, 30, 64, 20), "NumericalView", startamp, minamp, maxamp, ampinc, 'linear'); nfreq2 = NumericalView.new( w, Rect.newBy(267, 63, 64, 20), "NumericalView", startfreq2, minfreq, maxfreq, freqinc, 'exponential'); namp2 = NumericalView.new( w, Rect.newBy(521, 63, 61, 19), "NumericalView", startamp, minamp, maxamp, ampinc, 'linear'); namp3 = NumericalView.new( w, Rect.newBy(521, 106, 64, 20), "NumericalView", startamp, minamp, maxamp, ampinc, 'linear'); namp4 = NumericalView.new( w, Rect.newBy(521, 150, 64, 20), "NumericalView", startamp, minamp, maxamp, ampinc, 'linear'); namp5 = NumericalView.new( w, Rect.newBy(521, 203, 64, 20), "NumericalView", startamp, minamp, maxamp, ampinc, 'linear'); namp6 = NumericalView.new( w, Rect.newBy(521, 248, 64, 20), "NumericalView", startamp, minamp, maxamp, ampinc, 'linear'); namp7 = NumericalView.new( w, Rect.newBy(521, 307, 64, 20), "NumericalView", startamp, minamp, maxamp, ampinc, 'linear'); namp8 = NumericalView.new( w, Rect.newBy(521, 353, 64, 20), "NumericalView", startamp, minamp, maxamp, ampinc, 'linear'); nfreq3 = NumericalView.new( w, Rect.newBy(267, 106, 64, 20), "NumericalView", startfreq3, minfreq, maxfreq, freqinc, 'exponential'); nfreq4 = NumericalView.new( w, Rect.newBy(267, 150, 64, 20), "NumericalView", startfreq4, minfreq, maxfreq, freqinc, 'exponential'); nfreq5 = NumericalView.new( w, Rect.newBy(267, 203, 64, 20), "NumericalView", startfreq5, minfreq, maxfreq, freqinc, 'exponential'); nfreq6 = NumericalView.new( w, Rect.newBy(267, 248, 64, 20), "NumericalView", startfreq6, minfreq, maxfreq, freqinc, 'exponential'); nfreq7 = NumericalView.new( w, Rect.newBy(267, 307, 64, 20), "NumericalView", startfreq7, minfreq, maxfreq, freqinc, 'exponential'); nfreq8 = NumericalView.new( w, Rect.newBy(267, 353, 64, 20), "NumericalView", startfreq8, minfreq, maxfreq, freqinc, 'exponential'); //create labels for sliders. StringView.new( w, Rect.newBy(138, 4, 128, 20), "Frequency") .backColor_(rgb(204,204,204)).labelColor_(rgb(24,117,52)); StringView.new( w, Rect.newBy(380, 4, 128, 20), "Amplitude") .backColor_(rgb(204,204,204)).labelColor_(rgb(239,31,29)); //Now link number box and slider values for frequency. freq1.action = { nfreq1.value = freq1.value }; nfreq1.action = { freq1.value = nfreq1.value }; freq2.action = { nfreq2.value = freq2.value }; nfreq2.action = { freq2.value = nfreq2.value }; freq3.action = { nfreq3.value = freq3.value }; nfreq3.action = { freq3.value = nfreq3.value }; freq4.action = { nfreq4.value = freq4.value }; nfreq4.action = { freq4.value = nfreq4.value }; freq5.action = { nfreq5.value = freq5.value }; nfreq5.action = { freq5.value = nfreq5.value }; freq6.action = { nfreq6.value = freq6.value }; nfreq6.action = { freq6.value = nfreq6.value }; freq7.action = { nfreq7.value = freq7.value }; nfreq7.action = { freq7.value = nfreq7.value }; freq8.action = { nfreq8.value = freq8.value }; nfreq8.action = { freq8.value = nfreq8.value }; //Now link number box and slider values for amplitude. amp1.action = { namp1.value = amp1.value }; namp1.action = { amp1.value = namp1.value }; amp2.action = { namp2.value = amp2.value }; namp2.action = { amp2.value = namp2.value }; amp3.action = { namp3.value = amp3.value }; namp3.action = { amp3.value = namp3.value }; amp4.action = { namp4.value = amp4.value }; namp4.action = { amp4.value = namp4.value }; amp5.action = { namp5.value = amp5.value }; namp5.action = { amp5.value = namp5.value }; amp6.action = { namp6.value = amp6.value }; namp6.action = { amp6.value = namp6.value }; amp7.action = { namp7.value = amp7.value }; namp7.action = { amp7.value = namp7.value }; amp8.action = { namp8.value = amp8.value }; namp8.action = { amp8.value = namp8.value }; //Play the Sine waves { Mix.ar([ SinOsc.ar( ControlIn.kr(freq1), 0, (ControlIn.kr(amp1) * ControlIn.kr(box1)) ), SinOsc.ar( ControlIn.kr(freq2), 0, (ControlIn.kr(amp2) * ControlIn.kr(box2)) ), SinOsc.ar( ControlIn.kr(freq3), 0, (ControlIn.kr(amp3) * ControlIn.kr(box3))), SinOsc.ar( ControlIn.kr(freq4), 0, (ControlIn.kr(amp4) * ControlIn.kr(box4))), SinOsc.ar( ControlIn.kr(freq5), 0, (ControlIn.kr(amp5) * ControlIn.kr(box5))), SinOsc.ar( ControlIn.kr(freq6), 0, (ControlIn.kr(amp6) * ControlIn.kr(box6))), SinOsc.ar( ControlIn.kr(freq7), 0, (ControlIn.kr(amp7) * ControlIn.kr(box7))), SinOsc.ar( ControlIn.kr(freq8), 0, (ControlIn.kr(amp8) * ControlIn.kr(box8))) ] ) }.scope; w.close; )