From: owner-sc-users-digest@lists.io.com (sc-users-digest) To: sc-users-digest@lists.io.com Subject: sc-users-digest V1 #142 Reply-To: sc-users Sender: owner-sc-users-digest@lists.io.com Errors-To: owner-sc-users-digest@lists.io.com Precedence: bulk sc-users-digest Monday, July 10 2000 Volume 01 : Number 142 ---------------------------------------------------------------------- Date: Sat, 08 Jul 2000 02:07:39 +0200 From: Julian Rohrhuber <---@---.---> Subject: Re: Streams and Strings Examples Dies ist eine mehrteilige Nachricht im MIME-Format. - --------------94D2A6FF73C8993851A89ACD Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit > When I get a chance I will post on my website the patterns that I have already written > the storeParamsOn methods for. good idea. > PseqSliders(16,30,50,1).gui(layout) > > gives a 16 step analog style sequencer, randomisable, rotate-able, printable and saveable. > And I have found I can use it for any kind of array that I want to alter with a gui, eg. > delay times or probability weights. I have been using gui separate from data which is very compact if you have a lot of patterns. this sounds easy and practical, though. There is a file attached, one little addition I´ve done to ListPatterns, because I wanted Patterns that only yield one of their items at a time. Just for the pool. Julian - --------------94D2A6FF73C8993851A89ACD Content-Type: text/plain; charset=us-ascii; x-mac-type="54455854"; x-mac-creator="74747874"; name="ListPatternExt.sc" Content-Transfer-Encoding: 7bit Content-Description: Unknown Dokument Content-Disposition: inline; filename="ListPatternExt.sc" //_______PopPatterns Ppseq : ListPattern { var <>offset; *new { arg list, repeats=1, offset=0; ^super.new(list, repeats).offset_(offset) } asStream { ^Routine.new({ arg inval; var item, offsetValue; offsetValue = offset.value; list = list.collect({ arg item; item.asStream }); if (inval.eventAt('reverse') == true, { repeats.value.do({ arg j; list.size.reverseDo({ arg i; item = (list @@ (i + offsetValue)).next; inval = item.embedInStream(inval); }); }); },{ repeats.value.do({ arg j; list.size.do({ arg i; item = (list @@ (i + offsetValue)).next; inval = item.embedInStream(inval); }); }); }); }); } } Ppshuf : ListPattern { asStream { ^Routine.new({ arg inval; var item, stream; list = list.scramble; list = list.collect({ arg item; item.asStream }); repeats.value.do({ arg j; list.size.do({ arg i; item = (list @@ i).next; inval = item.embedInStream(inval); }); }); }); } } Pprand : ListPattern { asStream { ^Routine.new({ arg inval; var item; list = list.collect({ arg item; item.asStream }); repeats.value.do({ arg i; item = list.at(list.size.rand).next; inval = item.embedInStream(inval); }); }); } } Ppxrand : ListPattern { asStream { ^Routine.new({ arg inval; var item, index, size; index = list.size.rand; list = list.collect({ arg item; item.asStream }); repeats.value.do({ arg i; size = list.size; index = (index + (size - 1).rand + 1) % size; item = list.at(index).next; inval = item.embedInStream(inval); }); }); } } Ppwrand : ListPattern { var <>weights; *new { arg list, weights, repeats=1; ^super.new(list, repeats).weights_(weights) } asStream { ^Routine.new({ arg inval; var item; list = list.collect({ arg item; item.asStream }); repeats.value.do({ arg i; item = list.at(weights.windex).next; inval = item.embedInStream(inval); }); }); } } - --------------94D2A6FF73C8993851A89ACD-- ------------------------------ Date: Sat, 08 Jul 2000 00:31:53 -0500 From: Gary Morrison <---@---.---> Subject: Buiding an Array - --------------603C5691336C1E5C72057BBF Content-Type: text/plain; charset=us-ascii; x-mac-type="54455854"; x-mac-creator="4D4F5353" Content-Transfer-Encoding: 7bit The help on ArrayedCollection, it says about the add method: Adds an item to an ArrayedCollection if there is space. If there is not any space left in the object then this method returns a new ArrayedCollection. For this reason, you should always assign the result of add to a variable - never depend on add changing the receiver. Here are the examples it gives along with SuperCollider's evaluation of these examples in italics: ( // z and y are the same object var y, z; z = [1, 2, 3]; y = z.add(4); z.postln; y.postln; [ 1, 2, 3, 4 ] [ 1, 2, 3, 4 ] ) ( // in this case a new object is returned var y, z; z = [1, 2, 3, 4]; y = z.add(5); z.postln; y.postln; [ 1, 2, 3, 4 ] [ 1, 2, 3, 4, 5 ] ) My questions are, 1. Why, since z is unpredictable after doing an add would you be interested in z anymore? Or to put it another way, why (other than that you would leave behind an orphaned chunk of memory) would you ever do other than z = z.add(5), so that z will have a predictable value after doing the add? 2. Is there a means of garbage-collecting such orphaned chunks of memory? Or even better, is there a method to add to an array that, if it can't expand its original location in memory, not only puts it somewhere else, but also garbage-collects the old block? - --------------603C5691336C1E5C72057BBF Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: 7bit The help on ArrayedCollection, it says about the add method:
Adds an item to an ArrayedCollection if there is space. If there is not any space left in the object then this method returns a new ArrayedCollection. For this reason, you should always assign the result of add to a variable - never depend on add changing the receiver.Here are the examples it gives along with SuperCollider's evaluation of these examples in italics:
(My questions are,
// z and y are the same object
var y, z;
z = [1, 2, 3];
y = z.add(4);
z.postln;
y.postln;
[ 1, 2, 3, 4 ]
[ 1, 2, 3, 4 ]
)(
// in this case a new object is returned
var y, z;
z = [1, 2, 3, 4];
y = z.add(5);
z.postln;
y.postln;
[ 1, 2, 3, 4 ]
[ 1, 2, 3, 4, 5 ]
)
(print out [1, 1] rather than [1, 1, 2, 3, 5, 8, 13]?
var fibArray, lastVal = 1, prevVal = 1;fibArray = [1, 1];
do (5, {arg iterCount;
fibArray = fibArray.add (lastVal + prevVal);
prevVal = lastVal; lastVal = fibArray.pop;
});fibArray.postln;
)
I've injected an iterCount.postln; into the do loop and it definitely is executing the loop five times, which presumably means that its doing five ArrayedCollection.adds.
I would think that, since I'm reassigning to the variable fibArray
whatever the add produces (be it the original chunk of memory
or a new, larger one), it should end up referring to an array with 5+2
entries in it.
- --------------A9EDCED45D7A974EC7CD17DD--
------------------------------
Date: Sat, 08 Jul 2000 00:55:31 -0500
From: James McCartney <---@---.--->
Subject: Re: Buiding an Array
> My questions are,
> Why, since z is unpredictable after doing an add would you be interested in z
> anymore? Or to put it another way, why (other than that you would leave
> behind an orphaned chunk of memory) would you ever do other than z = z.add(5),
> so that z will have a predictable value after doing the add?
> Is there a means of garbage-collecting such orphaned chunks of memory? Or even
> better, is there a method to add to an array that, if it can't expand its
> original location in memory, not only puts it somewhere else, but also
> garbage-collects the old block?
>
Please don't post in styled text. It makes quoting difficult.
There is no orphaned memory in SuperCollider, it is garbage collected
automatically.
You could use z.add(item); if you had preallocated the array to the proper
size, so that you knew it would not reallocate when an item was added to it.
Otherwise you should use z = z.add(item);
This happens to be the same way that array adds work in the Sather
programming language and is the most efficient way to implement it.
- --- james mccartney james@audiosynth.com Meaning that if I do z=z.add(x); and it is unable to extend
the existing array it the interpreter will dispose of, and possibly eventually
reallocate, the old array memory, but if I do y=z.add(x), it won't?
You could use z.add(item); if you had preallocated the array to the
proper
I've been changing the typeface or indenting stuff not just for the
hell of it, but to make apparent what is program code, or interpreter results,
and what is just english text. That seems like pretty common practice
in users' manuals, so I thought it would be useful here too.
I could use quotes I suppose, but then that could get confusing if the
code I'm quoting also contains quotes. Normal English rules say that
I should use semiquotes for quoting things that in themselves include quotes
and always put commas and periods inside the quotes, but that obviously
doesn't work for quoting code.
- --------------03F1EC2B83AF938A9CF676EC--
------------------------------
Date: Sat, 08 Jul 2000 12:57:10 -0500
From: James McCartney <---@---.--->
Subject: Re: Buiding an Array
on 7/8/00 11:52 AM, Gary Morrison at mr88cet@texas.net wrote:
> Meaning that if I do z=z.add(x); and it is unable to extend the existing array
> it the interpreter will dispose of, and possibly eventually reallocate, the
> old array memory, but if I do y=z.add(x), it won't?
SC will automatically reclaim objects that have become unreachable. If an
object is reachable by any path then it is retained. If you retain a
reference to an object then it cannot be reclaimed.
So you cannot create dangling pointers in SC. However one thing you can do
accidentally is retain a reference to an object you no longer need. This can
happen in the interpreter variables or class variables. You can clear all of
the interpreter variables by typing this.clearAll in the interpreter.
> Ah. Is there then some alternative version of Array.new that makes the array
> a certain size?
Array.new(n) creates an array big enough to hold n elements, however its
size is zero, meaning it has no elements. Elements can be added to it.
Array.newClear(n) creates an array of n elements, all set to nil. The size
is n.
- --- james mccartney james@audiosynth.com
print out [1, 1] rather than [1, 1, 2, 3, 5, 8, 13]?
Because pop removes the item you just added.
- --- james mccartney james@audiosynth.com <http://www.audiosynth.com>
SuperCollider - a real time synthes=
is programming language for the PowerMac.
<ftp://www.audiosynth.com/pub/updates/SC2.2.8.sea.hqx>
- --MS_Mac_OE_3045867939_224423_MIME_Part--
------------------------------
Date: Sat, 08 Jul 2000 11:52:37 -0500
From: Gary Morrison <---@---.--->
Subject: Re: Buiding an Array
- --------------F8AF8CD24A4C17C1F5AC89D9
Content-Type: text/plain; charset=us-ascii; x-mac-type="54455854"; x-mac-creator="4D4F5353"
Content-Transfer-Encoding: 7bit
> There is no orphaned memory in SuperCollider, it is garbage collected
> automatically.
Great.
Meaning that if I do z=z.add(x); and it is unable to extend the existing array it
the interpreter will dispose of, and possibly eventually reallocate, the old array
memory, but if I do y=z.add(x), it won't?
>
>
> You could use z.add(item); if you had preallocated the array to the proper
> size, so that you knew it would not reallocate when an item was added to it.
> Otherwise you should use z = z.add(item);
Ah. Is there then some alternative version of Array.new that makes the array a
certain size?
- --------------F8AF8CD24A4C17C1F5AC89D9
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
There is no orphaned memory in SuperCollider, it
is garbage collected
Great.
automatically.
Ah. Is there then some alternative version of Array.new
that makes the array a certain size?
size, so that you knew it would not reallocate when an item was added
to it.
Otherwise you should use z = z.add(item);
- --------------F8AF8CD24A4C17C1F5AC89D9--
------------------------------
Date: Sat, 08 Jul 2000 12:02:45 -0500
From: Gary Morrison <---@---.--->
Subject: Re: Fibonacci Array Example
- --------------03F1EC2B83AF938A9CF676EC
Content-Type: text/plain; charset=us-ascii; x-mac-type="54455854"; x-mac-creator="4D4F5353"
Content-Transfer-Encoding: 7bit
> on 7/8/00 12:42 AM, Gary Morrison at mr88cet@texas.net wrote:
Haha.
I've been changing the typeface or indenting stuff not just for the hell of it,
but to make apparent what is program code, or interpreter results, and what is
just english text. That seems like pretty common practice in users' manuals, so
I thought it would be useful here too.
I could use quotes I suppose, but then that could get confusing if the code I'm
quoting also contains quotes. Normal English rules say that I should use
semiquotes for quoting things that in themselves include quotes and always put
commas and periods inside the quotes, but that obviously doesn't work for
quoting code.
- --------------03F1EC2B83AF938A9CF676EC
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
on 7/8/00 12:42
AM,
Gary Morrison at mr88cet@texas.net wrote:
Haha.