Lecture code files: uofi.box.com/s/b2hapggp6taaea... Homework assignments: uofi.box.com/s/fi1ibe34biouft... An introduction to creating graphical user interfaces (GUIs) in SuperCollider.
Hi Eli. I note that an alternative to using 8.collect({Slider.new()}) to generate the sliders (@15mins) is to use {Slider.new(win)}!8. I'm a little confused why this works yet 8.do({Slider.new()}) does not work. In fact this probably boils down to the fact that i still can't wrap my head around the distinction between .collect and .do (whose help files seem so similar).
The difference between 'do' and 'collect' involves _what_ _these_ _methods_ _return._ 'do' returns its receiver, but 'collect' returns a collection populated with the returned values of its function. Therefore, 8.do({Thing}) will always return '8,' but 8.collect({Thing}) will return an array of eight Things. In this case, 'collect' is a good choice because it returns an array of Sliders. We capture this array in a variable so that we can reference the Sliders later on. Because 'do' only returns its receiver (the number 8), it's not a good choice here - there's no point is capturing a reference to the number 8. A good question is - what is 'do' actually useful for? I think it's safe to say that anything you can do with 'do', you can also do with 'collect', but not the other way around. So, 'do' is useful when you simply want to do something a certain number of times, but don't need to capture and retain some result, for example, setting a value for each Slider in the array. (And 'do' is only two characters long, which is a small bonus). Relatedly, it's important to be aware that 8.do and 8.collect are shortcuts for [0,1,2,3,4,5,6,7].do and [0,1,2,3,4,5,6,7].collect. There are lots of other iteration methods in the same family as 'do/collect' (select, reject, detect, any, every, etc.). Understanding these may help put 'do' and 'collect' into context. See the Collection help file for examples and descriptions.