2016-09-19 3 views
-1

저는 자바 프로그래밍에 익숙하지 않고 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(); 
     } 
    } 


} 

어떤 도움을 주셔서 감사합니다!

답변

2

data1/data2 값은 MIDI 메시지의 데이터 바이트입니다 (있는 경우).

MIDI 메시지의 형식을 알고 있다고 가정합니다. official specification 또는 summary table을 참조하십시오.

노트 켜기 메시지의 경우 data1은 노트 번호이고 data2은 속도 (= 볼륨)입니다. 음표 꺼짐 메시지의 경우 음표 번호는 data1이고, 속도는 보통 data2입니다 (대개 무시됩니다).

+0

그게 내가 말한 문서가 어디 있는지 모르겠다 고 생각한 것입니다. 하지만 내 문제는 여전히 나타납니다 : 데이터 바이트 1을 바꿀 때 음표가 전혀 바뀌지 않습니다 – bailey2092

+0

정확히 무엇을 바꾸 시나요? –

+0

0에서 127 사이의 숫자. – bailey2092

관련 문제