?? life.pde
字號(hào):
// Based on the work of Bjoern Froehli. Many thanks!
import promidi.*;
class Life {
// The state of the life object
final static int DEAD = -1;
final static int BORN = 0;
final static int ALIVE = 1;
int state;
// Midi
MidiIO midiIO;
MidiOut midiout;
int midiInstrument;
int midiLength;
int midiVelocity;
Note note;
// x and y corner position, width and height
int x, y, w, h;
Life(int winWidth, int winHeight, int row, int col, int idx, int idy) {
// Calculate width and height
w = winWidth / row;
h = winHeight / col;
// Position in the grid
x = w * idx;
y = h * idy;
// Not born yet
state = Life.DEAD;
// Midi instrument
midiInstrument = 30;
midiLength = 20;
midiVelocity = 80;
// Midi object
midiIO = MidiIO.getInstance();
midiIO.closeOutput(1);
midiout = midiIO.getMidiOut(1, 2);
midiout.sendProgramChange(new ProgramChange(midiInstrument));
// Higher notes at the top of the grid
setNote( (int) ( ((float) idy / col) * 16) );
}
void display() {
ellipseMode(CORNER);
fill(127);
ellipse(x, y, w, h);
}
void playSound() {
midiout.sendNote(note);
}
void clicked(int mx, int my) {
if (mx > x && mx < x + w && my > y && my < y + h) {
state = Life.BORN;
}
}
int getState() {
return state;
}
void setState(int state) {
this.state = state;
}
void setNote(int n) {
switch(n) {
case 0:
note = new Note(86, midiVelocity, midiLength);
break;
case 1:
note = new Note(83, midiVelocity, midiLength);
break;
case 2:
note = new Note(79, midiVelocity, midiLength);
break;
case 3:
note = new Note(74, midiVelocity, midiLength);
break;
case 4:
note = new Note(71, midiVelocity, midiLength);
break;
case 5:
note = new Note(67, midiVelocity, midiLength);
break;
case 6:
note = new Note(62, midiVelocity, midiLength);
break;
case 7:
note = new Note(59, midiVelocity, midiLength);
break;
case 8:
note = new Note(55, midiVelocity, midiLength);
break;
case 9:
note = new Note(50, midiVelocity, midiLength);
break;
case 10:
note = new Note(47, midiVelocity, midiLength);
break;
case 11:
note = new Note(43, midiVelocity, midiLength);
break;
case 12:
note = new Note(38, midiVelocity, midiLength);
break;
case 13:
note = new Note(35, midiVelocity, midiLength);
break;
case 14:
note = new Note(31, midiVelocity, midiLength);
break;
case 15:
note = new Note(26, midiVelocity, midiLength);
break;
default:
note = new Note(20, midiVelocity, midiLength);
break;
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -