SuperCollider Collectionについて

はじめに

本文はプレビューです。うまくまとめられたら、書き直します。以下、嘘を書いているかもしれませんし、結局helpの日本語注釈付きになってしまっていますので参考にならないと思います。途中で挫折していますし。ただ、helpの日本語注釈付きなんてすばらしいものは、それはそれでめちゃめちゃ需要ありそうですけれどね。ま、helpを翻訳する気なんざさらさらないですけれど。

以下、こんな感じで

/*
本テキストでは、Collectionオブジェクトをコレクションと記載します。
スパコでのコレクションとはオブジェクトの集合を指し、CollectionクラスのサブクラスにArray,Listなどなどがあります。コレクションの子に配列があるといった認識になります。
まず、つまづく点にArrayとListの違いがあります。Arrayは最大サイズが固定なので、はじめに定義したサイズを超えた要素は廃棄されます。Listはサイズが固定ではないため廃棄されず挿入されます。//おそらくこんな感じです、私はまだ詳しく理解出来ていません。
Array,ListともにCollection,SequenceableCollectionのサブクラスですのでこれらのメソッドは使用できますが、ArrayのメソッドはListでは使えません。ただし、同じだったり似たようなメソッドが多々ありますのでごっちゃになりがちです。親子関係を明確にしておかないと死ぬかもしれません。
*/

Collection

/*
一番の親クラスはCollectionなので、メソッドは一通り押さえておきましょう
*/

Class Methods:
*newFrom(collection)
Creates a new Collection from another collection. This supports the interface for the mathod "as"
//別のコレクションからコレクションを作成
Array.newFrom(Set[4, 2, 1]);	//[ 2, 4, 1 ] , setオブジェクトからArrayオブジェクトを作成
Set.newFrom(Array[4, 2, 1]);	//Set[ 2, 4, 1 ], ArrayオブジェクトからSetオブジェクトを作成
[1, 2, 3, 4, 3, 2].as(Set); // as(someClass) calls someClass.newFrom(this)


*with(collection)
Creates a new Collection from the args.
//要素に引数を代入したコレクションを作成
Array.with(4, 2, 1);	//[ 4, 2, 1 ]

*fill(size, function)
Creates a Collection of the given size, the elements of which are determined by evaluation the given function. The function is passed the index as an argument.
//コレクションのサイズを定義し、関数の戻り値を要素に代入したコレクションを作成。関数の引数にはインデックス番号が渡されます
Array.fill(4, { arg i; i * 2 });		//[ 0, 2, 4, 6 ] 、引数に渡されるインデックス番号は、0, 1, 2, 3になります
Accessing:
size
Answers the number of objects contained in the Collection.
//コレクションのサイズを返す
List[1, 2, 3, 4].size;		//4

isEmpty
Answer whether the receiver contains no objects.
//コレクションが要素を持っていないならばtrueを返す
List[].isEmpty;	//true
Adding and Removing:
add(anObject)
Add anObject to the receiver.
//anObjectをレシーバに追加。
//レシーバとはドット(.)の前に記述するオブジェクトを指します。レシーバ.メソッド()と書きます。
//これはメソッド呼び出し記法なんですかね?ドットシンタックスじゃないのかな・・・・・・
List[1, 2].add(3);		//List[ 1, 2, 3 ]

addAll(aCollection)
Add all items in aCollection to the receiver.
//aCollectionの要素をレシーバに追加
List[1, 2].addAll(List[3, 4]);		//List[ 1, 2, 3, 4 ]

remove(anObject)
Remove anObject from the receiver. Answers the removed object.
//レシーバからanObjectを削除
(
var a;
a = List[1, 2, 3, 4];
a.remove(3);
a;
)		//List[ 1, 2, 4 ]

removeAll(aCollection)
Remove all items in aCollection from the receiver.
//aCollectionの要素をレシーバから削除
List[1, 2, 3, 4].removeAll(List[2, 3]);		//List[ 1, 4 ]

Note that multiple items in the receiver will not necessarily be removed:
//レシーバの要素が全て削除されるわけではない、全て削除はremoveEvery
~closet = [\hat, \hat, \hat, \coat, \coat, \shoe, \shoe];
~closet.removeAll([\hat, \coat, \shoe, \shoe]); //[ hat, hat, coat ]  Doesn't empty the closet, just removes what we wanted to

See removeEvery (below) for a related method that removes all occurrences.

removeEvery(aCollection)
Remove all occurrences of the items in aCollection from the receiver.
//レシーバからaCollectionの要素を全て削除
List[1, 2, 3, 2, 3, 2, 3, 4].removeEvery(List[2, 3]);	//List[ 1, 4 ] 2,3を全て削除

removeAllSuchThat(function)
Remove all items in the receiver for which function answers true. The function is passed two arguments, the item and an integer index. Answers the objects which have been removed.
//レシーバから関数の戻り値を削除
(
var a;
a = List[1, 2, 3, 4];
a.removeAllSuchThat({ arg item, i; item < 3 });
a;
)		//List[ 3, 4 ] , 3より小さい要素を削除
putEach(keys, values)
Put the values in the corresponding indices given by keys. If one of the two argument arrays is longer then it will wrap.
//レシーバのkeysで指定したインデックスに valuesを追加、引数のいずれかが配列ならそれを追加
y = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];		//[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
y.putEach([4, 7], [\smelly, \head])		//[ 0, 1, 2, 3, smelly, 5, 6, head, 8, 9 ] , 4個目と7個目にsmelly,headを追加
y.putEach([2, 3, 5, 6], \wotsits);		//[ 0, 1, wotsits, wotsits, smelly, wotsits, wotsits, head, 8, 9 ] , 2,3,5,6個目にwotsistsを追加

atAll(keys)
return a collection of all the items for the keys.
//レシーバの要素からkeysインデックス番号のものを抜き出す
y = [\a, \b, \c];		//[ a, b, c ]
y.atAll([0, 2])		//[ a, c ]

ArrayCollection

Class Methods
*with(... args)
Create a new ArrayedCollection whose slots are filled with the given arguments.
//argで埋めた新しい配列を作成
Array.with(7, 'eight',  9).postln;		//[ 7, eight, 9 ]

*series(size, start, step)
Fill an ArrayedCollection with an arithmetic series.
//等差級数で埋めた新しい配列、startからstepづつ増やした数値をsize分の要素で配列を作成
Array.series(5, 10, 2).postln;			//[ 10, 12, 14, 16, 18 ]

*geom(size, start, grow)
Fill an ArrayedCollection with a geometric series.
//等比級数で埋めた新しい配列、startからgrow倍の数値をsize分の要素で配列を作成
Array.geom(5, 1, 3).postln;			//[ 1, 3, 9, 27, 81 ]

*iota(...sizes)
Fills an ArrayedCollection with a counter. See J_concepts_in_SC for more examples.
//iota(a, b, c, d)ならd個の要素をもった配列がc個あり、そのc個の配列がb個あり、そのb個の配列がa個ある配列を作成、要素は0からカウントアップ
//[ [ [ [ d個 ] がc個 ] がb個 ] がa個 ]分かりにくいけれど、こんな感じです。
Array.iota(2, 3);					//[ [ 0, 1, 2 ], [ 3, 4, 5 ] ] 3個の要素を持った配列が2個
Array.iota(2, 3, 4);					//[ [ [ 0, 1, 2, 3 ], [ 4, 5, 6, 7 ], [ 8, 9, 10, 11 ] ], [ [ 12, 13, 14, 15 ], [ 16, 17, 18, 19 ], [ 20, 21, 22, 23 ] ] ]

*fill2D(rows, cols, function)
Creates a 2 dimensional ArrayedCollection of the given sizes. The items are determined by evaluation of the supplied function. The function is passed row and column indexes as arguments. See J_concepts_in_SC
//2次元配列を作成、rows個の要素を持った配列をcols個作成し要素はfunctionで代入
Array.fill2D(2, 4, 0);					//[ [ 0, 0, 0, 0 ], [ 0, 0, 0, 0 ] ]
Array.fill2D(3, 4, { arg r, c; r*c+c; });	//[ [ 0, 1, 2, 3 ], [ 0, 2, 4, 6 ], [ 0, 3, 6, 9 ] ]

*fill3D(planes, rows, cols, function)
Creates a 3 dimensional ArrayedCollection of the given sizes. The items are determined by evaluation of the supplied function. The function is passed plane, row and column indexes as arguments. See J_concepts_in_SC
//fill2Dの3次元版
Array.fill3D(2, 3, 4, { arg p, r, c; p; });

*fillND(dimensions, function)
Creates a N dimensional ArrayedCollection where N is the size of the array dimensions. The items are determined by evaluation of the supplied function. The function is passed N number of indexes as arguments.
//多次元版
Array.fillND([4, 4], { arg a, b; a+b; });				//2d
Array.fillND([4, 4, 4], { arg a, b, c; a+b*c; });		//3d
Array.fillND([1, 2, 3, 4], { arg a, b, c, d; b+d; });	//4d

とまあこのように

つらつらhelpを見ていますが、よくわからないメソッドがごちゃごちゃとあります。自分の使いそうなクラス、メソッドは理解して意訳する必要はありそうですね。