자바코드 질문좀 드립니다.ㅠ.ㅠ
사라
import java.awt.*;
import javax.swing.*;
import javax.sound.midi.*;
import java.util.*;
import java.awt.event.*;
public class beatbox {
jpanel mainpanel;
arraylistjcheckbox checkboxlist;
sequencer sequencer;
sequence sequence;
track track;
jframe theframe;
string[] instrumentnames = {bass drum,closed hi-hat,open hi-hat,acoustic snare,crash cymbal,
hand clap,high tom,hi bongo,maracas,whistle,low conga,cowbell,vibraslap,low-mid tom,
high agogo,open hi conga};
int[] instruments = {35,42,46,38,49,39,50,60,70,72,64,56,58,47,67,62};
public static void main(string[] args){
new beatbox().buildgui();
}
public void buildgui(){
theframe = new jframe(cyber beatbox);
theframe.setdefaultcloseoperation(jframe.exit_on_close);
borderlayout layout = new borderlayout();
jpanel background = new jpanel(layout);
background.setborder(borderfactory.createemptyborder(10,10,10,10));
//비어있는 경계선을 사용하여 패널 둘레와 구성요소가 들어가는 자리 사이에 빈공간을 만들수 있습니다.
checkboxlist = new arraylistjcheckbox();
box buttonbox = new box(boxlayout.y_axis);
jbutton start = new jbutton(start);
start.addactionlistener(new mystartlistener());
buttonbox.add(start);
jbutton stop = new jbutton(stop);
stop.addactionlistener(new mystoplistener());
buttonbox.add(stop);
jbutton uptempo = new jbutton(tempo up);
uptempo.addactionlistener(new myuptempotlistener());
buttonbox.add(uptempo);
jbutton downtempo = new jbutton(tempo down);
downtempo.addactionlistener(new mydowntempolistener());
buttonbox.add(downtempo);
box namebox = new box(boxlayout.y_axis);
for(int i = 0; i 16; i++){
namebox.add(new label(instrumentnames[i]));
}
background.add(borderlayout.east,buttonbox);
background.add(borderlayout.west,namebox);
theframe.getcontentpane().add(background);
gridlayout grid = new gridlayout(16,16);
grid.setvgap(1);
grid.sethgap(2);
mainpanel = new jpanel(grid);
background.add(borderlayout.center,mainpanel);
for(int i = 0; i 256;i++){
jcheckbox c = new jcheckbox();
c.setselected(false);
checkboxlist.add(c);
mainpanel.add(c);
}
setupmidi();
theframe.setbounds(50,50,300,300);
theframe.pack();
theframe.setvisible(true);
}
public void setupmidi(){
try{
sequencer = midisystem.getsequencer();
sequencer.open();
sequence = new sequence(sequence.ppq,4);
track = sequence.createtrack();
sequencer.settempoinbpm(120);
}catch(exception e){e.printstacktrace();}
}
public void buildtrackandstart(){
int[] tracklist = null;
sequence.deletetrack(track);
track = sequence.createtrack();
for(int i = 0; i 16;i++){
tracklist = new int[16];
int key = instruments[i];
for(int j = 0; j 16; j++){
jcheckbox jc = (jcheckbox)checkboxlist.get(j + (16*i));
if(jc.isselected()){
tracklist[j] = key;
} else {
tracklist[j] = 0;
}
}
maketracks(tracklist);
track.add(makeevent(176,1,127,0,16));
}
track.add(makeevent(192,9,1,0,15));
try{
sequencer.setsequence(sequence);
sequencer.setloopcount(sequencer.loop_continuously);
sequencer.start();
sequencer.settempoinbpm(120);
}catch(exception e){e.printstacktrace();}
}//buildtrackandstrat 메소드끝
public class mystartlistener implements actionlistener{
public void actionperformed(actionevent a){
buildtrackandstart();
}
}
public class mystoplistener implements actionlistener{
public void actionperformed(actionevent a){
sequencer.stop();
}
}
public class myuptempotlistener implements actionlistener{
public void actionperformed(actionevent a){
float tempofactor = sequencer.gettempofactor();
sequencer.settempofactor((float)(tempofactor * 1.03));
}
}
public class mydowntempolistener implements actionlistener{
public void actionperformed(actionevent a){
float tempofactor = sequencer.gettempofactor();
sequencer.settempofactor((float)(tempofactor* .97));
}
}
public void maketracks(int[] list){
for (int i=0; i16; i++){
int key = list[i];
if(key != 0){
track.add(makeevent(144,9,key,100,i));
track.add(makeevent(128,9,key,100,i+1));
}}}
public midievent makeevent(int comd,int chan,int one,int two,int tick){
midievent event = null;
try{
shortmessage a = new shortmessage();
a.setmessage(comd,chan,one,two);
event = new midievent(a,tick);
}catch(exception e){e.printstacktrace();}
return event;
}
}
음악소리 실행하는 파일입니다. 빨간줄 친 midievent부분 이 좀 이해가 안갑니다. shortmessage()가 어떤역할을 하는지..
그리고 여기서 생성한 int comd,int chan,int one,int two,int tick 이변수들..어디에서 활용이 되는 건지 모르겠습니다.
답변해주시면 정말 감사합니다.