サンプル6(リズムを鳴らす)


3

4

6

7

8

0

-




 W




 E




 R




 T




 Y




 U




 I




 O




 P




 @

S

D

G

H

J

L

;




 Z




 X




 C




 V




 B




 N




 M




 ,




 .




 /


サンプル5に追加したソース
<body>

<label>Beats:</label> <select id=beat onchange='changebeat();'></select>
<label>Tempo:</label> <select id=tempo onchange='changetempo();'></select>
<button id=play onclick='play();'>Play</button>

<script><!--

var playing=0;
var interval=600;
var timeout;
var beat=4;
var count;

function play(){
	if(playing==1){
		playing=0;
		document.getElementById('play').innerHTML='Play';
		clearTimeout(timeout);
	}else{
		playing=1;
		document.getElementById('play').innerHTML='Stop';
		count=0; tick();
	}
}

function tick(){
	Jazz.MidiOut(0x99,count?33:34,90);
	count++; if(count>=beat) count=0;
	timeout=setTimeout(tick,interval);
}


function changebeat(){
	beat=select_beat.options[select_beat.selectedIndex].value;
}

function changetempo(){
	interval=60000./select_tempo.options[select_tempo.selectedIndex].value;
}

var select_beat=document.getElementById('beat');
for(var i=2;i<=4;i++){ select_beat[i-2]=new Option(i,i,i==4,i==4);}
var select_tempo=document.getElementById('tempo');
for(var i=40;i<=240;i++){ select_tempo[i-40]=new Option(i,i,i==100,i==100);}

--></script>

</body>