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.

Editor Settings

Code Indentation

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

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

              
                <h1>和音</h1>
<p>マイナー(1オクターブ)</p>
<ul id="piano">
   <li id="C4" class="w_key">ド</li>
   <li id="Cs4" class="b_key"></li> 
   <li id="D4" class="w_key">レ</li>
   <li id="Ds4" class="b_key"></li> 
   <li id="E4" class="w_key">ミ</li>
   <li id="F4" class="w_key">ファ</li>
   <li id="Fs4" class="b_key"></li>
   <li id="G4" class="w_key">ソ</li>
   <li id="Gs4" class="b_key"></li>
   <li id="A4" class="w_key">ラ</li>
   <li id="As4" class="b_key"></li>
   <li id="B4" class="w_key">シ</li>
   <li id="C5" class="w_key">ド</li>
</ul>
              
            
!

CSS

              
                h1, p {
  text-align: center;
}

#piano {
  background: #333;
  padding: 10px;
  width: 305px;
  display: block;
  margin: 0 auto;
  position: relative;
}

.w_key {
  background: #FFF;
  border: 0px solid #333;
  width: 34px;
  text-align: center;
  padding:  90px 0 10px;
  display: inline-block;
}

.w_key:hover, 
.b_key:hover {
  opacity: 0.7;
}

.b_key {
  position: absolute;
  z-index: 10;
  top: 10px;
  margin: 0 -20px;
  padding: 0;
  background: #000;
  border: 1px solid #fff;
  color: #fff;
  width: 35px;
  height: 75px;
  text-align: center;
  display: inline-block; 
}


              
            
!

JS

              
                //DOM
var Key = document.querySelectorAll('#piano li');

//音階
var scale = [
  //休符
  'null', 
  //1オクターブ目
  'C4', 'C#4', 'D4', 'D#4', 'E4', 'F4', 'F#4', 'G4', 'G#4', 'A4', 'A#4', 'B4',
  //2オクターブ目
  'C5', 'C#5', 'D5', 'D#5', 'E5', 'F5', 'F#5', 'G5', 'G#5', 'A5', 'A#5', 'B5'];

//ルート音
var root = {C4: 0, Cs4: 1, D4: 2, Ds4: 3, E4: 4, F4: 5, Fs4: 6, G4: 7, Gs4: 8, A4: 9, As4: 10, B4: 11, C5: 12};

//マイナースケール
var codem =[1,4,8];

//12コード
var twelveCode =[root['C4'],root['Cs4'],root['D4'],root['Ds4'],root['E4'],root['F4'],root['Fs4'],root['G4'],root['Gs4'],root['A4'],root['As4'],root['B4'],root['C5']]

//和音入れ場
var chords = [];

//和音
for (var i = 0 ; i < Key.length; i++ ) {
  chords.push( [] );
  for (var  j = 0; j < codem.length; j++){
    var nmb = scale[twelveCode[i]+codem[j]];
    chords[i].push(nmb); 
  }
}

//シンセ生成
var synth = new Tone.PolySynth().toMaster();

//イベントリスナ
for (var i = 0; i < Key.length; i++) {
(function(i) {
  Key[i].addEventListener('click', function () { 
  //マイナーコードが4分音符の長さ鳴る
  synth.triggerAttackRelease(chords[i], '4n');
  }, false);
 })(i);
}

              
            
!
999px

Console