저는 자바 프로그래밍에 익숙하지 않고 javax.sound API (특히 미디 시퀀서)를 고심하려고 노력하고 있습니다. ShortMessage 클래스에 대한 문서에 따르면 오버로드 된 setmessage 메소드 중 하나는 int 명령, int 채널, int 데이터 1, int 데이터 2를 사용합니다. 나는 처음 두 가지 주장을 이해하지만, 나는 마지막 두 가지 옵션이 무엇인지 완전히 모르겠습니다. 제가 배우려고 노력하는 책은 피치와 속도가 맞다고 말합니다. 그러나 내가이 ints를 변경할 때 피치 나 스피커에서 나오는 음표의 볼륨이 전혀 변하지 않습니다. 아래는 내 소스 코드입니다.미디 트랙 피치 나 인스트르먼트가 바뀌지 않습니다
import javax.sound.midi.*;
public class BeastBoxStarter {
public static void main(String args[]) {
BeastBoxStarter playWithThis = new BeastBoxStarter();
playWithThis.play();
}
public void play(){
try {
Sequencer player = MidiSystem.getSequencer();
try{
Sequence seq = new Sequence(Sequence.PPQ, 4);
Track track = seq.createTrack(); //initialize a track
ShortMessage one = new ShortMessage(); //initialize a new ShortMessage
one.setMessage(ShortMessage.NOTE_ON, 1, 127, 1); //set the message
MidiEvent NoteOn = new MidiEvent(one, 1); //add a midi method to turn on the note
track.add(NoteOn); //add the midi to the sequence track
ShortMessage two = new ShortMessage(); //initialize a new ShortMessage
one.setMessage(ShortMessage.NOTE_OFF, 1, 127, 1); //set the message
MidiEvent NoteOff = new MidiEvent(two, 16); //add a midi method to turn on the note
track.add(NoteOff); //add the midi to the track
player.setSequence(seq); //add the sequence to the sequencer
player.open();
player.start(); //play the sequence with the sequencer
}
catch(InvalidMidiDataException iex){
iex.printStackTrace();
}
}
catch (MidiUnavailableException mex) {
mex.printStackTrace();
}
}
}
어떤 도움을 주셔서 감사합니다!
그게 내가 말한 문서가 어디 있는지 모르겠다 고 생각한 것입니다. 하지만 내 문제는 여전히 나타납니다 : 데이터 바이트 1을 바꿀 때 음표가 전혀 바뀌지 않습니다 – bailey2092
정확히 무엇을 바꾸 시나요? –
0에서 127 사이의 숫자. – bailey2092