I'm newbie. When I try to run this sketch, it gave me "Cannot convert from Object to int" on the line p = pitches.get(i);
Also, I wonder how to declare and initialize an ArrayList in a class. I wonder if I actually did it the right way. Many thanks in advance for your help.
Quote:class ChanLite
{
int x;
int y;
ArrayList pitches;
ChanLite(int ix, int iy) {
x = ix;
y = iy;
pitches = new ArrayList(5);
}
void display(int pit, int vel) {
int tr, tg, tb, p = 0;
pitches.add(pit);
for (int i = pitches.size()-1; i >=0; i--) {
p = pitches.get(i);
tr = tr + red(c[p%12]);
tg = tg + green(c[(int)pitches.get(i)%12]);
tb = tb + blue(c[(int)pitches.get(i)%12]);
}
fill(tr*vel/128/pitches.size(), tg*vel/128/pitches.size(), tb*vel/128/pitches.size());
rect(x, y, 20, 20);
}
void remove(int pit) {
// pop
int tr, tg, tb = 0;
pitches.add(pit);
for (int i = pitches.size()-1; i >=0; i--) {
if (pitches.get(i) == pit) {pitches.remove(i);} else {
tr = tr + red(c[pit%12]);
tg = tg + green(c[pit%12]);
tb = tb + blue(c[pit%12]);}
}
fill(tr*vel/128/pitches.size(), tg*vel/128/pitches.size(), tb*vel/128/pitches.size());
rect(x, y, 20, 20);
}
}