# [chuck-users] reference sub-sections of multi-dimensional arrays

eli queen eli at sleepingweather.com
Tue Apr 29 14:45:01 EDT 2008

```hi all ... this is my first post to the list. so, as you would guess,
i'm new to chuck.

the question ...

i'm working on a class with following functionality:
serial 12 tone row in > calculate a 12 tone matrix (2D array) >
lookup indexed rows (transposition) and/or lookup indexed columns
(inversion) > output lookups as 1D arrays

the row (x) part is simple:

array2D[ row# ] @=> int array1D[];

but, is it possible to reference the y subsection of a 2D array?

i know i could do it with a function i.e.:

int i[12];

fun void invrton ( int y ) {
for (0 => int x; x < 12; x++) {
toneRow.matrix[x][y] => i[x];
}
}

invrton(1);

this will assign i[] as values of column i(1), but is there a way w/o
the function?

i'll most likely put both lookups in the public twlvTone class so the
patterns can be accessed by shered-ed instruments.

anyway ... here's the full code:

public class twlvTone
{
int matrix[12][12];

fun void setMatrix ( int p0[] ) {
for (0 => int x; x < 12; x++) {
for (0 => int y; y < 12; y++) {
(p0[x] + ((12 - p0[y]) % 12)) % 12 => matrix[y][x];
}
}
}

}

twlvTone toneRow;

toneRow.setMatrix( [0, 11, 7, 8, 3, 1, 2, 10, 6, 5, 4, 9] );

<<< toneRow.matrix[0][5] >>>;

toneRow.matrix[1] @=> int t1[];
<<< t1[11] >>>;

thanks,
eli

```