GameOfLife/Unit-Lib — pull request #38 by miguel-negrao (2014-02-13 12:20:42+00:00)
Title: UX - plays a mono Udef as if it was multichannel of n channels by playin...

UX - plays a mono Udef as if it was multichannel of n channels by playing n synths. Addresses #36.

```
UChain( UX(4, \sine), UX(4, \whiteNoise), UX(4, \lowPass), [\output, [\numChannels, 4] ]).gui

//nice syntax:
UChain( [4, \sine], [4, \whiteNoise], [4, \lowPass], [\output, [\numChannels, 4] ]).gui

//only works for mono in or mono out
Udef(\test,{
UIn.ar(0,2)
})
UChain( UX(4, \test) )

//generates the correct compile string
UChain( [4, \sine], [4, \whiteNoise], [4, \lowPass], [\output, [\numChannels, 4] ]).asCompileString

//bundle generated:
UX(4, \sine).makeBundle(s)[0].dopostln

[ 9, u_sine, 1014, 1, 1, freq, 440, amp, 0.1, u_o_ar_0_lvl, 0, u_o_ar_0_bus, 0 ]
[ 9, u_sine, 1015, 1, 1, freq, 440, amp, 0.1, u_o_ar_0_lvl, 0, u_o_ar_0_bus, 1 ]
[ 9, u_sine, 1016, 1, 1, freq, 440, amp, 0.1, u_o_ar_0_lvl, 0, u_o_ar_0_bus, 2 ]
[ 9, u_sine, 1017, 1, 1, freq, 440, amp, 0.1, u_o_ar_0_lvl, 0, u_o_ar_0_bus, 3 ]

```

I gave it a go at implementing this. I deliberately choose to address only a specific case which is where there is a maximum one input and one output on the original Udef. This was as not to complicate matters regarding where those inputs and outputs should go. So we just take the bus number of the inputs and output and then use n-1 next consecutive buses. This is implemented by creating n synths and then passing the correct bus number to u_i_ar_0_bus and u_o_ar_0_bus. Everything else seems to work out of the box due to the fact that the synths get added to the synth array and so will all of them get the same set messages, etc. The main disavantage of this approach is that when going to the IO panel what you see doesn't reflect what will happen since you don't see the aditional connections happening. In any case, since I wanted to address the most simple solution, I didn't want the user to be able to change where things got routed for each channel (for that they can already duplicate the udef in the gui or by code). The main reason I didn't implement that is that for the current implementation I didn't have to touch the udef at all, while if I wanted to add the args u_o_ar_1_bus, etc then they would not be present in the specs array of the udef and I suspect things would break. I would say that this solution addresses the basic use case, which is "gee, I wished that lowpass could do 8 channels intead of just 1...".

I tried to test things but I might have missed something.