[sc-users] plot with range

andrea valle valle at di.unito.it
Sat Dec 2 12:17:00 PST 2006


Hi to all,

I was (very gently) hacking ArrayedCollection-plot to be able to define 
a comparison range so to displayed proportionally scaled arrays.

First: am I reinventing the wheel? (Probably).

Any way, here's my plot2 (new code indicated with comments):

+ ArrayedCollection {

plot2 { arg name, bounds, discrete=false, numChannels = 1, range;
		//new: range = comparison range (array e.g. [-1,1])
		var plotter, txt, chanArray, unlaced, val, minval, maxval, window, 
thumbsize, zoom, width,
			layout, write=false;
		var minPlot, maxPlot; 						//new
		
		bounds = bounds ?  Rect(200 , 140, 705, 410);
		
		width = bounds.width-8;
		zoom = (width / (this.size / numChannels));
		
		if(discrete) {
			thumbsize = max(1.0, zoom);
		}{
			thumbsize = 1;
		};
		minval = this.minItem;
		maxval = this.maxItem;
			
			// new code
		name = name ? "plot2";						
		range = range ? [minval, maxval];			
		minPlot = minval.linlin(range[0], range[1], 0.0, 1.0);
		maxPlot = maxval.linlin(range[0], range[1], 0.0, 1.0);
			// end new code
		
		unlaced = this.unlace(numChannels);
		chanArray = Array.newClear(numChannels);
		unlaced.do({ |chan, j|
			val = Array.newClear(width);
			width.do { arg i;
				var x;
				x = chan.blendAt(i / zoom);
				val[i] = x.linlin(minval, maxval, minPlot, maxPlot); //new
			};
			chanArray[j] = val;
		});
		window = SCWindow(name, bounds);
		txt = SCStaticText(window, Rect(8, 0, width, 18))
				.string_("index: 0, value: " ++ this[0].asString);
		layout = SCVLayoutView(window, Rect(4, txt.bounds.height, width,
			bounds.height - 30 - txt.bounds.height)).resize_(5);
		numChannels.do({ |i|
			plotter = SCMultiSliderView(layout, Rect(0, 0,
					layout.bounds.width,layout.bounds.height))
				.readOnly_(true)
				.drawLines_(discrete.not)
				.drawRects_(discrete)
				.thumbSize_(thumbsize)
				.valueThumbSize_(1)
				.colors_(Color.black, Color.blue(1.0,1.0))
				.action_({|v|
					var curval;
					curval = v.currentvalue.linlin(0.0, 1.0, minval, maxval);
					
					txt.string_("index: " ++ (v.index / zoom).roundUp(0.01).asString ++
					", value: " ++ curval);
					if(write) { this[(v.index / zoom).asInteger]  = curval };
				})
				.keyDownAction_({ |v, char|
					if(char === $l) { write = write.not; v.readOnly = write.not;  };
				})
				.value_(chanArray[i])
				.resize_(5)
				.elasticMode_(1);
				
		});
		
		^window.front;
		
	}
}



Consider these:

a = Signal.newClear(16);
a.waveFill({arg x; 0.5*sin(2*pi*x)}, 0, 15);
a.plot2(range:[-1.5,1.5], name:"|1.5|");
a.plot2(range:[-1.0,1.0],name:"|1|");
a.plot2(range:[-0.5,0.5],name:"|0.5|");

Now, this:

a.plot2(range:[-0.25,0.25],name:"|0.25|");

What's happening in the last case? I was expecting a cut curve. In 
general if array max or min exceed range I have this behaviour.

Many thanks

-a-




Andrea Valle
DAMS - Facoltà di Scienze della Formazione
Università degli Studi di Torino
http://www.semiotiche.it/andrea
andrea.valle at unito.it
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: text/enriched
Size: 7747 bytes
Desc: not available
Url : http://www.create.ucsb.edu/pipermail/sc-users/attachments/20061202/85d57ae9/attachment-0001.bin


More information about the sc-users mailing list