Plotting the array of ugens with nesting differs from the array of numbers with nesting

Dear users,

I am a bit confused due to the third example from the following codes:

Ex. 1: One-level arrays have the same behaviour:

  [       0, 1      ]  .plot       // code 1.1.
{ Line.kr(0, 1, 0.01) }.plot(0.01) // code 1.2.

Ex. 2: Two-level arrays have the same behaviour:

  [        [0, 1]      ,        [1, 0]       ]  .plot       // code 2.1.
{ [ Line.kr(0, 1, 0.01), Line.kr(1, 0, 0.01) ] }.plot(0.01) // code 2.2.

Ex. 3: Three-level arrays do not have the same behaviour:

(  [ [        [0, 1]      ,        [1, 0]       ], 
     [        [0, 1]      ,        [1, 0]       ] ]  .plot) // code 3.1.

({ [ [ Line.kr(0, 1, 0.01), Line.kr(1, 0, 0.01) ], 
	 [ Line.kr(0, 1, 0.01), Line.kr(1, 0, 0.01) ] ] }.plot) // code 3.2.

How could I reconstruct code 3.2. to get the same plotted result as code 3.1.?

I appreciate any help you can provide.

1 Like

I believe I thought something falsely, but I could not figure it out. Could anyone help me?

I just had a look at the source for Plotter…

I can see that a .plot method is defined for ArrayedCollection and a different .plot method is defined for Function.

in both cases the plot is divided into channels and those can be displayed separately or superposed.
[ [0, 1] , [1, 0] ] .plot
[ [0, 1] , [1, 0] ] .plot.superpose_(true)

you can also toggle superposition by pressing ‘s’ while over the plot window.

the method for ArrayedCollection will plot 2 and 3-dimensional arrays.

but the .plot method for Function will not.

The reason is that audio on the server is always represented as a 1-dimensional Array of channels. There is no meaning to nesting in channel representations. The .plot method under the hood calls .loadToFloatArray on the function - this sends the SynthDef to the server, computes the audio and writes it into a buffer. The buffers contents are then asynchronously sent back to the language.

Also just a quick correction: this

{ Line.kr(0, 1, 0.01) }.plot(0.01) // code 1.2.

is a single channel

this:

{ [ Line.kr(0, 1, 0.01), Line.kr(1, 0, 0.01) ] }.plot(0.01) // code 2.2.

is a 1-dimensional array of 2 channels

this one:

({ [ [ Line.kr(0, 1, 0.01), Line.kr(1, 0, 0.01) ], 
	 [ Line.kr(0, 1, 0.01), Line.kr(1, 0, 0.01) ] ] }.plot)

is a 2- dimensional Array of channels so can’t be rendered or plotted

I anticipated the same behaviour without checking the details of how each method was implemented. It was my fault. I appreciate your guidance and explanation!

1 Like