java.lang.ArrayIndexOutOfBoundsException: 4
조회수 1389회
void playNote(int pitch, boolean state, int instrument) {
//If current note has to be played and is not active.
if (state == true && activeNote[pitch] == false) {
//Send ON, channel, pitch and velocity to midi, change pitch to fixed notes if current instrument is a drum.
sc.sendMidi(sc.NOTE_ON, channel, ((instrument <= 12) ? octave+note[pitch] : drum[pitch]), velocity);
activeNote[pitch] = true;
}
//If current does not have to be played but is still active.
else if (state == false && activeNote[pitch] == true) {
//Send OFF, channel, pitch and velocity to midi, change pitch to fixed notes if current instrument is a drum.
sc.sendMidi(sc.NOTE_OFF, channel, ((instrument <= 12) ? octave+note[pitch] : drum[pitch]), velocity);
activeNote[pitch] = false;
}
//If current has to be played and also is still active
else if (state == true && activeNote[pitch] == true) {
//Send first an OFF message and then an ON message.
sc.sendMidi(sc.NOTE_OFF, channel, ((instrument <= 12) ? octave+note[pitch] : drum[pitch]), velocity);
sc.sendMidi(sc.NOTE_ON, channel, ((instrument <= 12) ? octave+note[pitch] : drum[pitch]), velocity);
activeNote[pitch] = true;
}
}
//Todo: Save music to midi.
void saveNote(int pitch, boolean state) {
if (state == true && activeNote[pitch] == false) {
score.addNote(i, channel, channel, pitch, random(60, 100), 1, 1, 1);
i++;
}
}
//Set octave of the current instrument
void setOctave(int input) {
int prevOctave = octave;
octave = 12*input;
for (int i = 0; i <8; i++) {
if (activeNote[i] == true) {
sc.sendMidi(sc.NOTE_OFF, channel, prevOctave+note[i], velocity);
sc.sendMidi(sc.NOTE_ON, channel, octave+note[i], velocity);
}
}
}
int readOctave() {
return (octave/12) - 1;
}
//Turn all active notes off
void disable() {
sc.stop();
}
//Set volume of instrument.
void setVolume(int input) {
if (abs(volume - input) > 5) {
sc.sendMidi(sc.CONTROL_CHANGE, channel, 7, input);
volume = input;
}
}
int readVolume() {
return volume;
}
//Change pitch of the instrument.
void setVelocity(int input) {
if (abs(prevVelocity - input) > 5) {
velocity = input;
prevVelocity = input;
}
}
-
(•́ ✖ •̀)
알 수 없는 사용자
2 답변
-
이렇게 올리시면 뭐가 문제인지 알 수가...
어디서 문제가 있는지 라인이나 메서드명을 알려주세요. 다른 사람이 직접 실행해볼 수 있을 만큼 소스를 올리는것도 좋은 질문 방법입니다.
스크린샷의 경고는 스태틱으로 선언된 변수를 인스턴스를 통해 접근해서 그렇습니다.
MidiMessageTypes sc = new MidiMessageTypes(); Object someVariable = sc.NOTE_ON;
위처럼 하지 마시고 아래처럼 하세요.
Object someVariable = MidiMessageTypes.NOTE_ON;
-
뭐 어쩌라는 건지?? 기본 예의가 없네요
-
(•́ ✖ •̀)
알 수 없는 사용자
-
댓글 입력