| Author |
Message |
kijjaz

Joined: Sep 20, 2004 Posts: 765 Location: bangkok, thailand
Audio files: 4
|
Posted: Tue Jul 22, 2008 4:17 pm Post subject:
Playing with Dynamic Array |
 |
|
As I'm getting very interested in using the new ChucK 1.2.1.2's dynamic array feature especially for building more complex data structures,
I've started this topic so we can share about this feature.
Today, I'm try adding array members:
| Code: | int a[0][0]; // start with a blank a[][]
<<< "int a[0][0];", "" >>>;
a << [1] << [2, 3]; // add [1] and [2, 3] to a
<<< "a << [1] << [2];", "" >>>;
a[1] << 4; // add 4 to a[1][1]
<<< "a[1][1] << 4;", "" >>>;
<<< "a.size(): ", a.size() >>>;
<<< "a[0].size(): ", a[0].size(), " a[1].size(): ", a[1].size() >>>;
<<< "a[0][0]:", a[0][0] >>>;
<<< "a[1][0]:", a[1][0] >>>;
<<< "a[1][1]:", a[1][1] >>>;
<<< "a[1][2]:", a[1][2] >>>; |
From the code, we start with a[0][0]
and after adding [1] and [2, 3] to a
we have a[0] and a[1] that each has different size,
so actually we have just grown a tree with different number of leaves between different branches.
This is such a nice thing we can do in ChucK!
. . .
Feel free to share more about arrays. |
|
|
Back to top
|
|
 |
ilSignorCarlo

Joined: Sep 17, 2007 Posts: 28 Location: Bologna
|
Posted: Thu Jul 24, 2008 6:07 am Post subject:
Re: Playing with Dynamic Array |
 |
|
| kijjaz wrote: |
| Code: | int a[0][0]; // start with a blank a[][]
<<< "int a[0][0];", "" >>>;
a << [1] << [2, 3]; // add [1] and [2, 3] to a
<<< "a << [1] << [2];", "" >>>;
a[1] << 4; // add 4 to a[1][1]
<<< "a[1][1] << 4;", "" >>>;
<<< "a.size(): ", a.size() >>>;
<<< "a[0].size(): ", a[0].size(), " a[1].size(): ", a[1].size() >>>;
<<< "a[0][0]:", a[0][0] >>>;
<<< "a[1][0]:", a[1][0] >>>;
<<< "a[1][1]:", a[1][1] >>>;
<<< "a[1][2]:", a[1][2] >>>; |
|
I don't know if it is normal, but on Windows I can't run this code inside MiniAudicle. I get this error:
[unnamed1]:line(4): cannot resolve operator '<<' on types 'int[][]' and 'int[]'
Anyway, it works fine from the shell. _________________ Self-referential phrases, like this one, are not so funny or good for a forum signature. |
|
|
Back to top
|
|
 |
kijjaz

Joined: Sep 20, 2004 Posts: 765 Location: bangkok, thailand
Audio files: 4
|
Posted: Thu Jul 24, 2008 9:49 am Post subject:
|
 |
|
Oh.. the operator << (add new member to the array, thus increase that array size by 1) ..
is a new feature in ChucK 1.2.1.2..
but current miniAudicle on the website has ChucK 1.2.1.1.
I was compiling miniAudicle but replacing the whole chuck source code with 1.2.1.2 so I can run 1.2.1.2-compatible code in miniAudicle.
So I guess, for you, if you still don't compile miniAudicle for windows,
you might have to try this with command-line 1.2.1.2 ChucK for now.
I hope we'll have the new miniAudicle executable up at ChucK's web soon. |
|
|
Back to top
|
|
 |
Kassen
Janitor


Joined: Jul 06, 2004 Posts: 7678 Location: The Hague, NL
G2 patch files: 3
|
Posted: Thu Jul 24, 2008 5:08 pm Post subject:
|
 |
|
| kijjaz wrote: |
I was compiling miniAudicle but replacing the whole chuck source code with 1.2.1.2 so I can run 1.2.1.2-compatible code in miniAudicle.
|
Does that work like that? _________________ Kassen |
|
|
Back to top
|
|
 |
kijjaz

Joined: Sep 20, 2004 Posts: 765 Location: bangkok, thailand
Audio files: 4
|
Posted: Thu Jul 24, 2008 7:02 pm Post subject:
|
 |
|
Yes. It simply works right away. I was compiling in Linux.
First, I extracted miniAudicle source,
then delete all files in chuck-1.2.1.1,
and repleace with ones from chuck-1.2.1.2's sourcecode package,
then compile.
THe Help -> About also shows the correct ChucK version. |
|
|
Back to top
|
|
 |
kijjaz

Joined: Sep 20, 2004 Posts: 765 Location: bangkok, thailand
Audio files: 4
|
Posted: Thu Jul 24, 2008 7:27 pm Post subject:
|
 |
|
This is one thing I tried with dynamic array:
It might become quite useful and easy.
It's adding members to 2D array,
and the good thing is that...
for example if we have int A[4][0];
each A[i] is independently sizable.
so by this, we can create more flexible tree structure array.
an easy example:
| Code: | int melody[0][0]; // new melody buffer
for(int i; i < 10; i++)
{
melody << [0];
// increase melody size for a set of new members
// add more members
for(int j; j < Std.rand2(3, 12); j++)
{
melody[i] << Std.rand2(0, 12); // add new note
}
}
Flute s => dac;
for(int i; i < 10; i++)
{
for(1 => int j; j < melody[i].size(); j++) // skip the first member '0'
{
melody[i][j] + 60 => Std.mtof => s.freq;
.2 => s.noteOn;
150::ms => now;
.2 => s.noteOff;
}
second => now;
} |
|
|
|
Back to top
|
|
 |
waldemaR
Joined: Feb 08, 2009 Posts: 14 Location: düsseldorf, germany
|
Posted: Thu Feb 26, 2009 1:11 pm Post subject:
|
 |
|
dear all,
i have same problem but with the command line.
error message:
[jogi_ClComboBox.ck]:line(87): cannot resolve operator '<<' on types 'ComboBoxEntry[]' and 'ComboBoxEntry'
i have download the file from the thread:
http://electro-music.com/forum/viewtopic.php?highlight=jogi&t=29736
and the jogi_ClComboBox.ck make the error.
any idea or help is appreciate, thank you.
waldemaR |
|
|
Back to top
|
|
 |
waldemaR
Joined: Feb 08, 2009 Posts: 14 Location: düsseldorf, germany
|
|
|
Back to top
|
|
 |
Inventor
Stream Operator

Joined: Oct 13, 2007 Posts: 5966 Location: San Antonio, Tx, USA
Audio files: 258
|
Posted: Fri Feb 27, 2009 9:50 pm Post subject:
|
 |
|
I have not yet found a need for this feature but I like the fact that we can make tree structures out of arrays. I'm sure there are fascinating things that we can do now that were not possible or practical before. _________________ "Let's make noise for peace." - Kijjaz |
|
|
Back to top
|
|
 |
waldemaR
Joined: Feb 08, 2009 Posts: 14 Location: düsseldorf, germany
|
Posted: Sat Feb 28, 2009 4:19 am Post subject:
jogi |
 |
|
jogi is for me helpful to learn chuck that's my reason, why.
waldemaR |
|
|
Back to top
|
|
 |
|