マウスによる演奏
sounds = new AudioClip[nsound]; //auファイルを読み込む sounds[i] = getAudioClip(getCodeBase(),"sound.au"); sounds[themenote[i]-1].play();//演奏
<APPLET CODE = "harp.Applet1.class" NAME = "Harp"> <PARAM NAME = "nsound" VALUE = "12"> <PARAM NAME = "dir" VALUE = "audio"> <PARAM NAME = "Speed" VALUE = "100"> </APPLET>
public void getMedia(){//.auファイルの読み込み int i; sounds = new AudioClip[nsound]; for(i=0;i<nsound;i++){ try{ sounds[i] = getAudioClip(getCodeBase(),dir+"/TONE"+(i+1)+".AU"); }catch(Exception e){ System.out.println(e);} } }
public void changeaRect(){//格子の色を変更 int i,x; int floor,room; //段とマス x= (int)(Math.random() * nsound*6)+1; //乱数を生成 floor=x % nsound; //何段めかを調べる room= (int)(Math.random() * nsound); //左から何番の格子か x= (int)(Math.random() * (nsound)); if(x>=floor){ //ノートナンバーは格子のナンバーとする noteno[floor][room]=room; } else{ //ノートのナンバーを変更する noteno[floor][room]=(int)(Math.random() * 12); //ノートナンバー } }
public boolean mouseMove(Event event,int x,int y) { //System.out.println("mouseMove:dim"+dim.width+"nowx:"+nowx); nowx=x/(dim.width/nsound); if(nowx>nsound-1) nowx=nsound-1; nowy=y/(dim.height/nsound); if(nowy>nsound-1) nowy=nsound-1; if(beforex==nowx && beforey==nowy){//マウスの移動なし return true; } else{ sounds[noteno[nowy][nowx]].play(); beforex=nowx;beforey=nowy; } return true; }
public void paint(Graphics g) { if(counter==12){ changeaRect(); int i,i1; for(i1=0;i1<nsound;i1++){ for(i=0;i<nsound;i++){ if(i1==nowy && i==nowx) g.setColor(Color.white); else g.setColor(color[noteno[i1][i]]); g.fillRect(i*dim.width/nsound,i1*dim.height/nsound, dim.width/nsound,dim.height/nsound); } } } else if(counter<12){ //最初にテーマの演奏、以後格子をランダムに変更しながら表示 theme(counter); counter++; } }