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>和音の再生</p>
<button id="canonchord">カノン</button>
<button id="canonchord_loop">カノンループ</button>
<br>
<button id="transport_start">Transport_start</button>
<button id="transport_stop">Transport_stop</button>
<button id="transport_stop_delete">Transport_stop(イベントも削除)</button>


              
            
!

CSS

              
                
              
            
!

JS

              
                //Polysynth音源
let synth = new Tone.PolySynth().toMaster();

let GM=["G3","B3","D4"];
let Em=["E3","G3","B3"];

let canon=[
  ['0:0:0', ["C4","E4","G4"]],
  ['0:1:0', ["G3","B3","D4"]],
  ['0:2:0', ["A3","C4","E4"]],
  ['0:3:0', Em],//←変数を使うこともできる
  ['1:0:0', ["F3","A3","C3"]],
  ['1:1:0', ["C3","E3","G3"]],
  ['1:2:0', ["F3","A3","C3"]],
  ['1:3:0', GM]
];

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

$("#canonchord").on("click",function(){
    let canonplay = new Tone.Part(soundset, canon).start()
});

$("#canonchord_loop").on("click",function(){
    let canonloop = new Tone.Part(soundset, canon).start()
    //繰り返し回数を設定
    canonloop.loop=2;
    //loopされるタイミングを"2m"(2小節分(?)に修正)※デフォルトは"1m"でloopが行われるため、下記の記載が無いと最後まで再生されません
    canonloop.loopEnd="2m";
});

$("#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上のイベントを削除している
});
              
            
!
999px

Console