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

              
                <h1>和音鍵盤</h1>
<ul id="piano">
   <li id="C4" class="w_key">C</li>
   <li id="Cs4" class="b_key"></li> 
   <li id="D4" class="w_key">D</li>
   <li id="Ds4" class="b_key"></li> 
   <li id="E4" class="w_key">E</li>
   <li id="F4" class="w_key">F</li>
   <li id="Fs4" class="b_key"></li>
   <li id="G4" class="w_key">G</li>
   <li id="Gs4" class="b_key"></li>
   <li id="A4" class="w_key">A</li>
   <li id="As4" class="b_key"></li>
   <li id="B4" class="w_key">B</li>
   <li id="C5" class="w_key">C</li>
</ul>
<div id="code_type">
<p id="code_type_text"></p>
<p id="code_keys_text"></p>
<form name="code_types" class="">
	<dl>
		<dt>根音</dt>
		<dd>
			<label><input type="radio" id="code_R" name="code_type" value="ルート(R)" onchange="codeTypeSelect()" checked>(R)</label>
			<label><input type="radio" id="code_5" name="code_type" value="パワーコード(5)" onchange="codeTypeSelect()">5</label>
		</dd>	
	</dl>
	<dl>
		<dt>三和音</dt>
		<dd>
			<label><input type="radio" id="code_M" name="code_type" value="メジャー(M)" onchange="codeTypeSelect()">(M)</label>
			<label><input type="radio" id="code_m" name="code_type" value="マイナー(m)" onchange="codeTypeSelect()">m</label>
			<label><input type="radio" id="code_dim" name="code_type" value="ディミニッシュ(dim)" onchange="codeTypeSelect()">dim</label>
			<label><input type="radio" id="code_aug" name="code_type" value="オーギュメント(aug)" onchange="codeTypeSelect()">aug</label>
			<label><input type="radio" id="code_sus4" name="code_type" value="サスペンデッド4th(sus4)" onchange="codeTypeSelect()">sus4</label>
		</dd>
	</dl>
	<dl>
		<dt>四和音</dt>
		<dd>
			<label><input type="radio" id="code_M7" name="code_type" value="メジャーセブンス(M7)" onchange="codeTypeSelect()">M7</label>
			<label><input type="radio" id="code_7" name="code_type" value="セブンス(7)" onchange="codeTypeSelect()">7</label>
			<label><input type="radio" id="code_mM7" name="code_type" value="マイナー・メジャー・セブンス(mM7)" onchange="codeTypeSelect()">mM7</label>
			<label><input type="radio" id="code_m7" name="code_type" value="マイナー・セブンス(m7)" onchange="codeTypeSelect()">m7</label>
			<label><input type="radio" id="code_m7-5" name="code_type" value="マイナー・セブンス・フラット・ファイブ(m7(-5))" onchange="codeTypeSelect()">m7(-5)</label>
			<label><input type="radio" id="code_dim7" name="code_type" value="ディミニッシュ・セブンス(dim7)" onchange="codeTypeSelect()">dim7</label>
			<label><input type="radio" id="code_augM7" name="code_type" value="オーグメント・メジャー・セブンス(augM7)" onchange="codeTypeSelect()">augM7</label>
			<label><input type="radio" id="code_aug7" name="code_type" value="オーギュメント・セブンス(aug7)" onchange="codeTypeSelect()">aug7</label>
			<label><input type="radio" id="code_M7sus4" name="code_type" value="メジャー・セブンス・サスペンデッド4th(M7sus4)" onchange="codeTypeSelect()">M7sus4</label>
			<label><input type="radio" id="code_7sus4" name="code_type" value="セブンス・サスペンデッド4th(7sus4)" onchange="codeTypeSelect()">7sus4</label>
			<label><input type="radio" id="code_6" name="code_type" value="シックスス(6)" onchange="codeTypeSelect()">6</label>
			<label><input type="radio" id="code_m6" name="code_type" value="マイナー・シックスス(m6)" onchange="codeTypeSelect()">m6</label>
		</dd>
	</dl>
	<dl>
		<dt>五和音</dt>
		<dd>
			<label><input type="radio" id="code_M9" name="code_type" value="メジャーナインス(M9)" onchange="codeTypeSelect()">M9</label>
			<label><input type="radio" id="code_9" name="code_type" value="ナインス(9)" onchange="codeTypeSelect()">9</label>
			<label><input type="radio" id="code_7_f9" name="code_type" value="セブンス・フラット・ナインス(7(-9))" onchange="codeTypeSelect()">7(-9)</label>
			<label><input type="radio" id="code_7_s9" name="code_type" value="セブンス・シャープ・ナインス(7(+9))" onchange="codeTypeSelect()">7(+9)</label>
			<label><input type="radio" id="code_m7_11" name="code_type" value="マイナー・セブンス・イレブンス(m7(11))" onchange="codeTypeSelect()">m7(11)</label>
			<label><input type="radio" id="code_7_s11" name="code_type" value="セブンス・シャープ・イレブンス(7(+11))" onchange="codeTypeSelect()">7(+11)</label>
			<label><input type="radio" id="code_M7_13" name="code_type" value="メジャー・セブンス・サーティーンズ(M7(13))" onchange="codeTypeSelect()">M7(13)</label>
			<label><input type="radio" id="code_M7_13" name="code_type" value="セブンス・サーティーンズ(M7(13))" onchange="codeTypeSelect()">7(13)</label>
			<label><input type="radio" id="code_M7_f13" name="code_type" value="セブンス・フラット・サーティーンズ(M7(-13))" onchange="codeTypeSelect()">7(-13)</label>
			<label><input type="radio" id="code_69" name="code_type" value="シックス・ナインス(69)" onchange="codeTypeSelect()">69</label>
			<label><input type="radio" id="code_m69" name="code_type" value="マイナー・シックス・ナインス(m69)" onchange="codeTypeSelect()">m69</label>
		</dd>
	</dl>
</form>
</div>
              
            
!

CSS

              
                body {
	font-family: sans-serif;
}

h1, #code_type, #code_type_text {
  text-align: center;
}

form {
  margin: 0 auto ;
	max-width: 400px; 
  border: 1px solid #ccc;
  padding: 10px 10px 0;
	text-align: left;
}

form dl {
	padding: 5px 0 0;
	display: flex;
	margin: 0;	
}

form dl:not(:last-child) {
	border-bottom: 1px solid #eee;
}

form dt {
	font-weight: bold;
	width: 15%;
}

form dd {
	margin: 0;
	display: inline-block;
	width: 85%;
}

label {
  margin: 0 10px 10px 0;
	display: inline-block;
}

label:hover {
  cursor: pointer;
}

#piano {
  background: #333;
  padding: 10px;
  width: 310px;
  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; 
}

#code_type_text {
  font-size: 20px;
	margin: 10px 0 0;
}

#code_keys_text {
	margin: 0 0 10px;
}
              
            
!

JS

              
                //DOM
const Key = document.querySelectorAll('#piano li');
const codeTypeText = document.querySelector('#code_type_text');
const codeType = document.getElementsByName("code_type");
const codeKeysText = document.querySelector('#code_keys_text');

//音階
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',
  //3オクターブ目
  'C6', 'C#6', 'D6', 'D#6', 'E6', 'F6', 'F#6', 'G6', 'G#6', 'A6', 'A#6', 'B6',
];

//コードタイプ
var codeTypes = [
		//ルート音
    {'codeName': '(R)',
        'codeKeys': [1]},
    {'codeName': '(5)',
        'codeKeys': [1,8]},		
		//三和音
    {'codeName': '(M)',
        'codeKeys': [1,5,8]},
    {'codeName': 'm',
        'codeKeys': [1,4,8]},
    {'codeName': 'dim',
        'codeKeys': [1,4,7]},
    {'codeName': 'aug',
        'codeKeys': [1,5,9]},
    {'codeName': 'sus4',
        'codeKeys': [1,6,8]},
		//四和音
    {'codeName': 'M7',
        'codeKeys': [1,5,8,12]},
    {'codeName': '7',
        'codeKeys': [1,5,8,11]},	
    {'codeName': 'mM7',
        'codeKeys': [1,4,8,12]},
    {'codeName': 'm7',
        'codeKeys': [1,4,8,11]},
    {'codeName': 'm7(-5)',
        'codeKeys': [1,4,7,11]},
    {'codeName': 'dim7',
        'codeKeys': [1,4,7,10]},
    {'codeName': 'augM7',
        'codeKeys': [1,5,9,12]},	
    {'codeName': 'aug7',
        'codeKeys': [1,5,9,11]},	
    {'codeName': 'M7sus4',
        'codeKeys': [1,6,8,12]},	
    {'codeName': '7sus4',
        'codeKeys': [1,6,8,11]},	
    {'codeName': '6',
        'codeKeys': [1,5,8,10]},	
    {'codeName': 'm6',
        'codeKeys': [1,4,8,10]},
		//五和音
	  {'codeName': 'M9',
    		'codeKeys': [1,5,8,12,15]},
	  {'codeName': '9',
    		'codeKeys': [1,5,8,11,15]},
	  {'codeName': '7(-9)',
    		'codeKeys': [1,5,8,11,14]},
	  {'codeName': '7(+9)',
    		'codeKeys': [1,5,8,11,16]},
	  {'codeName': 'm7(11)',
    		'codeKeys': [1,4,8,11,18]},
	  {'codeName': '7(+11)',
    		'codeKeys': [1,5,8,11,19]},
	  {'codeName': 'M7(13)',
    		'codeKeys': [1,5,8,12,22]},
	  {'codeName': '7(13)',
    		'codeKeys': [1,5,8,11,22]},
	  {'codeName': '7(-13)',
    		'codeKeys': [1,5,8,11,21]},
	  {'codeName': '69',
    		'codeKeys': [1,5,8,10,15]},
	  {'codeName': 'm69',
    		'codeKeys': [1,4,8,10,15]},
];

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

//和音
for (let h = 0 ; h < codeTypes.length; h++ ) {
  chords.push( [] );
  for (let i = 0 ; i < Key.length; i++ ) {
    chords[h].push( [] );
    for (var  j = 0; j < codeTypes[h]['codeKeys'].length; j++){     
      const nmb = scale[i+codeTypes[h]['codeKeys'][j]];
      chords[h][i].push(nmb); 
    }
  }
}

//コードタイプ設定
  function codeTypeSelect() {
    for(let i = 0; i < codeType.length; i++){
      if(codeType[i].checked) {
        const CodeTypeValue = codeType[i].value;
        codeTypeText.innerHTML = CodeTypeValue;
        const CodeKyesValue = codeTypes[i].codeKeys;	
        codeKeysText.innerHTML = '構成音:' +  CodeKyesValue;
        return chords[i];
      }
    }
  }

codeTypeSelect();

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

//イベントリスナ
for (let i = 0; i < Key.length; i++) {
(function(i) {
  Key[i].addEventListener('click', function () { 
  //チェックされているコードタイプを確認
  var seletcCords = codeTypeSelect();
  //メジャーコードが4分音符の長さ鳴る
  synth.triggerAttackRelease(seletcCords[i], '4n');
  }, false);
 })(i);
}
              
            
!
999px

Console