diff --git a/Ch 8 Object Modeling/Ch8codefigures1.scd b/Ch 8 Object Modeling/Ch8codefigures1.scd index 6bec58d..8a95003 100644 --- a/Ch 8 Object Modeling/Ch8codefigures1.scd +++ b/Ch 8 Object Modeling/Ch8codefigures1.scd @@ -1,16 +1,16 @@ -/////////////////////// Object Modeling code figures /////////////////// +/////////////////////// Object Modeling code figures /////////////////// // figure 8.1 - a Puppet class, and tests for it. - -Puppet { + +Puppet { var <>myfreq; // an instance variable with a getter and a setter method - + // a method for creating a new object of this kind *new { |myfreq=50| ^super.new.myfreq_(myfreq) } - + // a simple method that uses 'myfreq' for something audible. blip { { Blip.ar(myfreq, 11) * XLine.kr(1, 0.01, 0.6, doneAction: 2) }.play; } } @@ -35,7 +35,7 @@ m.blip; // should sound differently m = (); // make an empty event m.myfreq_(50); // put something in it with a setter method: a pseudo-instance variable m.myfreq; // look it up with a getter method - // put a function into it with a setter: + // put a function into it with a setter: // this becomes a pseudo-method m.blip_({ |ev| { Blip.ar(ev.myfreq, 11) * XLine.kr(1, 0.01, 0.6, doneAction: 2) }.play; }); m.blip; // execute the function with a pseudo-method call (same name) @@ -49,9 +49,9 @@ m.blip; // execute the function with a pseudo-method call (same name) m.numHarms_(20); // a new instvar m.decay_(0.3); // and another // update the blip method to use them: -m.blip_({ |ev| - { Blip.ar(ev.myfreq, ev.numHarms) - * XLine.kr(1, 0.01, ev.decay, doneAction: 2) }.play; +m.blip_({ |ev| + { Blip.ar(ev.myfreq, ev.numHarms) + * XLine.kr(1, 0.01, ev.decay, doneAction: 2) }.play; }); ) m.blip; // test @@ -83,8 +83,8 @@ z.win.close; // close when done ( z.makeWin = { |z, message="Shout this!"| z.win = Window("Shout", Rect(0, 900,1200, 100)).front; - z.win.alpha_(0.7); - z.win.view.background_(Color.clear); + z.win.alpha_(0.7); + z.win.view.background_(Color.clear); z.win.alwaysOnTop_(true); z.txtView = TextView(z.win, Rect(0, 0,1200, 100)); @@ -93,8 +93,8 @@ z.makeWin = { |z, message="Shout this!"| z.txtView.background_(Color.clear); }; ) -z.makeWin; -z.makeWin("Try showing that."); +z.makeWin; +z.makeWin("Try showing that."); @@ -124,17 +124,17 @@ z.shout("Do we get this too?"); // also when window has closed? z.txtView.stringColor_(Color.red); // try a single color ( -z.animate = { |z, dt=0.2, n = 6| +z.animate = { |z, dt=0.2, n = 6| var colors = [Color.red, Color.green, Color.black]; - Task { - n.do { |i|Ê - dt.wait; + Task { + n.do { |i| + dt.wait; z.txtView.stringColor_(colors.wrapAt(i)) } }.play(AppClock) }; ) -z.animate; // test with default values +z.animate; // test with default values z.animate(0.1, 24); // and test with arguments given @@ -147,7 +147,7 @@ z.animate(0.1, 24); // and test with arguments given - // figure 8.9 - using codeDump to shout + // figure 8.9 - using codeDump to shout this.codeDump = { |str, result, func| [str, result, func].printAll }; @@ -164,22 +164,22 @@ this.codeDump = { |str| if (str.beginsWith(z.shoutTag)) { z.shout(str.drop(z.sho // figure 8.10 - updated setMessage flashes text. ( -z.setMessage = { |z, str| - var messSize = str.size; +z.setMessage = { |z, str| + var messSize = str.size; var fontsize = (1.64 * z.txtView.bounds.width) / max(messSize, 32); z.txtView.font_(GUI.font.new("Monaco", fontsize)); z.txtView.string_(str); z.animate; }; ) -//!! a long comment gets scaled down to a rather smaller font size, minimally fontsize 32! +//!! a long comment gets scaled down to a rather smaller font size, minimally fontsize 32! //!! short is big! ( z.makeWin = { |q, message="Shout this!"| z.win = Window("Shout", Rect(0, 900,1200, 100)).front; - z.win.alpha_(0.7); - z.win.view.background_(Color.clear); + z.win.alpha_(0.7); + z.win.view.background_(Color.clear); z.win.alwaysOnTop_(true); z.txtView = TextView(z.win, Rect(0, 0,1200, 100)); @@ -200,16 +200,16 @@ z.makeWin("shout."); Shout { classvar <>tag="//!!"; var tag="//!!", <>width=1250, <>defaultCodeDumpFunc; + classvar <>tag="//!!", <>width=1250, <>defaultCodeDumpFunc; var myfreq; // an instance variable with a getter and a setter method - + // a method for creating a new object of this kind *new { |myfreq=50| ^super.new.myfreq_(myfreq) } - + // a simple method that uses 'myfreq' for something audible. - blip { { Blip.ar(myfreq, 11) * XLine.kr(1, 0.01, 0.6, doneAction: 2) }.play; } + blip { { Blip.ar(myfreq, 11) * XLine.kr(1, 0.01, 0.6, doneAction: 2) }.play } } // tests for the behavior implemented so far: @@ -56,12 +56,12 @@ m.blip; // should sound differently // figure 8.2 - a puppet modeled as an event. -m = (); // make an empty event +m = (); // make an empty event m.myfreq_(50); // put something in it with a setter method: a pseudo-instance variable -m.myfreq; // look it up with a getter method - // put a function into it with a setter: +m.myfreq; // look it up with a getter method + // put a function into it with a setter: // this becomes a pseudo-method -m.blip_({ |ev| { Blip.ar(ev.myfreq, 11) * XLine.kr(1, 0.01, 0.6, doneAction: 2) }.play; }); +m.blip_({ |ev| { Blip.ar(ev.myfreq, 11) * XLine.kr(1, 0.01, 0.6, doneAction: 2) }.play }); m.blip; // execute the function with a pseudo-method call (same name) @@ -70,11 +70,11 @@ m.blip; // execute the function with a pseudo-method call (same name) // figure 8.3 - add more instance variables, change the blip method. ( m.numHarms_(20); // a new instvar -m.decay_(0.3); // and another +m.decay_(1); // and another // update the blip method to use them: -m.blip_({ |ev| - { Blip.ar(ev.myfreq, ev.numHarms) - * XLine.kr(1, 0.01, ev.decay, doneAction: 2) }.play; +m.blip_({ |ev| + { Blip.ar(ev.myfreq, ev.numHarms) + * XLine.kr(1, 0.01, ev.decay, doneAction: 2) }.play; }); ) m.blip; // test @@ -108,8 +108,8 @@ z.win.close; // close when done ( z.makeWin = { |z, message="Shout this!"| z.win = Window("Shout", Rect(0, 900,1200, 100)).front; - z.win.alpha_(0.7); - z.win.view.background_(Color.clear); + z.win.alpha_(0.7); + z.win.view.background_(Color.clear); z.win.alwaysOnTop_(true); z.txtView = TextView(z.win, Rect(0, 0,1200, 100)); @@ -118,8 +118,8 @@ z.makeWin = { |z, message="Shout this!"| z.txtView.background_(Color.clear); }; ) -z.makeWin; -z.makeWin("Try showing that."); +z.makeWin; +z.makeWin("Try showing that."); @@ -132,7 +132,7 @@ z.setMessage = { |z, str| z.txtView.string_(str) }; z.setMessage("Does this update?"); // test ( z.shout = { |z, str| - if (z.win.isNil or: { z.win.isClosed }) { z.makeWin }; + if(z.win.isNil or: { z.win.isClosed }) { z.makeWin }; z.setMessage(str); }; ) @@ -149,30 +149,30 @@ z.shout("Do we get this too?"); // also when window has closed? z.txtView.stringColor_(Color.red); // try a single color ( -z.animate = { |z, dt=0.2, n = 6| +z.animate = { |z, dt=0.2, n = 6| var colors = [Color.red, Color.green, Color.black]; - Task { - n.do { |i|Ê - dt.wait; + Task { + n.do { |i| + dt.wait; z.txtView.stringColor_(colors.wrapAt(i)) } }.play(AppClock) }; ) -z.animate; // test with default values +z.animate; // test with default values z.animate(0.1, 24); // and test with arguments given - // figure 8.8 is an image // + // figure 8.8 is an image // - // figure 8.9 - using codeDump to shout + // figure 8.9 - using codeDump to shout this.codeDump = { |str, result, func| [str, result, func].printAll }; @@ -189,22 +189,22 @@ this.codeDump = { |str| if (str.beginsWith(z.shoutTag)) { z.shout(str.drop(z.sho // figure 8.10 - updated setMessage flashes text. ( -z.setMessage = { |z, str| - var messSize = str.size; +z.setMessage = { |z, str| + var messSize = str.size; var fontsize = (1.64 * z.txtView.bounds.width) / max(messSize, 32); z.txtView.font_(GUI.font.new("Monaco", fontsize)); z.txtView.string_(str); z.animate; }; ) -//!! a long comment gets scaled down to a rather smaller font size, minimally fontsize 32! +//!! a long comment gets scaled down to a rather smaller font size, minimally fontsize 32! //!! short is big! ( z.makeWin = { |q, message="Shout this!"| z.win = Window("Shout", Rect(0, 900,1200, 100)).front; - z.win.alpha_(0.7); - z.win.view.background_(Color.clear); + z.win.alpha_(0.7); + z.win.view.background_(Color.clear); z.win.alwaysOnTop_(true); z.txtView = TextView(z.win, Rect(0, 0,1200, 100)); @@ -218,7 +218,7 @@ z.makeWin("shout."); // class files can be put into one of these locations: -Platform.userExtensionDir; +Platform.userExtensionDir; Platform.systemExtensionDir; @@ -228,16 +228,16 @@ Platform.systemExtensionDir; Shout { classvar <>tag="//!!"; var tag="//!!", <>width=1250, <>defaultCodeDumpFunc; + classvar <>tag="//!!", <>width=1250, <>defaultCodeDumpFunc; var