Tone.jsで音を鳴らしてみる
Tone.jsを使って簡単な演奏をしてみた。
今回は4分音符で単調なメロディーを繰り返すだけ。
doremi.html
<!-- index.html -->
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>サウンド</title>
</head>
<body>
<button id="play">PLAY</button>
<button id="stop">STOP</button>
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="https://cdn.rawgit.com/Tonejs/Tone.js/4c2cf070/build/Tone.js"></script>
<script>
var bell = new Tone.Synth().toMaster();
var bellPart = new Tone.Sequence(function(time, note){
bell.triggerAttackRelease(note, "4n", time);
}, ["C4", "D4", "E4", "F4", "E4", "D4","C4", "4n"]).start(0);
Tone.Transport.bpm.value = 120;
$("#play").click(function() {
Tone.Transport.start()
});
$("#stop").click(function() {
Tone.Transport.stop()
});
</script>
</body>
実行結果
今のところ4分音符の使い方しかわからず。
途中に2分音符や8分音符を挟むにはどうすればよいのだろう。
コメント