Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <p>Tone.sampler</p>
<p>単音</p>
<button id="single_C">ド</button>
<button id="single_E">ミ</button>
<button id="single_G">ソ</button>
<button id="CMajor">和音</button>
<p>音階</p>
<button id="tonejs_kaeru">カエルの歌</button>
<button id="tonejs_star">きらきら星</button>
<br>
<br>
<button id="transport_start">Transport_start</button>
<button id="transport_stop">Transport_stop</button>
<button id="transport_stop_delete">Transport_stop(イベントも削除)</button>

<p>音楽を再生する場合</p>
<button id="pianomusic">通常再生</button>
<button id="pianomusic_keyup">キーを上げて再生</button>
              
            
!

CSS

              
                
              
            
!

JS

              
                //ピアノ音源
let piano = new Tone.Sampler({
  "C3":"https://dl.dropbox.com/s/wx1cdawifqyijvn/piano_C3.mp3?dl=0",
  "G3":"https://dl.dropbox.com/s/pppxlzcf1g8mcmf/piano_G3.mp3?dl=0"
}).toMaster();

let pianomusic = new Tone.Sampler({
  "C3":"https://dl.dropbox.com/s/k3i7qqde16b0oul/pianoBGM.mp3?dl=0"
}).toMaster();

//カエルの歌(単音)
let kaeru =['C3','D3','E3','F3','E3','D3','C3',null,'E3','F3','G3','A3','G3','F3','E3',null,'C3',null,'C3',null,'C3',null,'C3',null,['C3','C3'],['D3','D3'],['E3','E3'],['F3','F3'],'E3','D3','C3']; 

//きらきら☆
let star = [
  ['0:0:0',"C5"],
  ['0:1:0',"C5"],
  ['0:2:0',"G5"],
  ['0:3:0',"G5"],
  ['1:0:0',"A5"],
  ['1:1:0',"A5"],
  ['1:2:0',"G5"],
  ['2:0:0',"F5"],
  ['2:1:0',"F5"],
  ['2:2:0',"E5"],
  ['2:3:0',"E5"],
  ['3:0:0',"D5"],
  ['3:1:0',"D5"],
  ['3:2:0',"C5"],
];

//関数を作成
function pianoset(time, note) {
    piano.triggerAttackRelease(note, '4n', time);
}

$("#single_C").on("click",function(){
  piano.triggerAttackRelease("C3","2n");
});

$("#single_E").on("click",function(){
  piano.triggerAttackRelease("E3","2n");
});

$("#single_G").on("click",function(){
  piano.triggerAttackRelease("G3","2n");
});

$("#CMajor").on("click",function(){
  piano.triggerAttackRelease(["C3","E3","G3"],"1m");
});

$("#tonejs_kaeru").on("click",function(){
    let kaerumelody = new Tone.Sequence(pianoset, kaeru).start()
  //繰り返し回数を0回に設定(繰り返し回数を指定しないと無限にループする)
    kaerumelody.loop = 0;
});

$("#tonejs_star").on("click",function(){
    let star_play = new Tone.Part(pianoset, star).start();
});

$("#transport_start").on("click",function(){
    Tone.Transport.start();
});

$("#transport_stop").on("click",function(){
   Tone.Transport.stop();//←transportをストップ
});

$("#transport_stop_delete").on("click",function(){
   Tone.Transport.stop();//←transportをストップ
   Tone.Transport.cancel();//transport上のイベントを削除している
});

$("#pianomusic").on("click",function(){
  pianomusic.triggerAttackRelease("C3","1m");
});

$("#pianomusic_keyup").on("click",function(){
  pianomusic.triggerAttackRelease("D3","1m");
});

//BPMの指定
Tone.Transport.bpm.value = 120;
              
            
!
999px

Console