computer programming for musical applications ii tutorial10.gui 5 december, 2008
TRANSCRIPT
![Page 1: Computer Programming For Musical Applications II Tutorial10.GUI 5 December, 2008](https://reader036.vdocuments.mx/reader036/viewer/2022083005/56649f1f5503460f94c36ef6/html5/thumbnails/1.jpg)
Computer Programming For Musical Applications II
Tutorial10.GUI
5 December, 2008
![Page 2: Computer Programming For Musical Applications II Tutorial10.GUI 5 December, 2008](https://reader036.vdocuments.mx/reader036/viewer/2022083005/56649f1f5503460f94c36ef6/html5/thumbnails/2.jpg)
TODAY
Quick GUI Review
EZSlider
Exercises
MTE2007 Computer Programming For Musical Applications II
2December 5, 2008
![Page 3: Computer Programming For Musical Applications II Tutorial10.GUI 5 December, 2008](https://reader036.vdocuments.mx/reader036/viewer/2022083005/56649f1f5503460f94c36ef6/html5/thumbnails/3.jpg)
Windows
MTE2007 Computer Programming For Musical Applications II
3
GUI.window.new(name,bounds,resizable,border,server,scroll)
Create a window
December 5, 2008
name – A text string displayed at the top of the windowbounds – A Rect object specifying location and sizeresizable – Boolean allowing window to be resizedborder – Boolean drawing a border and title bar. If false,
the window can only be closed from within SC codeserver – does nothingscroll – draws scrollbars if content goes beyond bounds
![Page 4: Computer Programming For Musical Applications II Tutorial10.GUI 5 December, 2008](https://reader036.vdocuments.mx/reader036/viewer/2022083005/56649f1f5503460f94c36ef6/html5/thumbnails/4.jpg)
Basic Window Example
MTE2007 Computer Programming For Musical Applications II
4
//create a 600x360 window, at x=256, y=64 (from bottom left)//make it resizable, with bordersw = SCWindow("My Window", Rect(256, 64, 600, 360), true, true, 0, false);
w.front; // bring it to the frontw.close; // close the window
December 5, 2008
![Page 5: Computer Programming For Musical Applications II Tutorial10.GUI 5 December, 2008](https://reader036.vdocuments.mx/reader036/viewer/2022083005/56649f1f5503460f94c36ef6/html5/thumbnails/5.jpg)
Buttons
MTE2007 Computer Programming For Musical Applications II
5
SCButton.new(parent,bounds)
December 5, 2008
states – an array containing the sequence of states of the button each state is an array itself of the form:
[label, textcolor, background color] action – a function that is called when the button is released value – returns the current state (not settable) valueAction – sets the current state
Members:
![Page 6: Computer Programming For Musical Applications II Tutorial10.GUI 5 December, 2008](https://reader036.vdocuments.mx/reader036/viewer/2022083005/56649f1f5503460f94c36ef6/html5/thumbnails/6.jpg)
Button Example
MTE2007 Computer Programming For Musical Applications II
6
(w = SCWindow.new; // uses default values for boundsb = SCButton(w, Rect(20,20,340,30));// create a button with 2 statesb.states = [ ["Touch Me", Color.black, Color.yellow], ["Push Me", Color.white, Color.red], ];b.action = { |state| if(state.value == 1) { "Mmmm nice".postln;} { "Aah, too hard".postln; } };w.front;)
December 5, 2008
![Page 7: Computer Programming For Musical Applications II Tutorial10.GUI 5 December, 2008](https://reader036.vdocuments.mx/reader036/viewer/2022083005/56649f1f5503460f94c36ef6/html5/thumbnails/7.jpg)
Basic Window Example
MTE2007 Computer Programming For Musical Applications II
7December 5, 2008
Task
Create a basic window on the screen that contains a button with two states: Start and Stop
Make the button play a Synth when you press the Start button and make it stop the Synth when you press the Stop button
![Page 8: Computer Programming For Musical Applications II Tutorial10.GUI 5 December, 2008](https://reader036.vdocuments.mx/reader036/viewer/2022083005/56649f1f5503460f94c36ef6/html5/thumbnails/8.jpg)
EZSlider
MTE2007 Computer Programming For Musical Applications II
8
EZSlider(window, dimensions, label, controlSpec, action, initVal, initAction, labelWidth, numberWidth)
December 5, 2008
controlSpec: An easy way to map your slider values to something more useful e.g.
ControlSpec(24,60,\lin,1) action: A function to be called when the sliders value is changed e.g.
{|ez| mySynth.set(\note,ez.value)}
EZSlider is a wrapper class for managing a label, slider and number box.
![Page 9: Computer Programming For Musical Applications II Tutorial10.GUI 5 December, 2008](https://reader036.vdocuments.mx/reader036/viewer/2022083005/56649f1f5503460f94c36ef6/html5/thumbnails/9.jpg)
Connecting your GUI to a Synth
MTE2007 Computer Programming For Musical Applications II
9
(// define a synthSynthDef(”synthy", { arg note = 36, fc = 1000, rq = 0.25, bal=0, amp=0.4, gate = 1; var x;x = Mix.fill(4, { LFSaw.ar((note + {0.1.rand2}.dup).midicps, 0, 0.02) }); x = RLPF.ar(x, fc, rq).softclip; x = RLPF.ar(x, fc, rq, amp).softclip; x = Balance2.ar(x[0], x[1], bal); x = x * EnvGen.kr(Env.cutoff, gate, doneAction: 2); Out.ar(0, x); }).load(s);)
December 5, 2008
First define a Synth -
![Page 10: Computer Programming For Musical Applications II Tutorial10.GUI 5 December, 2008](https://reader036.vdocuments.mx/reader036/viewer/2022083005/56649f1f5503460f94c36ef6/html5/thumbnails/10.jpg)
December 5, 2008 MTE2007 Computer Programming For Musical Applications II
10
Connecting your GUI to a Synth
(//Start of main code bracket var w, startButton, node, noteControl, cutControl, resControl, balControl, ampControl,cmdPeriodFunc;
//Make a windoww = GUI.window.new("DEMO WINDOW",Rect(20,400,440,180)); w.front; //Make the window visible and bring it to the front w.view.decorator = FlowLayout(w.view.bounds); w.view.background = Color(0,0,0); //Set the background color
startButton = GUI.button.nstartButton = GUI.button.new(w,75@24); startButton.states = [ ["Start", Color.white, Color.green],["Stop", Color.white, Color.red] ];
//Code continues on next slide….
![Page 11: Computer Programming For Musical Applications II Tutorial10.GUI 5 December, 2008](https://reader036.vdocuments.mx/reader036/viewer/2022083005/56649f1f5503460f94c36ef6/html5/thumbnails/11.jpg)
December 5, 2008 MTE2007 Computer Programming For Musical Applications II
11
Connecting your GUI to a Synth
startButton.action = { |view| if(view.value == 1){ //Start the sound node = Synth(\synthy, [ \note, noteControl.value, \fc, cutControl.value, \rq, resControl.value, \bal, balControl.value, \amp, ampControl.value.dbamp ]); }{ //Set gate to zero to cause envelope to release node.release; node = nil; }; };
//Code continues on next slide….
![Page 12: Computer Programming For Musical Applications II Tutorial10.GUI 5 December, 2008](https://reader036.vdocuments.mx/reader036/viewer/2022083005/56649f1f5503460f94c36ef6/html5/thumbnails/12.jpg)
December 5, 2008 MTE2007 Computer Programming For Musical Applications II
12
Connecting your GUI to a Synth//Create controls for all parameters w.view.decorator.nextLine; //Move down a line in the GUI screen noteControl = EZSlider(w,400@24, "Note", ControlSpec(24,60,\lin,1), {|ez| node.set(\note,ez.value)},36); w.view.decorator.nextLine; cutControl = EZSlider(w,400@24, "CutOff", ControlSpec(200,5000,\exp,1), {|ez| node.set(\fc,ez.value)},1000); w.view.decorator.nextLine;resControl = EZSlider(w, 400 @ 24, "Resonance", ControlSpec(0.1, 0.7), {|ez| node.set( \rq, ez.value )}, 0.2);w.view.decorator.nextLine;balControl = EZSlider(w, 400 @ 24, "Balance", \bipolar, {|ez| node.set( \bal, ez.value )}, 0);w.view.decorator.nextLine;ampControl = EZSlider(w, 400 @ 24, "Amp", \db, {|ez| node.set( \amp, ez.value.dbamp )}, -6);//Code continues on next slide….
![Page 13: Computer Programming For Musical Applications II Tutorial10.GUI 5 December, 2008](https://reader036.vdocuments.mx/reader036/viewer/2022083005/56649f1f5503460f94c36ef6/html5/thumbnails/13.jpg)
December 5, 2008 MTE2007 Computer Programming For Musical Applications II
13
Connecting your GUI to a Synth// set start button to zero upon a cmd-periodcmdPeriodFunc = { startButton.value = 0; };CmdPeriod.add(cmdPeriodFunc);
// stop the sound when window closes and remove cmdPeriodFunc.w.onClose = {node.free; node = nil;CmdPeriod.remove(cmdPeriodFunc);};
) //End of main code bracket
![Page 14: Computer Programming For Musical Applications II Tutorial10.GUI 5 December, 2008](https://reader036.vdocuments.mx/reader036/viewer/2022083005/56649f1f5503460f94c36ef6/html5/thumbnails/14.jpg)
December 5, 2008 MTE2007 Computer Programming For Musical Applications II
14
Connecting your GUI to a SynthTask:
Create a window with one button and 4 EZ sliders
Make the button trigger a Synth and make the sliders control 4 parameters of the Synth
![Page 15: Computer Programming For Musical Applications II Tutorial10.GUI 5 December, 2008](https://reader036.vdocuments.mx/reader036/viewer/2022083005/56649f1f5503460f94c36ef6/html5/thumbnails/15.jpg)
December 5, 2008 MTE2007 Computer Programming For Musical Applications II
15
Create a Mean FilterTask:
Create a window with one EZ Slider + a separate text box
Create a function that will take the value from the EZ Slider and filters the current value using a mean filter. Display the filtered value of the EZ Slider in the separate text box.
A mean filter is very easy to create…all you need is an array of size N (for example 10) which should be filled with 0’s at the start of the program. Then every time you want to filter a value you do the following steps: Move the position of the values in the filter down by 1 Insert the latest value to the end of the array Add up all the values in the array and divide by N – this gives you your filtered value