JavaScript preprocessors can help make authoring JavaScript easier and more convenient. For instance, CoffeeScript can help prevent easy-to-make mistakes and offer a cleaner syntax and Babel can bring ECMAScript 6 features to browsers that only support ECMAScript 5.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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.
<h1>和音鍵盤</h1>
<div id="code_type">
<form name="code_types">
<label><input type="radio" id="code_M" name="code_type" value="codeM" onchange="codeTypeSelect()" checked>
メジャー</label>
<label>
<input type="radio" id="code_m" name="code_type" value="codem" onchange="codeTypeSelect()">
マイナー</label>
</form>
<p id="code_type_text"></p>
</div>
<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>
h1, #code_type, #code_type_text {
text-align: center;
}
form {
margin: 0 auto ;
display: inline-block;
border: 1px solid #ccc;
padding: 10px;
}
label {
margin: 0 10px;
}
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;
}
//DOM
var Key = document.querySelectorAll('#piano li');
var codeTypeText = document.querySelector('#code_type_text');
var codeType = document.getElementsByName("code_type");
//音階
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 codeTypes = [
{'codeName': 'M',
'codeKeys': [1,5,8]},
{'codeName': 'm',
'codeKeys': [1,4,8]}
];
//検証
//console.log(codeTypes[1]['codeKeys'].length);
//console.log(codeTypes[1]['codeKeys'][2]);
//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 h = 0 ; h < codeTypes.length; h++ ) {
chords.push( [] );
for (var i = 0 ; i < Key.length; i++ ) {
chords[h].push( [] );
for (var j = 0; j < codeTypes[h]['codeKeys'].length; j++){
var nmb = scale[twelveCode[i]+codeTypes[h]['codeKeys'][j]];
chords[h][i].push(nmb);
}
}
}
//コードタイプ設定
function codeTypeSelect() {
for(var i = 0; i < codeType.length; i++){
if(codeType[i].checked) {
var CodeTypeValue = codeType[i].value;
codeTypeText.innerHTML = CodeTypeValue;
return chords[i];
}
}
}
codeTypeSelect();
//シンセ生成
var synth = new Tone.PolySynth().toMaster();
//イベントリスナ
for (var i = 0; i < Key.length; i++) {
(function(i) {
Key[i].addEventListener('click', function () {
//チェックされているコードタイプを確認
var seletcCords = codeTypeSelect();
//メジャーコードが4分音符の長さ鳴る
synth.triggerAttackRelease(seletcCords[i], '4n');
}, false);
})(i);
}
Also see: Tab Triggers