私はかなりプログラミングに新しく、私はjavax.sound API(特にMIDIシーケンサー)を頭に入れようとしています。 ShortMessageクラスのドキュメントによると、オーバーロードされたsetmessageメソッドの1つは、int command、int channel、int data1、int data2です。私は最初の2つの議論を理解するが、私は最後の2つのオプションが何であるか完全にはわからない。私が学ぶことを試みている本は、ピッチとスピードが合理的だと言っていますが、私がそれらのイントを変えると、スピーカーから出てくる音の音程や音量はまったく変化しません。以下は私のソースコードです。MIDIトラックの音程や音程が変化しない
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